Expand description
Exact vector storage and scoring. Persistent HNSW lives in vector_graph.
Storage layout
──────────────
Meta table : meta::vector_indexes
key : <collection>::<field> (UTF-8)
value : postcard-serialised VectorDef
Vector table: vec::<collection>::<field>
key : ULID bytes (16 B, big-endian)
value : raw f32 LE bytes (dimensions × 4 B)
Structs§
- Cached
Vectors - Decoded vectors for one
collection::field, tagged with its vector revision. - Hnsw
Options - Configuration for an HNSW vector index.
- Vector
Block - Contiguous decoded vectors; IDs and values avoid one allocation per vector.
- Vector
Def - Vector
Search Result - A single result returned by
Collection::find_nearest.
Enums§
- Vector
Metric - Similarity metric used when searching a vector index.
Constants§
- DEFAULT_
VECTOR_ CACHE_ BYTES - Maximum retained decoded vector bytes per database. Oversized indexes stream.
- META_
HNSW_ TABLE - Stores HNSW options: key =
"{collection}::{field}", value = postcardHnswOptions. - META_
VECTOR_ TABLE
Functions§
- compute_
similarity - cosine_
similarity - decode_
f32_ vec - Decode little-endian bytes back to
Vec<f32>. ReturnsNoneifbytes.len()is not a multiple of 4. - dot_
similarity - encode_
f32_ vec - Encode a
&[f32]as little-endian bytes. - euclidean_
similarity - Converts Euclidean distance to a similarity score in
(0, 1]. Identical vectors → 1.0; the further apart, the closer to 0. - hnsw_
table_ name - HNSW graph blob table:
hnsw::{collection}::{field}, single key =b"graph". - l2_norm
- L2 (Euclidean) norm of a vector. Hoist this out of a scan loop for cosine —
the query’s norm is constant across every candidate, so recomputing it per
candidate (as
cosine_similaritydoes) wastes one dot+sqrt per stored vector. - new_
shared_ vector_ cache - norm_sq
- The norm half of [
dot_and_norm_sq], on its own. - score_
with_ norms score_with_query_normwith the stored vector’s squared norm also known.- score_
with_ query_ norm compute_similaritywith the query’s L2 norm supplied by the caller.- value_
to_ f32_ vec - Extract a float vector from a document field value.
Accepts
Value::Arraywhose elements are all numeric (FloatorInt). ReturnsNoneif the value is not a numeric array. - vec_
meta_ key - vec_
table_ name
Type Aliases§
- Shared
Vector Cache - Shared across every
Collectionhandle from the sameDatabase, so a write through one handle invalidates reads through another. - Vector
Cache Map