HNSWIndex 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package HNSWIndex --version 1.3.0
                    
NuGet\Install-Package HNSWIndex -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HNSWIndex" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HNSWIndex" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="HNSWIndex" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HNSWIndex --version 1.3.0
                    
#r "nuget: HNSWIndex, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=HNSWIndex&version=1.3.0
                    
Install HNSWIndex as a Cake Addin
#tool nuget:?package=HNSWIndex&version=1.3.0
                    
Install HNSWIndex as a Cake Tool

HNSWIndex

Perform KNN Query for millions of data points fast and with great accuracy.

HNSWIndex is a .NET library for constructing approximate nearest-neighbor (ANN) indices based on the Hierarchical Navigable Small World (HNSW) graph. This data structure provides efficient similarity searches for large, high-dimensional datasets.

Key Features

  • High Performance: Implements the HNSW algorithm for fast approximate k-NN search.
  • Flexible Distance Metric: Pass any Func<TLabel, TLabel, TDistance> for custom distance calculation.
  • Flexible Heuristic: Pass heuristic function for nodes linking.
  • Concurrency Support: Thread safe graph building API
  • Configurable Parameters: Fine-tune the indexing performance and memory trade-offs with parameters
  • Save and Load: Save resulting structure on file system and restore later

Installation

Install via NuGet:

dotnet add package HNSWIndex

Or inside your .csproj:

<PackageReference Include="HNSWIndex" Version="x.x.x" />

Getting Started

1. Optionally configure parameters

var parameters = new HNSWParameters
{ 
    RandomSeed = 123,
    DistributionRate = 1.0,
    MaxEdges = 16,
    CollectionSize = 1024,
    // ... other parameters
};

2. Create empty graph structure ()

var index = new HNSWIndex<float[], float>(Metrics.SquaredEuclideanMetric.Compute);

3. Build the graph

var vectors = RandomVectors();
foreach (var vector in vectors)
{
	index.Add(vector)
}

Or multi-threaded

var vectors = RandomVectors();
Parallel.For(0, vectors.Count, i => {
    index.Add(vectors[i]);
});

4. Query the structure

var k = 5;
var results = index.KnnQuery(queryPoint, k);

5. Save and Load graph from file system

index.Serialize(pathToFile);
var index = HNSWIndex<float[], float>.Deserialize(Metrics.SquaredEuclideanMetric.Compute, pathToFile);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.2 112 6/18/2025
1.3.1 128 6/16/2025
1.3.0 295 6/10/2025
1.2.0 149 5/25/2025
1.1.5 158 4/18/2025
1.1.4 114 2/12/2025
1.1.3 122 2/11/2025
1.1.2 107 2/8/2025
1.1.1 123 2/6/2025
1.1.0 110 2/3/2025
1.0.2 102 1/22/2025
1.0.1 112 1/7/2025
1.0.0 113 1/6/2025