Architecture

How VLite works

One Rust engine writes vectors and graphs to one authoritative file. Every index is a rebuildable cache. Embed the engine or run it as a server.

Key terms

TermWhat it means in VLite
DatabaseOne .vlite file with your records, collections and graphs. Embed it, or serve it with vlite-server, one file per server.
CollectionA named set of records, like a table, with its own vector size and settings. Every database has default; named collections need format v4 or newer.
GraphA named property graph in the same file: nodes, typed edges and links to records.
TenantA private space for one team or customer in the same file. Its users and API keys see only its collections and graphs.
UserA person who signs in to the dashboard as super admin, editor or viewer. Apps use API keys.

Tenants and users exist only on a server; their settings live in its admin directory.

InterfacesSearch & indexes StorageOperations & decisions Errors

Layers

Every interface calls the same Database core. Only storage touches the file. Switch to 3D to rotate the layers.

VLite layers: interfaces call the Database core; search indexes are rebuildable; storage writes the authoritative file. Open full-size diagram
Text diagram
flowchart TB
  SDK["SDKs and APIs<br/>Rust · Python · Node.js · C · WASM<br/>REST · gRPC · console · MCP"]
  DB["Database core<br/>collections · records · metadata<br/>vectors · graphs · queries · change feed"]
  IDX["Search and indexes · rebuildable<br/>HNSW · ScalarU8 · metadata<br/>BM25 · hybrid RRF · Disk ANN"]
  STORE["Storage and format<br/>checksummed frames · optional encryption<br/>file / memory backend"]
  FILE[("data.vlite<br/>authoritative committed records")]
  SDK -->|"same embedded API"| DB
  DB -->|"query / rebuild"| IDX
  DB -->|"durable commits"| STORE
  STORE --> FILE

One file

The database file is the only source of committed records. It is an append-only log of checksummed frames, with no separate write-ahead log. Indexes and ANN snapshots derive from it, so losing them never loses data.

The authoritative database rebuilds in-memory indexes and optional ANN sidecars; a matching snapshot can reload the cache. Open full-size diagram
Text diagram
flowchart LR
  F[("data.vlite<br/>authoritative")]
  A["data.vlite.ann<br/>ANN snapshot cache"]
  D["disk-ann-#lt;id#gt;.dann<br/>Disk ANN"]
  M["In-memory indexes<br/>HNSW · metadata · BM25"]
  F -- "rebuild on open" --> M
  F -- "persist graph" --> A
  F -- "build" --> D
  A -. "load if identity matches" .-> M

Header, optional encryption descriptor, then the append-only log. Each commit adds a data frame; timestamped commits add a time anchor first. Integers are little-endian.

Header and optional encryption descriptor precede frames; each frame ends with a validated commit footer. Open full-size diagram
A valid footer marks a committed frame.

Every file starts with a 32-byte header. Its CRC32 covers bytes 0–27 and is checked on every open.

FlagMeaning
1 · encryptedFrame bodies are sealed with ChaCha20-Poly1305, and an encryption descriptor follows the header.
2 · timestampsEach commit is preceded by a time-anchor frame (op 11), so a restore can target a point in time.
4 · graphThe file can hold property graphs. Set by default on new files.

Only v5 files have flags. Unknown bits fail with UnsupportedFeature rather than being ignored, so an older binary never misreads a newer file.

Encryption descriptor (64 bytes, readable, encrypted files only):

KDF 0 is a raw 32-byte key. KDF 1 derives the key from a passphrase with Argon2id, using the stored cost. The key ID is a short fingerprint of the key, and the key check confirms the key before anything is decrypted. A wrong key returns EncryptionKeyMismatch with the expected key ID, never a corruption error.

Frames

A frame is a 36-byte prefix, a body and a 16-byte footer. The footer is the commit marker: a frame without a valid footer is never treated as committed.

Prefix (36 bytes):

CRC32 checks cover the header, each prefix (bytes 0–31) and each footer, which covers every earlier byte of its frame. The footer repeats the sequence, so a frame copied from elsewhere fails. In encrypted files the prefix and footer stay readable, so recovery still works, and the prefix is authenticated together with the body.

OpSinceBody
1 · putv1Vector, then payload
2 · deletev1Empty
3 · batchv21–4,096 entries for one collection, up to 16 MiB
4 · putv3Vector, payload and metadata (see Records)
5 · create collectionv4Name (up to 63 bytes), dimensions and settings
6 · drop collectionv4Empty
7 · settingsv4Collection settings, up to 16 KiB
8 · metadata updatev5New metadata only; the vector is not rewritten
9 · put with expiryv59-byte expiry, then an op 4 body
10 · named vectorsv5Replaces the collection's named and sparse vectors, up to 16 MiB
11 · time anchorv5Commit time in milliseconds (timestamps flag)
12 · graphv5Graph changes (graph flag; see Graph frames)

A batch entry has a 16-byte header (op, ID and length) and holds a put or a delete. From v4, the last entry may be an import checkpoint, which commits an import job's progress together with its records.

Format versions

Features that need new on-disk structures use a newer format version. Files are never converted silently: using such a feature on an older file returns an error such as MetadataRequiresUpgrade or CollectionsRequireUpgrade, and the file is left unchanged.

Explicit file-format progression from base logs to collections, then expiry and extended vectors, then property graphs, the default for new files. Open full-size diagram
Text diagram
flowchart LR
  V3["V1–V3<br/>base log"] --> V4["V4<br/>lineage · collections · import checkpoints"] --> V5["V5<br/>expiry · geo metadata · named/sparse vectors"] --> G["V5 + graph<br/>property graphs · default for new files"]
VersionAdds
1Put and delete frames; written only by older releases
2Atomic batches; written only by older releases
3Typed metadata
4Lineage, collections, settings and import checkpoints; enables the change feed
5Flags, encryption, commit timestamps, expiry, metadata-only updates, geo metadata, named and sparse vectors
5 + graphProperty graphs; the default for new files

Graph frames

Property graphs are stored in op 12 frames. Each frame changes one graph and commits as one unit, together with any vector writes it carries. Graph indexes are rebuilt when the file opens; there is no graph sidecar.

Each entry:

TagEntry
1, 2Create a graph; drop an empty graph
3Raise the next node and edge IDs
4–6Put, patch or delete a node
7–9Put, patch or delete an edge
10, 11Attach a node to a vector record; detach it
12Put the graph schema
64Vector write: a collection ID, then a batch entry

Sidecar files

Only the database file holds data. Every other file can be rebuilt, reissued or recreated.

FileHoldsIf lost or stale
data.vliteEvery committed record, collection and graphThis is your data; back it up
data.vlite.annHNSW snapshot (VLITEANN, SHA-256 trailer, up to 4 GiB), bound to the lineage, sequence and per-collection digestsAny commit makes it stale; the index is rebuilt instead
data.vlite.dannDisk ANN (VLDANN01, 128-byte header, 8 MiB default cache), bound to the lineage and revision it was built fromStale or damaged copies are refused; build it again

Snapshots are written to a staging file, synced and renamed into place. Encrypted databases refuse both ANN files, because they would hold plaintext vectors. The server keeps Disk ANN files in its admin directory as disk-ann-<collection id>.dann.

Server admin directory (VLITE_ADMIN_DIR):

FileHoldsIf lost
users.jsonAccounts and Argon2id password hashes; sessions stay in memoryRecreate the accounts
credentials.jsonAPI credentials, stored as SHA-256 hashes of their secretsReissue the tokens
tenants.jsonTenant registryTenant mappings are lost; records remain
webhooks.jsonWebhook subscriptions and delivery statsRegister the endpoints again
webhooks.cursorWebhook delivery positionDelivery restarts at the newest change; changes in between are skipped
audit.jsonlAudit log, rotated to audit.1.jsonl at 16 MiBAudit history only
next-startupWhich restored copy to open at the next startThe server opens its configured database path
backup-*.vlite
restore-*.vlite
Backups (each with a .manifest.json) and restored copies made through the API or dashboardOnly those copies

Write path

A write returns after its frame reaches the OS; a flusher syncs it within 60 s, or full durability syncs first. Indexes change only after that, so readers never see uncommitted data. A batch of up to 4,096 operations commits as one unit.

Commit sequence: validate, encode, append, synchronize (at once under full durability, else within 60 seconds), publish indexes and acknowledge; failed writes roll back or return an error. Open full-size diagram
Text diagram
sequenceDiagram
  autonumber
  participant App as Caller
  participant DB as Database (exclusive owner)
  participant Enc as format / crypto
  participant F as data.vlite
  participant Idx as In-memory indexes
  App->>DB: put / delete / write_batch
  DB->>DB: validate limits, dimensions, metadata
  DB->>Enc: encode frame (prefix, body, footer CRC)
  Enc-->>DB: bytes (sealed if encrypted)
  DB->>F: append at end of file
  opt Durability::Full
    DB->>F: sync_all()
  end
  alt append or fsync failed
    DB->>F: truncate to previous length + sync
    DB-->>App: error (state unchanged)
  else committed
    DB->>Idx: apply mutation, update HNSW / metadata / BM25
    DB-->>App: Ok
  end
  Note over DB,F: Periodic (default): a flusher syncs within 60 s

Recovery

Opening a file replays the log. A corrupt file and a torn tail from a crash are separate errors. Neither is fixed silently: an explicit repair removes only the unacknowledged last frame.

Recovery validates locking, headers and committed frames; corruption and incomplete tails return distinct errors; tail repair is explicit. Open full-size diagram
Text diagram
flowchart TD
  O["open(path)"] --> L{"try_lock()"}
  L -- "held elsewhere" --> EL["Error::Locked"]
  L -- "ok" --> H{"header magic,<br/>CRC, version, flags"}
  H -- "bad" --> EC["Error::Corrupt"]
  H -- "ok" --> N{"next frame"}
  N -- "end of file" --> R["rebuild indexes<br/>load ANN snapshot if identity matches"]
  N -- "fewer bytes than<br/>prefix / declared length" --> ET["Error::IncompleteTail<br/>(offset, bytes)"]
  N -- "bad magic, CRC,<br/>sequence or semantics" --> EC
  N -- "valid" --> AP["apply committed frame"] --> N
  R --> RDY["ready"]
  ET -. "explicit repair()" .-> TR["truncate torn tail"] --> O

Concurrency

One process owns a file for writing. Or several read-only processes share it while no writer has it open. The server runs reads in parallel and serializes writes.

A server owns an exclusive file lock; shared reader processes are an alternative mode, not concurrent with that writer. Open full-size diagram
Text diagram
flowchart LR
  subgraph Clients
    direction TB
    H1["HTTP request"]
    H2["HTTP request"]
    G1["gRPC stream"]
  end
  Clients --> AUTH["bearer auth · scopes · rate limit"] --> MX["RwLock#lt;Database#gt;"]
  MX -->|"shared guard"| READ["parallel read routes"]
  MX -->|"exclusive guard"| WRITE["commits · rebuild / publish"]
  READ --> CORE["one server-owned Database"]
  WRITE --> CORE
  CORE --> LK["exclusive OS file lock"] --> FILE[("data.vlite")]
  MX -. "snapshot" .-> BG["background HNSW build"] -. "catch up + publish" .-> WRITE
  subgraph Alternative["Alternative: writer closed"]
    R1["reader process · open_read_only"] --> SH["shared OS file locks"]
    R2["reader / MCP process · open_read_only"] --> SH
    SH --> RF[("data.vlite · open-time snapshots")]
  end
  LK -. "mutually exclusive modes" .-> SH

Records

A record has a 64-bit ID, a full-precision vector, an optional payload, typed metadata and an optional expiry. Indexes are built from these records when the file opens.

Records hold vectors, payload, metadata and expiry; vectors and metadata feed rebuildable indexes. Open full-size diagram
Text diagram
flowchart LR
  ID["u64 record id"] --> V["dense f32 vector<br/>+ named / versioned vectors"]
  ID --> P["payload bytes ≤ 1 MiB"]
  ID --> MD["typed metadata<br/>int · float · string · bool · geo"]
  ID --> EX["expiry / revision"]
  MD --> MP["ordered metadata postings ≤ 16 indexes"]
  MD --> TP["BM25 postings ≤ 8 text fields"]
  V --> HG["HNSW graph"]
  V --> QC["ScalarU8 codes"]

On disk (op 4 body):

Vectors are always stored as full-precision f32, even when an index uses ScalarU8. Metadata is a field count, then fields sorted by name, each with a type tag: 1 string, 2 integer, 3 float, 4 boolean or 5 geo point (v5). Op 9 puts a 9-byte expiry (a flag and a time in milliseconds) before the same body, and op 8 replaces only the metadata.

Query planner

A search uses HNSW only when a ready index matches its metric and settings. Otherwise it scans exactly. Lower distance is always nearer, and ties resolve deterministically.

Query planning chooses matching ready HNSW or exact scans, then returns deterministic top-k results. Open full-size diagram
Text diagram
flowchart TD
  Q["search(vector, k, filter)"] --> M{"metric"}
  M -- "inner_product" --> EX["exact scan"]
  M -- "squared_l2 / cosine" --> I{"ready HNSW with<br/>matching config, metric<br/>and quantization?"}
  I -- "yes" --> ANN["HNSW traversal<br/>ef_search ≥ k"]
  I -- "no" --> F{"filter uses<br/>metadata index?"}
  F -- "yes" --> CS["exact scan over<br/>candidate ID set"]
  F -- "no" --> EX
  ANN --> RR["exact f32 rerank"]
  CS --> TOP["top-k hits"]
  EX --> TOP
  RR --> TOP

HNSW and quantization

HNSW uses a seeded, deterministic level assignment. ScalarU8 shrinks vectors four times for traversal; final ranking uses the original vectors. See the traversal experiment.

ScalarU8 accelerates candidate traversal; final ranking uses original full-precision vectors. Open full-size diagram
Text diagram
flowchart LR
  R["f32 records"] -->|train per-dimension codebook| CB["ScalarU8 codes<br/>4× smaller"]
  Q["f32 query"] --> T["graph traversal<br/>asymmetric u8 distance"]
  CB --> T
  T --> C["candidates<br/>k × rerank multiplier"]
  C --> X["exact f32 distance"]
  R --> X
  X --> K["top-k"]
ParameterDefault
m16
ef_construction100
seed42
ef_searchPer query, at least k

Hybrid search

Dense and BM25 text search run separately. Weighted reciprocal-rank fusion merges the two rankings.

Dense and BM25 rankings merge through weighted reciprocal-rank fusion into top-k results. Open full-size diagram
Text diagram
flowchart LR
  Q["query"] --> D["dense leg<br/>planner → ranked ids"]
  Q --> T["text leg<br/>BM25 → ranked ids"]
  D --> F["weighted RRF<br/>Σ weight / (60 + rank)"]
  T --> F
  F --> K["fused top-k ≤ 1,000"]

Encryption and tenants

Optional encryption seals each frame body with ChaCha20-Poly1305, using a key derived from your passphrase with Argon2id. Frame headers stay readable so recovery still works. Encrypted databases refuse ANN files on disk, which would hold plaintext vectors. Tenants are logical namespaces in one file, not separate files or encryption domains.

Argon2id derives a key for encrypted frame bodies; plaintext ANN sidecars are refused; logical tenants share one file. Open full-size diagram
Text diagram
flowchart LR
  PW["passphrase"] -->|Argon2id| K["256-bit key"]
  K --> S["seal frame body<br/>ChaCha20-Poly1305"]
  S --> F[("data.vlite<br/>header + descriptor + sealed frames")]
  F -. "plaintext sidecars refused" .-x DA[".ann · .dann"]
  subgraph Tenancy["One file, logical tenants"]
    T1["tenant A · docs"] --> N1["t#lt;hexA#gt;__docs"]
    T2["tenant B · docs"] --> N2["t#lt;hexB#gt;__docs"]
  end

Changes, restore and replicas

Change feeds, webhooks, replicas, backups and point-in-time restore all read the same committed frames.

Committed frames feed change capture, replication, webhooks, backups and point-in-time restore. Open full-size diagram
Text diagram
flowchart LR
  F[("committed frames<br/>seq 1..n")] --> CF["/v1/changes<br/>durable cursor · ≤ 10,000 events"]
  F --> SEG["log segments<br/>whole commits · checksummed"]
  SEG --> RF["ReplicaFollower"]
  CF --> WH["webhooks<br/>at-least-once"]
  F --> BK["backup"] --> PITR["restore to commit<br/>sequence or timestamp"]

Server

vlite-server owns one database. REST and gRPC share authentication, roles, rate limits and metrics. Remote access requires --allow-remote and authentication; TLS does not replace authentication.

REST and gRPC share authentication, authorization and a Database lock; operations surfaces expose logs and metrics. Open full-size diagram
Text diagram
flowchart LR
  CL["client"] -->|"TLS 1.2/1.3 · rustls"| L{"listener"}
  L -->|"/v1/..."| R["REST · Axum"]
  L -->|"vlite.v1.VLite"| G["gRPC · tonic<br/>8 MiB messages"]
  R --> A["bearer token<br/>role · scopes · tenant"]
  G --> A
  A --> RL["token-bucket<br/>rate limit"] --> DB["RwLock#lt;Database#gt;"]
  A -.-> AU["audit.jsonl"]
  DB -.-> OB["metrics: JSON · Prometheus<br/>OTLP traces"]
  R -. "sanitized access events" .-> LOG["in-memory structured log ring<br/>--log-buffer · default 2000"]
  LOG --> LG["GET /v1/admin/logs<br/>since · level · q · limit"]
  OB --> SUM["GET /v1/admin/metrics/summary"]
  LG --> UI["dashboard Observability<br/>cards · route table · live tail"]
  SUM --> UI

Bindings

Python and Node.js call the engine through a handle-based C ABI. Closing the handle releases the file lock.

Python and Node send handle-based requests through the C ABI to Database and release the handle on close. Open full-size diagram
Text diagram
sequenceDiagram
  participant L as Python / Node
  participant C as C ABI
  participant D as Database
  L->>C: open(path) → u64 handle
  L->>C: vlite_execute(handle, request bytes)
  C->>D: decode + dispatch
  D-->>C: result / typed error
  C-->>L: response string (freed by caller)
  L->>C: close(handle) → releases file lock

Limits

ItemMaximum
Dimensions65,536
Payload1 MiB
Metadata64 fields, 64 KiB
Batch4,096 operations, 16 MiB
Frame body256 MiB
Collections64; names up to 63 bytes
Collection settings16 KiB
Metadata indexes16
Text fields8
Filter conditions64
Hybrid results1,000
Graphs64 per file; 4,096 entries and 16 MiB per frame
Tenants1,024 over the server's lifetime

Limitations

More detail: Reference · Storage features · Security