Introducing a new way to review your PRs.

Read the announcement

helixdb / helix-db

HelixDB is an OLTP graph database with native vector and full-text search built in Rust on Object Storage.

View on GitHub

27 documents · Updated Nov 23, 2026

docs / index-lifecycle-and-search

The index system turns graph data into managed secondary, text, and vector indexes. It builds each new physical version in the background, makes it visible only after validation, keeps it current as graph data changes, and removes old data through a recoverable path. This page describes the index part of the database engine; storage format and graph transaction details are covered in storage encoding and migrations and graph mutations and transactions.

Index families

The system supports three index families. Each family has its own search or lookup behavior, but all families use the same catalog and lifecycle rules.

FamilyMain purposeIndexed source
SecondaryFind nodes or edges by exact or ordered property valuesA label and property. Equality indexes can be unique. Range indexes can be ascending or descending.
TextRank matching documents by full-text relevanceA string property or string array. The definition also fixes the text analyzer and optional tenant partition.
VectorRank nearby embeddings by distanceA numeric vector with a fixed dimension and one of cosine, Euclidean, or Manhattan distance.

An index definition identifies the graph element kind, label, and property. A tenant property can split text and vector data into independent partitions. The planner accepts these definitions through the index DDL paths in crates/…/create.rs and crates/…/drop.rs.

Catalog authority

Canonical catalog

The canonical catalog is the durable source of truth for index identity, definition, generation, and state. A generation is one physical version of an index. The loaded catalog exposes only Active generations to planning, while each serving path keeps an exact handle that includes the scope, identity, generation, and family definition. This prevents a request from reading rows from a different or retired generation. The catalog loader is defined in the fully qualified path crates/…/catalog.rs.

The same catalog snapshot also drives graph mutation routing. One serializable transaction classifies all active and building generations, then routes each graph change only to the families that can observe its label or indexed properties. This keeps mutation work and lifecycle changes in the same conflict boundary.

References: crates/…/catalog.rs• L18-54 crates/…/catalog.rs• L206-260 crates/…/mutation_catalog.rs• L1-8 crates/…/mutation_catalog.rs• L304-412

Lifecycle states

Every managed index follows a small state model. Building is hidden work. Active is the only state that can serve queries. Aborting removes an unfinished build. Dropping drains an active generation. Dropped keeps the logical identity and last generation so a later create can use a new generation.

The create and drop requests classify duplicates and definitions in a serializable transaction. They then publish the canonical record, operation record, and runnable work pointer together. IF NOT EXISTS can converge on an existing build or active generation. A changed definition is a conflict rather than a new physical version.

The main lifecycle transitions are:

  1. Create a hidden generation and enqueue BUILD.
  2. Scan source data in bounded steps.
  3. Apply changes that raced the scan.
  4. Validate the completed physical data.
  5. Activate the generation atomically.
  6. On drop or build failure, retire and delete the generation in bounded cleanup steps.

This state model is declared in crates/…/model.rs and coordinated by crates/…/lifecycle.rs.

References: crates/…/model.rs• L1263-1365 crates/…/model.rs• L1499-1603 crates/…/lifecycle.rs• L177-318 crates/…/lifecycle.rs• L372-477

Durable operation queue

The lifecycle uses an outbox: a durable queue of small work steps that advance one operation at a time. Each operation stores its family, kind, bounded progress, retry state, and terminal result. A claim carries a writer epoch so a restarted or replaced writer cannot complete work from an older owner.

The parent-owned worker scans queue pointers in a fair cycle across secondary, vector, and text families. It limits global and family concurrency, releases a claim after each checkpoint, and wakes when new work arrives or a retry becomes ready. A failed worker cycle restarts after its tasks join. Same-epoch recovery can reclaim a claim only after the earlier task has ended.

Public status reduces this internal state to queued, running, blocked, succeeded, or aborted. Progress reports the current stage and bounded work counters without exposing claims or raw cursors.

References: crates/…/outbox.rs• L64-151 crates/…/outbox.rs• L420-480 crates/…/operation.rs• L90-120 crates/…/operation.rs• L402-529 crates/…/worker.rs• L39-71 crates/…/worker.rs• L354-431 crates/…/worker.rs• L504-723 crates/…/public.rs• L186-287

Secondary index maintenance

Secondary builds

The secondary driver backfills a hidden generation from authoritative node or edge property rows. It captures an inclusive source boundary, resumes after a typed key cursor, and writes generation-qualified entries in bounded transactions. After the source scan, it applies coalesced mutation markers that arrived during the scan. It validates ownership and uniqueness before activation.

The build treats a mutation marker as a signal to read the current graph row again. This is important because the marker does not carry a possibly stale property value. A unique equality index blocks when two entities claim the same value. Invalid source data and work that cannot fit one bounded step also become explicit blockers.

References: crates/…/secondary.rs• L1-12 crates/…/secondary.rs• L701-818 crates/…/secondary.rs• L878-952 crates/…/secondary.rs• L985-1100 crates/…/operation.rs• L402-430

Secondary foreground updates

Graph writes maintain active secondary generations in the same graph transaction that changes the source row. The update removes the old indexed value and adds the new value. A building generation receives one coalesced delta instead, so the background build can reconcile the latest authoritative row later.

Equality and range indexes use different physical lanes. Unique equality keeps one owner for a value. Non-unique equality can return a set of owners. Range serving scans ordered values and checks the requested bounds before it accepts owners. The serving path can stop at an accepted-owner limit rather than a raw storage-row limit.

References: crates/…/secondary.rs• L254-296 crates/…/secondary.rs• L299-508 crates/…/exact.rs• L28-91 crates/…/exact.rs• L208-380

Secondary cleanup

Dropping a secondary generation scans only rows owned by its index and generation. It deletes physical entries, then retained build deltas, and finally changes the canonical state to Dropped. Each scan has a durable resume point, so a restart continues cleanup instead of repeating an unbounded delete.

References: crates/…/operation.rs• L451-473 crates/…/secondary.rs• L786-818 crates/…/secondary.rs• L1355-1356

Text build pipeline

The text driver builds immutable search splits from authoritative graph rows. A split is a self-contained text search unit. The build first records generation-qualified entity state. It then groups state by tenant partition, creates splits, uploads their content-addressed blobs, and attaches the exact blob references to database metadata.

The build moves through this pipeline:

flowchart LR
    A[Graph property rows] --> B[Generation entity state]
    B --> C[Partition-ordered documents]
    C --> D[Immutable text splits]
    D --> E[Manifest pages and roots]
    E --> F[Manifest validation]
    F --> G[Active text generation]

Database transactions control visibility. An uploaded blob is not searchable until its reference, manifest state, statistics, and active generation state commit. A failed later commit can leave an unreachable immutable blob, but it cannot publish a partial index.

References: crates/…/driver.rs• L1-16 crates/…/driver.rs• L142-174 crates/…/driver.rs• L662-858 crates/…/mod.rs• L1-5 crates/…/mod.rs• L261-304

Text mutation maintenance

Active text changes are grouped by generation and tenant partition inside the graph transaction. The system analyzes changed text once, records the document version and live state, and creates one optional new split for each affected destination. A delete or tenant move does not need a new blob for the old partition. It advances that partition's manifest revision and writes a dead state for the old document version.

Building text generations receive coalesced markers and statistics changes. Catch-up reads the current graph row and assigns a new logical version. This lets the build include changes that occur after its source scan without trusting an old request payload.

References: crates/…/mutation.rs• L1-11 crates/…/mutation.rs• L333-391 crates/…/active_runtime.rs• L18-31 crates/…/active_runtime.rs• L74-145 crates/…/active_batch.rs• L192-228 crates/…/active_batch.rs• L473-495 crates/…/active_retirement.rs• L56-207

Text serving

Text search resolves an active generation and one normalized partition before it reads a manifest. It validates the root, loads its pages, and opens only splits whose term summary may contain a query term. It then compares each split hit with generation-qualified live state and logical version, so stale documents in immutable splits do not reach the result set.

The final ranking uses BM25, a standard full-text relevance score. Corpus totals and term frequencies come from the same active generation. The request can search all entities or an exact candidate set produced by an upstream graph traversal.

sequenceDiagram
    participant Q as Query
    participant C as Active catalog
    participant M as Manifest
    participant S as Immutable splits
    participant L as Live state
    Q->>C: Resolve definition, generation, and partition
    C->>M: Load and validate root and pages
    M->>S: Open matching split blobs
    S->>L: Check entity version and live flag
    L-->>Q: Return top BM25 hits

References: crates/…/generation.rs• L204-332 crates/…/storage.rs• L205-278 crates/…/storage.rs• L281-407 crates/…/serving.rs• L143-228 crates/…/serving.rs• L323-490 crates/…/mod.rs• L469-489 crates/…/mod.rs• L504-674

Text compaction

Text splits are immutable, so foreground updates add new split references and mark old document versions dead. Compaction is a background optimization that merges useful same-partition splits, keeps only current live versions, and replaces the selected page in one database transaction. It retains the immutable blob objects even after their metadata is retired.

Active text updates publish a durable compaction pointer. The worker processes one pointer at a time and removes or refreshes it after checking the active record, root revision, page, and source observations. A concurrent update causes the compaction attempt to yield rather than overwrite newer text state.

References: crates/…/active_compaction.rs• L30-80 crates/…/active_compaction.rs• L135-274 crates/…/active_compaction.rs• L277-391 crates/…/compaction.rs• L1-10 crates/…/compaction.rs• L72-229

Vector build and ownership

The vector driver builds a hidden HNSW generation from validated numeric vectors. HNSW is a graph used to find nearby vectors without comparing every stored vector. Each generation carries a descriptor that fixes its dimension, metric, vector format, score meaning, and routing capability.

An unpartitioned definition owns one physical vector namespace. A tenant-partitioned definition resolves each tenant value through a durable mapping and can create a namespace only when a write or build needs it. The mapping is never created by a read. A building generation receives coalesced entity markers. An active generation updates its authorized HNSW rows in the graph transaction.

Legacy vector namespaces can be adopted without rebuilding their HNSW rows. Adoption first validates the old physical lanes, then validates the generated routing directory, transfers ownership, and publishes the current descriptor.

References: crates/…/vector.rs• L1-13 crates/…/vector.rs• L73-93 crates/…/vector.rs• L229-315 crates/…/vector.rs• L707-782 crates/…/driver.rs• L1-10 crates/…/driver.rs• L102-275 crates/…/driver.rs• L1069-1137 crates/…/model.rs• L1032-1181

Vector query serving

Vector serving validates the query shape and resolves the active generation through the request's stable read view. It checks the stored physical metadata against the generation descriptor before HNSW reads begin. A partitioned query with no mapped tenant partition returns no results without allocating or opening a physical index.

The normal search descends upper HNSW layers, explores layer zero, applies the configured SimHash policy when enabled, loads candidate vectors, and ranks them by the generation's metric. SimHash is a compact fingerprint used to reduce routing work. It does not change the stored vector distance contract. The result includes a stable distance meaning for cosine, Euclidean, or Manhattan search.

The read factory uses a process-local cache only when its generation identity and storage snapshot sequence match exactly. Otherwise it reads through the request's database view. This makes cache use an optimization rather than a source of visibility.

References: crates/…/dispatch.rs• L58-204 crates/…/generation.rs• L124-202 crates/…/generation.rs• L335-408 crates/…/storage.rs• L35-203 crates/…/search.rs• L258-347 crates/…/search.rs• L387-499 crates/…/read_index.rs• L20-101

Restricted vector search ranks only entities supplied by an upstream graph traversal. It first turns the input IDs into one exact membership set. Small sets use an exact vector scan. Larger sets use bounded seeds, routing rows, and graph expansion, but every returned entity must still belong to the exact set.

This separation allows graph predicates to limit vector ranking without allowing approximate routing to widen the result set. The execution layer preserves the original graph rows and adds only the computed $distance value to ranked results.

References: crates/…/restricted_vector.rs• L14-63 crates/…/restricted_vector.rs• L66-125 crates/…/restricted.rs• L1-7 crates/…/restricted.rs• L121-166 crates/…/restricted.rs• L345-370 crates/…/restricted.rs• L464-613 crates/…/restricted.rs• L837-1148

Serving, retirement, and recovery

Request read views

Search and indexed lookups use the request's read view. A write request reads through its transaction and can see its own index changes. A read request uses a stable snapshot. Generation resolution, metadata checks, manifest reads, vector rows, text live state, and candidate materialization must use that same view.

The request resolves runtime definition details first, then checks the durable active record. A missing active record is an index-lifecycle-unavailable result, not permission to fall back to a display name or an old physical namespace. A stable request view can continue using the generation it already resolved while a later request observes a newly published drop or replacement.

References: crates/…/read_view.rs• L1-16 crates/…/read_view.rs• L30-112 crates/…/definitions.rs• L10-53 crates/…/generation.rs• L292-408 crates/…/repository.rs• L239-314

Retirement paths

Dropping an active generation first changes its canonical state to Dropping. The family driver then removes data in bounded steps while new requests stop resolving that generation. Secondary cleanup removes entries and deltas. Vector cleanup retires the resident cache, deletes physical rows and tenant mappings, then deletes build state. Text cleanup removes generation metadata while retaining immutable blobs.

An unfinished build follows the same cleanup idea through Aborting. It removes only the hidden generation and then records Build as aborted. A failed or cancelled step therefore leaves durable progress or a durable cleanup path instead of an unknown half-active index.

References: crates/…/lifecycle.rs• L391-477 crates/…/operation.rs• L451-481 crates/…/driver.rs• L333-630 crates/…/cleanup.rs• L23-41 crates/…/cleanup.rs• L91-213

Recovery boundaries

Recovery favors retry when the durable inputs changed during preparation. Each bounded operation stores typed resume cursors and cumulative counters. The repository validates that a cursor belongs to the expected scope, generation, and physical lane before it accepts the next step.

The operation can become blocked when the source is invalid, uniqueness fails, a bounded entity or text manifest is too large, object storage is unavailable, or persisted state cannot satisfy a safety check. Operators can fix the source or service condition and retry the same operation. Catalog, descriptor, manifest, and ownership disagreement remains a corruption or invariant error so serving does not guess.

References: crates/…/repository.rs• L329-335 crates/…/repository.rs• L632-811 crates/…/operation.rs• L818-860 crates/…/operation.rs• L914-995 crates/…/outbox.rs• L135-151 crates/…/driver.rs• L495-638

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to an index definition must stay aligned across planner DDL identity, the validated catalog definition, physical generation metadata, and request-time definition lookup.
  • Changes to a lifecycle stage must update its typed progress payload, cursor validation, public status projection, worker dispatch, and family cleanup path together.
  • Changes to mutation routing must preserve the one catalog snapshot rule and cover label changes, indexed-property changes, tenant moves, and entity deletion for both active and building generations.
  • Changes to text manifests must keep root counts, page order, logical versions, corpus statistics, term statistics, split references, and compaction pointers consistent.
  • Changes to vector physical data must keep the generation descriptor, metric score meaning, routing layout, tenant mapping, cache identity, and cleanup authority aligned.
  • Changes to retry or claim behavior must preserve writer fencing and same-epoch recovery. A new worker must not reuse a claim while its prior task can still write.

Important failure modes

TriggerConsequenceGuard
A create or drop request uses the same identity with different definition fieldsThe request returns an index-definition conflictCompare the requested definition with the canonical record before enqueueing work
A backfill finds malformed source data, duplicate unique values, or work larger than one allowed batchThe operation becomes blocked and does not activateFix the source or size limit, then retry the existing operation
A prepared step observes a changed root, delta, artifact, or operation revisionThe step is retried without publishing stale physical dataKeep the exact preparation reads in the serializable commit boundary
A request resolves a building, dropping, or missing generationServing returns lifecycle-unavailable instead of reading an unsafe physical namespaceResolve only an active canonical record in the request read view
Vector metadata disagrees with the active generation descriptorVector serving fails closed before reading vector rowsValidate dimension, metric, score meaning, layout, and physical identity
A text root, page, live-state row, corpus statistic, or blob reference is missing or cross-ownedText serving reports catalog corruption rather than returning stale or mixed hitsCross-check key ownership, generation, partition, revision, and live version
A worker task fails or the process restarts after a claimDurable work remains queued or is reclaimed after safe same-epoch recoveryPersist checkpoints and fence claims with writer epochs
A vector tenant partition becomes emptyIts mapping and empty physical namespace are reclaimedVerify every physical lane is empty before deleting the mapping

Key files

FileWhy to read it
crates/…/model.rsDefines the shared index identities, generations, descriptors, and lifecycle states.
crates/…/lifecycle.rsShows how create, drop, abort, duplicate handling, and operation enqueueing become atomic catalog changes.
crates/…/catalog.rsShows how active durable records become planner and serving authority.
crates/…/mutation_catalog.rsShows how one graph transaction routes changes to all index families.
crates/…/operation.rsDefines bounded build and cleanup stages, progress, blockers, and execution states.
crates/…/outbox.rsDefines the durable operation queue and the family-driver boundary.
crates/…/worker.rsExplains fair background dispatch, concurrency limits, shutdown, and recovery.
crates/…/secondary.rsCovers secondary backfill, catch-up, active maintenance, serving, and cleanup.
crates/…/driver.rsCovers the text build pipeline from source scan through split publication and manifest validation.
crates/…/serving.rsShows how active text roots, pages, and entity state are validated before search.
crates/…/active_batch.rsExplains active text mutation batching, partition destinations, and state-only retirement.
crates/…/active_compaction.rsExplains restart-safe compaction for active text pages.
crates/…/vector.rsCovers vector document validation, active mutation, tenant partitions, and physical ownership.
crates/…/driver.rsCovers vector build, legacy adoption, descriptor validation, and physical cleanup.
crates/…/dispatch.rsConnects planned vector and text operations to lifecycle-aware serving.
crates/…/generation.rsShows definition, tenant, generation, and physical namespace resolution.
crates/…/storage.rsShows the final request-view boundary for vector rows and text manifests.
crates/…/search.rsExplains the shared unrestricted HNSW search session and layer-zero routing policy.
crates/…/restricted.rsExplains exact-membership vector ranking after graph prefiltering.
crates/…/mod.rsExplains immutable text split construction, blob access, live-state filtering, and BM25 search.