Search and vectors · Engineering
Vector search: exact, ANN, and metrics
How NonoDB stores vectors, when exact search is the right default, and what the IVF sidecar changes.
Vector search looks simple from the application side: send an embedding, get the nearest documents. Underneath, there is a trade between exactness and speed, and a set of operational questions that only appear at scale.
NonoDB supports exact vector search in LMDB and an optional IVF sidecar for approximate unfiltered queries. It does not generate embeddings; clients send ready vectors.
Creating an index
{"op": "create_vector_index", "coll": "articles", "field": "embedding", "dims": 384, "metric": "cosine"}dimsis required and must be between 1 and 65,536.metriciscosine(default),dot, orl2.- The field must be a JSON array of exactly
dimsfinite numbers. - Missing, malformed, or wrong-length vectors are not indexed; the write still succeeds.
- One vector per document per index is supported.
- The index is maintained in the same transaction as inserts, updates, deletes, TTL expiry, and restores.
Creation backfills existing documents synchronously. Like any large index build, it blocks writers while the transaction runs.
Exact search
Without a sidecar, vector_search scans the whole index:
O(N × dims) per queryThat is exact and predictable. For a small or medium collection, it is often the right choice. It also works with arbitrary filters and after any write.
Distances are lower-is-better:
| Metric | _distance |
|---|---|
cosine |
1 - cosine_similarity (0 is identical) |
dot |
negative dot product |
l2 |
squared Euclidean distance |
Results are sorted by _distance, then _id. skip and limit apply after ranking; limit defaults to 10 and is capped at 1,000.
Filters change the plan
A filter is a normal document filter. If it is an exact _id or can use a secondary index with at most 50,000 candidates, NonoDB checks those documents first. Otherwise it scans the vector index and checks candidates until enough matches are found.
A highly selective filter on an unindexed field can inspect most documents and approach a full scan. Create a secondary index for selective filters, or accept that filtered vector search is doing more work.
This is a common trap: a filter that is cheap in a normal query can be expensive when combined with vector ranking.
The IVF sidecar
An optional immutable IVF sidecar accelerates unfiltered queries. It clusters vectors and probes the nearest clusters instead of scanning every vector.
Controls:
NONODB_BUILD_VECTOR_ANN=1builds missing sidecars at startup;NONODB_VECTOR_ANN_COLLECTIONSlimits which collections are built;NONODB_VECTOR_ANN_PROBEsets probed clusters (default 16);NONODB_VECTOR_ANN_CLUSTERSsets a target cluster count, otherwisesqrt(entries)capped at 4,096;NONODB_VECTOR_ANN_QUANTIZE=sq8|int8stores quantized records, about 3.8× smaller, opt-in.
The sidecar is approximate. Recall depends on the data and nprobe. It is only used for unfiltered queries; filtered queries and queries after recent vector writes use the exact path.
Vector writes are tracked in a small LMDB delta and merged into unfiltered ANN queries. After 4,096 changed ids, queries use the exact index until the sidecar is rebuilt. That bound keeps the delta from growing without limit.
Why exact is still the default
An ANN index adds a second representation to keep consistent. It needs a rebuild path, a delta, a probe setting, and an operational story when recall drops.
For many small deployments, exact search is simpler and fast enough. The sidecar is an opt-in accelerator, not a requirement. Start exact, measure, then build the sidecar when the collection and latency justify it.
What it does not do
- No embedding generation. Bring your own vectors.
- No multi-vector documents.
- No GPU acceleration.
- No distributed vector sharding.
- No learned reranker.
- No automatic quantization unless configured.
- No guarantee of exact recall when the IVF sidecar is active.
If you need billion-scale vector search with quantization, sharding, and a mature ANN ecosystem, use a dedicated vector database. NonoDB is for keeping vectors next to documents when the scale fits one process.
A practical checklist
- Fix
dimsand metric before loading data. - Validate vectors before insert; malformed vectors are skipped, not rejected.
- Create selective secondary indexes for filters.
- Start with exact search and measure p95 latency.
- Build the IVF sidecar only for unfiltered queries that need it.
- Monitor recall against an exact sample after enabling ANN.
- Rebuild after large changes or quantization changes.
The vector API and search guide have the exact semantics and environment settings.