Expand description
Itzma core: object-storage-backed vector retrieval.
Vectors live as plain objects in a bucket. There is no server in the middle: any process with access to the bucket can write, and any process can query. Correctness comes from two primitives the object store already provides, put-if-absent and conditional update.
§Where to start
Namespace is the public API. Create one, upsert documents, query
for nearest neighbors:
use std::sync::Arc;
use itzma_core::{Document, Metric, Namespace, Schema};
use object_store::memory::InMemory;
let store = Arc::new(InMemory::new());
let schema = Schema::new(2, Metric::L2);
let ns = Namespace::create(store, "docs", schema).await?;
ns.upsert(vec![Document { id: "a".into(), vector: vec![1.0, 0.0], attrs: None, sparse: None }]).await?;
let hits = ns.query(&[0.0, 0.0], 5).await?;
assert_eq!(hits[0].id, "a");Any Arc<dyn object_store::ObjectStore> works as the backend: in-memory
for tests, local disk, or S3, GCS and Azure. Note that LocalFileSystem
does not implement conditional update, which manifest::update,
manifest::update_if and so Namespace::compact and
Namespace::upgrade_wal_format and Namespace::upgrade_segment_format need.
§Modules
| Module | Job |
|---|---|
namespace | The Namespace handle: create, open, upsert, delete (each also keyed), query, query_sparse, filter, index, index_sparse, compact, gc, maintain, recover |
document | Document, WalOp, Schema, Metric |
attrs | AttrSchema, AttrType: the typed attribute fields a namespace declares |
predicate | Predicate: a typed condition over attributes |
filter | FilterOptions, FilterPage, Row and the run behind Namespace::filter |
wal | Sequenced write-ahead log: wal::append, wal::append_keyed, wal::read_log |
manifest | The namespace manifest and its compare-and-swap update |
schema_object | schema.json, the schema written once at create |
segment | Segment binary codecs (versions 2 and 3), ids, and the manifest invariant check |
layer | layer::Layer: the net effect of applying operations in order |
compaction | Compaction, CompactionOptions and the run behind Namespace::compact |
gc | GcOptions, GcReport and the run behind Namespace::gc |
indexer | IndexOptions, IndexReport and the run behind Namespace::index |
sparse | SparseVector storage beside a segment: sparse.bin |
attr_indexer | IndexAttrsOptions, IndexAttrsReport and the run behind Namespace::index_attrs |
sparse_indexer | IndexSparseOptions, IndexSparseReport and the run behind Namespace::index_sparse |
maintain | MaintenanceOptions and the run behind Namespace::maintain |
columns | DocColumns: a batch of upserts held as columns, for Arrow input |
lease | MaintenanceLease: which process maintains a namespace |
inspect | inspect::report: a read-only look at what a namespace holds and what looks wrong |
search | Distance metrics and the flat top-k scan |
error | ItzmaError and Result |
A query or a compaction run reads at most a byte budget, DEFAULT_READ_BUDGET unless set
with Namespace::with_read_budget, and stops with ItzmaError::ReadBudgetExceeded past
it.
wal, manifest, layer, segment and compaction are public so
integration tests can drive them directly. Application code should stay on
Namespace.
§On-disk layout
<namespace>/
schema.json dimension, metric and attribute types, written once, never changed
maintenance/lease.json which process maintains the namespace, written by a loop's lease
gc/fenced-through how far the WAL fences reach, a hint for `gc` (only with fence_wal)
manifest/current.json schema, live segments, WAL fold point
wal/00000000000000000001.json one object per write batch (binary, see below)
wal/00000000000000000002.json
segments/<lo>-<hi>/data.bin compacted data, named by the WAL range it covers
segments/<lo>-<hi>/index-<n>.bin an index of that segment, generation n, once `index` built one
segments/<lo>-<hi>/sparse.bin the segment's sparse vectors, only if a document has one
segments/<lo>-<hi>/sparse-idx-<n>.bin its sparse inverted index, once `index_sparse` built oneThe manifest is JSON. WAL objects and segments are binary, and a WAL object
is ZSTD-compressed when that makes it smaller. The WAL key keeps
its .json suffix on purpose: every writer has to try the same key for the
same sequence number, or put-if-absent stops deciding the race. A write that carries an
idempotency key (WriteKey) is version 3, the same object with the key in
the header. A batch with a sparse vector is version 4, or 5 with a key.
Nothing in the layout is ever overwritten but the manifest, and the WAL
objects that Namespace::gc is asked to fence. GC deletes segments that a
merge or a later fold superseded, and with
GcOptions::fence_wal replaces folded WAL objects with 8-byte fences that
keep put-if-absent working at their keys. Nothing else is removed. The
schema is kept in the manifest and again in schema.json, which is
written once, so losing the manifest does not lose it.
Namespace::recover then writes a new manifest from the schema object, the
segment names and the WAL listing.
Namespace::maintain is the call to schedule: it compacts when the WAL tail
is long enough and then collects.
Every object carries a format_version so the encoding can change later. A
reader that meets a version it does not know fails with
ItzmaError::UnsupportedFormat instead of guessing. The manifest also
records the newest WAL format the namespace may contain, and a build that
reads an older one refuses the namespace with
ItzmaError::WalFormatTooNew before it touches the WAL.
Namespace::upgrade_wal_format raises that level, one way. A second level,
segment_format, does the same for segments: a build that reads an older
segment format is refused with ItzmaError::SegmentFormatTooNew, and
Namespace::upgrade_segment_format raises it. Compaction writes
the segment version that level allows.
Re-exports§
pub use attr_indexer::IndexAttrsOptions;pub use attr_indexer::IndexAttrsReport;pub use attrs::AttrSchema;pub use attrs::AttrType;pub use columns::AttrColumn;pub use columns::DocColumns;pub use columns::SparseColumn;pub use compaction::Compaction;pub use compaction::CompactionOptions;pub use document::Document;pub use document::Metric;pub use document::Schema;pub use document::SparseVector;pub use document::WalOp;pub use error::ItzmaError;pub use error::Result;pub use filter::FilterOptions;pub use filter::FilterPage;pub use filter::Row;pub use gc::GcOptions;pub use gc::GcReport;pub use indexer::IndexKind;pub use indexer::IndexOptions;pub use indexer::IndexReport;pub use lease::DEFAULT_LEASE_RENEW;pub use lease::DEFAULT_LEASE_TTL;pub use lease::LeaseOptions;pub use lease::MaintenanceLease;pub use lease::Role;pub use maintain::CompactTrigger;pub use maintain::MaintenanceOptions;pub use maintain::MaintenanceReport;pub use manifest::AttrIndexEntry;pub use manifest::IndexEntry;pub use manifest::Manifest;pub use manifest::SparseIndexEntry;pub use namespace::Namespace;pub use predicate::AttrValue;pub use predicate::Compare;pub use predicate::Predicate;pub use predicate::TextCompare;pub use recover::RecoverReport;pub use search::Hit;pub use segment::Matrix;pub use sparse_indexer::IndexSparseOptions;pub use sparse_indexer::IndexSparseReport;pub use wal::WriteKey;
Modules§
- attr_
indexer - Building the attribute index of one segment and publishing it:
Namespace::index_attrsindexes each live segment in turn. Mirrorssparse_indexer.rs’s shape — put-if-absent, then one manifest compare-and-swap — but reads the whole segment the wayindexer.rs’s dense index does (there is nomin_rowsfloor: building this index is one pass over attributes already being decoded, not a quantization or graph build). - attrs
- Typed attributes: the declared type of each field, and the check
a document’s
attrshas to pass to be written. - columns
- A batch of upserts held as columns.
- compaction
- Compaction: fold the WAL tail into a segment, or merge the segments.
- document
- The data model: documents, WAL operations, and the per-namespace schema.
- error
- The error type shared by every module in the crate.
- filter
- The filter-only query behind
Namespace::filter: one page of the id-order merge, read a block at a time, with the predicate tested on each winner. - gc
- Garbage collection: dead segments, and optionally old WAL objects.
- indexer
- Building the index of one segment and publishing it:
Namespace::indexindexes each live segment in turn. - inspect
- A read-only look at one namespace: what is stored and what looks wrong.
- layer
- Layers: the net effect of applying operations in order.
- lease
- The maintenance lease: which of the processes sharing a namespace runs its maintenance.
- maintain
- Maintenance: decide whether a compaction is due, run it, then collect.
- manifest
- The namespace manifest and its compare-and-swap update.
- namespace
- The
Namespacehandle: the public entry point for reading and writing. - predicate
- Filter predicates.
- quant
- Scalar quantization to one byte per dimension (the SQ8 codec), public so code outside this crate can reuse the exact quantization the SQ8 index uses instead of a second implementation that could drift from it.
- recover
- Rebuilding a lost manifest.
- scan
- Reading a namespace in id order:
Namespace::scanand the k-way merge it shares withNamespace::filter. - schema_
object - The schema object:
<namespace>/schema.json. - search
- Flat (brute-force) nearest-neighbor search.
- segment
- Segments: immutable binary snapshots of a layer.
- sparse
- The
sparse.binsidecar: one segment’s raw sparse vectors, row-addressed the same waydata.bin’s dense matrix is. Written by compaction only when at least one document in the segment has one (crate::compaction); read whole byNamespace::index_sparseto build the inverted index, and by the query engine’s unindexed-segment fallback. - sparse_
indexer - Building the sparse inverted index of one segment and publishing it
:
Namespace::index_sparse. Mirrorsindexer.rs’s shape for the dense index — put-if-absent, then one manifest compare-and-swap — with one algorithm, so there is nokind. - wal
- The write-ahead log, sequenced by put-if-absent.
Structs§
- Cache
Options - How to size
CacheStore’s tiers.nvmeis optional — omit it for a RAM-only cache (tests, or a deployment with no local disk to spare). - Cache
Store - A read-through cache in front of a real
ObjectStore: RAM first, then a local NVMe cache (if configured), theninner. Only reads are cached —put,delete,listandcopypass straight through, since every object here is immutable once written and there is nothing to invalidate, only capacity to manage. - CpuThreads
- Thread counts for this process’s two compute pools.
- Decoded
Cache - Parsed index heads, partitions, segment directories, blocks and decoded
segments, shared by every handle given it with
Namespace::with_decoded_cache. - Decoded
Cache Options - How a
DecodedCacheis sized. - Fetch
Policy - How a ranged read turns “these pieces of this object” into requests.
Chosen per store kind (see
FetchPolicy::local,FetchPolicy::object_store) and set on aNamespacewithwith_fetch_policy. - Gate
Options - The limits of one
GatedStore. - Gated
Store - An
ObjectStorewrapper that admits reads only while the bytes and the requests in flight stay under itsGateOptions. - Nvme
Options - The local NVMe tier’s settings.
- Query
Options - Settings for
Namespace::query_with. - Sparse
Query Options - Settings for
Namespace::query_sparse. - Stream
Error - A stream that stopped: the error, and what landed before it. Every
object in
landedis whole and in the WAL, one after the other. - Stream
Options - How
Namespace::upsert_streamcuts and queues a stream. - Stream
Report - What a stream wrote: the first and last seq it landed at, and how many
rows and objects. On an error,
StreamError::landedis this for what landed before it. - Upload
Options - How a handle writes segments and their sidecars, set with
Namespace::with_upload_options.
Constants§
- DEFAULT_
DECODED_ MAX_ BYTES - The limit a
DecodedCachehas when the caller does not say: 256 MiB. - DEFAULT_
FALLBACK_ MAX - The default
UploadOptions::fallback_max: 256 MiB. - DEFAULT_
GATE_ MAX_ BYTES - Default
GateOptions::max_bytesof a query gate: 64 MiB in flight. - DEFAULT_
GATE_ MAX_ REQUESTS - Default
GateOptions::max_requests: 256 reads in flight. - DEFAULT_
PART_ SIZE - The default
UploadOptions::part_size: 8 MiB. S3 needs at least 5 MiB in every part but the last. - DEFAULT_
RAM_ MAX_ BYTES - A RAM-only default: 256 MiB. A guess with no workload behind it yet, the
same caveat
DEFAULT_READ_BUDGETandCompactTrigger’s defaults already carry — this is a starting point to tune from real usage, not a measured number. - DEFAULT_
READ_ BUDGET - The default read budget of a
Namespace: 1 GiB. - DEFAULT_
RERANK - The default for
QueryOptions::rerank, a guess until the recall harness has measured one. - DEFAULT_
STREAM_ ABOVE - The default
UploadOptions::stream_above: 64 MiB. - DEFAULT_
STREAM_ DEPTH - The default
StreamOptions::depth. - DEFAULT_
STREAM_ TARGET_ BYTES - The default
StreamOptions::target_bytes: half the WAL’s 64 MiB body limit, so a chunk’s own estimate never pushes it over. - DEFAULT_
UPLOAD_ CONCURRENCY - The default
UploadOptions::concurrency. - MIN_
PART_ SIZE - The smallest
UploadOptions::part_size: 5 MiB, S3’s smallest part.
Functions§
- configure_
cpu - Set the thread counts of this process’s compute pools. The pools belong to
the process, not to a
Namespace, so this is called once, before the first query or build. A forked child has no pools yet and may call it again.