Skip to main content

Module vector

Module vector 

Source
Expand description

Vector-search primitive for mnem.

Provides a VectorIndex trait and a default BruteForceVectorIndex implementation (cosine-similarity linear scan, built in memory from the current repo head).

§Model scoping

Embeddings produced by different models occupy different semantic spaces: an openai:text-embedding-3-small vector cannot be mixed with a nomic:embed-text-v1.5 vector even if they share a dimension. Each BruteForceVectorIndex therefore binds to a single (model, dim) pair at build time and silently skips nodes with other embeddings. Agents that use several models build one index per model.

§Determinism

Build order is the canonical Prolly-tree key order, ties break on NodeId ASC, and scores are computed from stored normalised f32 vectors. Given the same repo head and the same query, two independent processes return byte-identical hit lists.

§Example

let idx = BruteForceVectorIndex::build_from_repo(repo, "openai:text-embedding-3-small")?;
let hits = idx.search(query, 5)?;
for h in hits {
println!("{} @ {:.4}", h.node_id, h.score);
}

§Why brute force?

Brute force is the correctness baseline every ANN system is measured against. It has zero hyperparameters, trivial determinism, no background build phase, and costs nothing in deps. For agent workloads in the <=100k-vector range (the common case) a tight vector-row dot product hits <20 ms per query on a laptop. HNSW lands as a sibling impl under the same trait once corpus sizes justify the added complexity.

Structs§

BruteForceVectorIndex
A cosine-similarity brute-force vector index.
VectorHit
One scored match returned by a VectorIndex search.

Traits§

VectorIndex
Read-only approximate-nearest-neighbours surface for node embeddings.