What's Changed
Added
- Synced hnswlib C++ headers to latest nmslib/hnswlib master
- New
hnswlib/stop_condition.hheader from upstream NewWithReplaceDeleted()— create index with replace-deleted supportAddPointWithReplace()— add vector reusing deleted slotsFree()— explicit memory release for HNSW index- Nil-safety checks for all public methods (return zero values instead of panicking)
- Comprehensive unit tests: 19 test functions covering all space types (L2, IP, Cosine)
- Performance benchmarks: 7 benchmark functions (AddPoint, SearchKNN, BatchOps, SaveLoad)
- Multi-platform Makefile with
portable,opt,bench,linttargets - Cross-compilation targets:
build-linux-amd64,build-linux-arm64,build-darwin-amd64,build-darwin-arm64,build-windows-amd64 - Windows support via MinGW-w64 (conditional CGO LDFLAGS,
uint64_ttypes) - GitHub Actions CI: Linux, macOS, Windows matrix with Go 1.21–1.26
CHANGELOG.mdwith full version history
Changed
- Upgraded hnswlib from v0.7.0 to latest master
- All C bridge types changed from
unsigned long inttouint64_tfor cross-platform safety (Windows LLP64 compatibility) SearchKNNnow usessync.Poolto reuse C-type buffers — allocs reduced 50% (4 → 2), L2 search ~12% fasterSearchBatchKNNuses lock-free per-index writes instead of mutex — allocs reduced 49% (412 → 211)normalizeVectoroptimized to in-place modification (no slice return/copy)- Removed unnecessary
runtime.GC()call fromFree() go.modbumped to Go 1.21
Fixed
- Fixed 3 upstream bugs in
hnswalg.h:internal_id→internalIdvariable name - Fixed
UpdateBatchPointscondition bug (&&→||for parameter validation) - Fixed
errchecklint warnings in test files
Benchmarks (Apple M3 Pro, Go 1.23, -O3 -march=native)
| Benchmark | ns/op | B/op | allocs/op |
|---|---|---|---|
| AddPoint (L2) | 1,805,974 | 512 | 1 |
| AddPoint (Cosine) | 1,476,631 | 512 | 1 |
| SearchKNN (L2, top-10) | 119,831 | 96 | 2 |
| SearchKNN (Cosine, top-10) | 89,467 | 96 | 2 |
| SearchBatchKNN (100×4) | 4,231,052 | 15,650 | 211 |
| SaveLoad (5000 vectors) | 16,149,372 | 50 | 1 |
Full Changelog: https://github.com/sunhailin-Leo/hnswlib-to-go/blob/v1.1.0/CHANGELOG.md