Search and vectors · Engineering

Keeping search indexes consistent with writes

Transactional deltas, immutable segments, sidecars, reindexing, and the consistency trade-offs behind built-in search.

A search index that drifts from the data is worse than no search index. Users see deleted documents, stale prices, or a result they cannot open. The hard part is not building an inverted index; it is keeping it correct while writes continue.

NonoDB uses a mix of transactional metadata and immutable sidecar files. The design is deliberately different for text/fuzzy indexes and vector ANN indexes.

Text and fuzzy: metadata plus segments

Text and fuzzy postings are not stored in a huge LMDB B+ tree. They live in immutable segment files under search/, with manifests, deltas, tombstones, and exact statistics in LMDB metadata.

The write path records the index change in the same transaction as the document. The immutable segment files are not rewritten on every insert; new data goes into a delta, and old segments are merged or rebuilt outside the hot path.

This keeps writes bounded and avoids rewriting a large segment for one document. It also means search has a sidecar lifecycle:

  • back up the search/ directory with the database;
  • rebuild missing segments if they are lost;
  • reindex after an incompatible format change;
  • expect a heavy backfill when creating a text or fuzzy index.

NONODB_REBUILD_MISSING_SEARCH=1 rebuilds missing text/fuzzy segment files at startup. reindex rebuilds all index types for a collection from the current documents.

Vector: exact index plus optional ANN

The exact vector index is transactional: inserts, updates, deletes, TTL expiry, and restores update the index in the same write transaction.

The optional IVF sidecar is immutable. 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 prevents the delta from growing forever and makes the recall trade-off explicit.

Filtered vector queries use the exact path, so a filter cannot silently query a stale ANN cluster set.

TTL and deletes

TTL expiry uses the normal delete path. Expired documents are hidden immediately by default, and search over-fetches when necessary so an expired top hit does not consume the requested limit.

Strict TTL reads are controlled by NONODB_TTL_STRICT_READS. With strict reads off, search may see a document until the sweeper removes it. That is a compatibility mode, not the default.

Deleted documents are excluded from search results. The underlying segment cleanup happens through the normal merge/rebuild path, not a synchronous rewrite of every posting.

Reindex is a write transaction

Creating a text, fuzzy, or vector index backfills synchronously. The daemon blocks writers while the backfill transaction is active. The same is true for reindex.

This is the main operational cost. On a large collection:

  • schedule index builds outside peak traffic;
  • expect memory to rise during parallel backfill;
  • expect write latency to pause while the build transaction is active;
  • verify the index definition before starting.

NONODB_INDEX_TIMEOUT bounds the build. NONODB_BACKFILL_WORKERS controls parsing parallelism; NONODB_SEARCH_WORKERS controls exact vector and single-term text search. These are not knobs for making a build free.

Backups and restores

A database backup includes search and vector sidecars alongside the LMDB snapshot. If a sidecar is missing after a restore, search may fail until it is rebuilt.

The safe sequence is:

  1. Back up the data directory, including search/ and vector-ann/.
  2. Verify the backup with the CLI.
  3. Restore the whole database, not just data.mdb.
  4. Run a search smoke test.
  5. Rebuild missing sidecars if the backup was partial.

The backup guide and restore guide cover the file layout.

What consistency you actually get

  • Document writes, secondary index entries, TTL state, history, and search metadata are updated in one transaction.
  • Text/fuzzy immutable segments are derived and may lag until a merge or rebuild.
  • Exact vector search is transactional.
  • ANN search is approximate and bounded by the delta/rebuild policy.
  • A reindex is a new backfill, not an incremental patch.

That is a practical consistency model for a single-node database. It is not a distributed search cluster with cross-node replication of every posting.

A checklist

  • Create search indexes before loading production traffic.
  • Include sidecar directories in backups.
  • Test restore with a search query, not only a document read.
  • Monitor index_builds and search latency.
  • Rebuild ANN after a large vector change if recall matters.
  • Reindex after an index-format upgrade.
  • Keep strict TTL reads on unless you need legacy behavior.

The search guide and operations guide document the sidecar layout, rebuild controls, and validation scripts.

All engineering notes →Read the docs