Documentation

Collections and advanced retrieval

These APIs extend the embedded engine. Plain Database methods use the default collection, and files are never upgraded automatically.

File compatibility and collections

Database::create makes a v3 file. Create v4 for named collections and durable import checkpoints:

use vlite::{CollectionSettings, CollectionSpec, Database, FormatVersion};

# fn example() -> vlite::Result<()> {
let mut db = Database::create_with_format("new.vlite", 3, FormatVersion::V4)?;
db.create_collection("documents", CollectionSpec {
    dimensions: 768,
    settings: CollectionSettings::default(),
})?;
db.collection_mut("documents")?.put(1, &vec![0.1; 768], b"document")?;
db.close()?;
# Ok(()) }

cargo run --locked --example collections -- new-example.vlite runs an end-to-end example of this page's features. It refuses an existing output file.

Each collection has its own dimensions, record IDs, settings and derived indexes. default cannot be dropped; a named collection can be dropped only when it is empty and has no open import job. Invalid settings and exceeded limits fail without creating anything.

Older binaries cannot open v4 files. Stop the file's owner, then upgrade to a new, nonexistent path and keep the original:

cargo run --bin vlite-maintain -- upgrade old.vlite new.vlite
cargo run --bin vlite-maintain -- verify new.vlite

Upgrading a copy does not switch a running service; verify the new file, then select it. v4 restore and compaction assign a new file identity, and derived indexes are rebuilt rather than stored.

Collection IDs are never reused within a v4 lineage, including across copy-out maintenance. When the ID space runs out, creating a collection fails without writing, even below the live-collection limit. A closed import keeps its collection name and a dropped flag, so recreating the name cannot resume it.

Error is #[non_exhaustive]; match it with a wildcard arm.

Opt-in v5 record features

Create a FormatVersion::V5 file for record expiry, GeoPoint metadata and metadata-only updates. Opening never migrates a file, v1–v4 files behave as before, and older binaries reject v5.

These query-time operations need no persistent indexes.

Record revisions

revision(id) returns the sequence of the record's last successful put. Revisions are per collection and record, and records in one atomic batch can share a revision, so never compare bare revisions across files, collections or IDs. Expected::Absent and Expected::Revision(revision) make puts and deletes conditional; a mismatch writes nothing. The check and the write use the same exclusively owned handle.

Metadata indexes and automatic planning

Declare indexes in CollectionSettings::metadata_indexes with MetadataIndexSpec and MetadataIndexKind::{Eq, Range, EqRange}. They update after each successful commit and are rebuilt on reopen or settings replacement. Candidates are always rechecked against the full typed filter, and indexed exact results match an unindexed scan: same IDs, distances and order.

CollectionRef::search_auto_with_settings(query, k, conditions, ef_search) returns hits, the chosen QueryPlan and SearchStats. It chooses exact_scan, exact_indexed, ann or filtered_ann: selective indexed queries score candidates exactly, broad queries can use a ready ANN index, and missing indexes mean exact search. Auto mode never builds an ANN index.

Settings persist in v4. On a legacy default collection they are memory-only, reported as SettingsPersistence::MemoryOnly.

Index up to eight string metadata fields with CollectionSettings::text_fields; payloads are not indexed. Text is split on non-alphanumeric characters and lowercased, with no stemming, phrase search or language-specific analysis. Token, query and posting limits apply. If the posting limit disables the index, writes still succeed and text queries return a readiness error.

HybridQuery::new(Some(vector), text, k) fuses vector and BM25 results with weighted reciprocal rank fusion, applying the same metadata filter to both. Fusion scores are not distances: higher is better, and ties break by ID. Hits include each leg's rank, the vector distance if any, and the BM25 score. The default vector leg is exact; VectorLeg::ApproximateReady never builds an index and can miss candidates. Candidate depth and weights change results.

Quantized ANN, memory and quality

Pass AnnOptions { quantization: Quantization::ScalarU8, rerank_multiplier: 4 } to the *_with_options APIs. Traversal uses scalar-u8 codes, then reranks candidates with exact distances from the current f32 vectors; buffered writes and metadata filters also use current records. Quantization is part of the index identity, so legacy APIs never use a quantized graph.

ann_memory reports component bytes for graph links, codes and codebook, buffer and resident vectors. These are not measured process RSS. The f32 vectors stay resident, so quantization can add code storage and does not promise lower total memory. ann_quality samples a ready index against exact search within a budget and reports a reason when it skips. Recall depends on the workload and is not guaranteed. The benchmark guide reproduces a bounded comparison.

Resumable ingestion

On v4, import_chunk(job, chunk, operations, policy) atomically commits accepted rows and a durable checkpoint in one synchronized frame. Legacy files return ImportsRequireUpgrade.

REST service and scoped credentials

vlite-server ... --create-if-missing --create-format 4 creates a v4 database; the default is a graph-enabled v5 file, and existing files are never migrated. GET /v1/capabilities reports the format, role and supported flags.

Automatic maintenance and backups

Both are off by default.

Operational diagnostics

Read-only diagnostics still check permissions. Inspect backend errors and skipped maintenance or backup work; do not treat them as success.

Embedded vector extensions

v5 also supports named and multi-vector records, bounded per-model embedding history, sparse inverted-index dot-product search, dense/sparse RRF, and resumable, revision-checked re-embedding with an atomic switch of the active version. Provider and reranker traits and a read-only query language are Rust APIs. See VECTORS.md for APIs, grammar, limits and examples.

Property graphs

Every build since v0.5.1 can store named property graphs in graph-enabled v5 files, which older releases refuse. Every new file is graph-enabled unless an explicit v3/v4 format is requested; copy an older file with vlite-maintain enable-graph. See GRAPH.md.

View or edit this page on GitHub ↗