Skip to content

Repository files navigation

nanovec

Go License Dependencies Recall

An embedded vector database in Go. Exact and approximate (HNSW) nearest-neighbour search, metadata filtering, and crash recovery, with zero dependencies beyond the standard library.

Single-node and in-memory. Built from scratch to be read and understood.

Performance

Recall vs throughput

On 100k clustered 128-d vectors, HNSW reaches 0.99 recall@10 at 5,300 QPS, about 38× faster than exact search, with 0.31 ms p99 latency. Reproduce: go run ./benchmark -n 100000 -clusters 2000.

Install

go get github.com/ashokDevs/nano-vector-db

Quick start

db := nanovec.New()
db.CreateCollection("docs", 128, nanovec.Cosine)
db.Insert("docs", "doc_1", embedding, map[string]any{"lang": "en"})

// exact search
hits, _ := db.Search("docs", query, 10)

// approximate search (build the index first)
db.BuildIndex("docs")
hits, _ = db.SearchApprox("docs", query, 10, 20) // ef=20

// filtered search
hits, _ = db.SearchFiltered("docs", query, 10, func(m map[string]any) bool {
    return m["lang"] == "en"
})

Durable mode logs and fsyncs every write, and recovers by replaying the log:

db, _ := nanovec.OpenDB("./data")
defer db.Close()

Features

  • Cosine, dot-product, and Euclidean metrics
  • HNSW approximate index with a tunable recall/latency knob
  • Metadata filtering during the scan
  • Bounded top-K selection (min-heap, O(n log k))
  • Binary snapshots and write-ahead-log crash recovery
  • Race-clean, no third-party dependencies

Architecture

flowchart LR
  I[Insert] --> S[Collection<br/>flat SoA store]
  S --> B[BuildIndex] --> H[HNSW graph]
  Q[Query] --> E{Search}
  E -->|exact| S
  E -->|approx| H
  S --> W[(WAL + snapshot)]
Loading

Roadmap

SIMD distance kernels, int8/product quantization, disk-backed collections, concurrent index build.

License

MIT

About

An embedded vector database in Go: exact and HNSW approximate search, metadata filtering, and write-ahead-log crash recovery. Zero dependencies.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages