Skip to main content

BruteForceVectorIndex

Struct BruteForceVectorIndex 

Source
pub struct BruteForceVectorIndex { /* private fields */ }
Expand description

A cosine-similarity brute-force vector index.

Stores L2-normalised f32 vectors in a flat row-major buffer for cache-friendly linear scans. search(q, k) is O(n * dim) in time and O(n) in allocations; a min-heap optimisation is not worth the complexity at the corpus sizes this impl targets (see module docs).

Implementations§

Source§

impl BruteForceVectorIndex

Source

pub fn empty(model: impl Into<String>, dim: u32) -> Self

Construct an empty index for (model, dim).

Agents who want to stream insert rather than build from a repo can start here. The repo-scan path (Self::build_from_repo) is the common case.

Source

pub fn model(&self) -> &str

Model identifier this index is bound to (e.g. "openai:text-embedding-3-small"). Exposed so downstream consumers (e.g. the KNN-edge derivation in mnem-http’s GraphCache) can tag their derived artefacts with the same model string the vectors were indexed under.

Source

pub const fn dim(&self) -> u32

Dimensionality of every stored vector. 0 iff the index was empty()-constructed and never inserted into.

Source

pub fn is_empty(&self) -> bool

true iff no vectors were indexed.

Source

pub fn points_iter(&self) -> impl Iterator<Item = (NodeId, &[f32])> + '_

Iterate (node_id, unit_vector_slice) pairs in build order (canonical Prolly-key order at build time). The returned slice is borrowed from the flat row-major buffer; every row is already L2-normalised so cosine == dot product.

Used by mnem-http’s GraphCache KNN-edge fallback to derive a deterministic KNN-edge substrate when the authored-edges adjacency is empty (experiment E0 wire activation). Returning a borrowed slice avoids the per-row to_vec() clone the HNSW variant pays.

Source

pub fn try_insert(&mut self, node_id: NodeId, embed: &Embedding) -> bool

Insert one node’s embedding. The node’s embedding MUST match self.model and self.dim; mismatched entries are silently skipped so callers can feed a heterogeneous stream.

Returns true if the vector was indexed, false if it was skipped (wrong model, wrong dim, absent, or undecodable).

Source

pub fn build_from_repo(repo: &ReadonlyRepo, model: &str) -> Result<Self, Error>

Build an index over every node at the repo head whose embedding under model is present in the per-commit sidecar (Commit.embeddings Prolly tree, keyed by NodeCid). Nodes without a sidecar entry under model are silently skipped.

The sidecar is the only source of truth: dense vectors live in a separate tree so nondeterministic producers (e.g. ORT thread-count drift) cannot leak into NodeCid and break federated dedup. Operators with repos authored before the sidecar shipped must run mnem reindex to lift inline vectors into the sidecar; until then those vectors are invisible to retrieval.

§Errors

Trait Implementations§

Source§

impl Clone for BruteForceVectorIndex

Source§

fn clone(&self) -> BruteForceVectorIndex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BruteForceVectorIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl VectorIndex for BruteForceVectorIndex

Source§

fn model(&self) -> &str

Embedding model this index was built for.
Source§

fn dim(&self) -> u32

Vector dimension the index accepts on queries.
Source§

fn search(&self, query: &[f32], k: usize) -> Result<Vec<VectorHit>, Error>

Nearest-neighbour lookup. Returns up to k hits. Read more
Source§

fn len(&self) -> usize

Number of indexed vectors.
Source§

fn is_empty(&self) -> bool

true iff no vectors were indexed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more