Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,26 @@ HnswIndex rebuilt = HnswIndex.Build(
seed: 42);
```

`ExportItems` returns copies of the original vectors passed to `Add`. Cosine
vectors are still stored normalized internally for search, but the portable
export preserves the original input values; rebuilding normalizes them again.
`ExportItems` returns copies of the stored vectors. For cosine these are the
unit-normalized vectors used for search (not the original input magnitudes);
rebuilding from them re-normalizes and reproduces the same index. Other metrics
store vectors unchanged, so the export matches the input.

## Memory-mapped loading

For large indexes or cold-start-heavy scenarios, `LoadMapped` memory-maps the
vector section of a saved file instead of reading it into the managed heap. The
graph is still loaded into memory, so search stays fast while the bulk of the
data (the vectors) is paged in on demand by the OS:

```csharp
using HnswIndex index = HnswIndex.LoadMapped("index.hnsw");
IReadOnlyList<(long Id, float Distance)> hits = index.Search(query, 10);
```

The returned index owns the mapping and is read-only — it must be disposed, and
`Add` throws. To modify an index, load it with `Load` instead. `LoadMapped`
requires the current on-disk format; re-save older indexes first.

## hnswlib parity validation

Expand Down
1 change: 1 addition & 0 deletions src/Hnsw.Net/Hnsw.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<Optimize>true</Optimize>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>HnswNet</RootNamespace>
<AssemblyName>Hnsw.Net</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
Loading