Skip to main content

Module vector_backend

Module vector_backend 

Source
Expand description

Vector index backend trait.

This trait is the abstraction layer over the concrete ANN backend (hnsw_rs or usearch). It exposes a stable interface that the rest of the crate (search.rs, hnsw_ops.rs, config.rs, lib.rs) uses, so that switching the backend is a matter of which impl is wired in at the hnsw_ops::rebuild_* and HnswIndex factory call sites.

§Design notes

  • The VectorBackend trait is intentionally minimal: just enough surface to satisfy the 8 call sites that currently use hnsw_rs.
  • All backends return Result<_, MemoryError> so error handling at the trait boundary doesn’t leak backend-specific error types.
  • HnswHit is renamed to VectorHit in the trait surface, but a type alias pub type HnswHit = VectorHit; is preserved for source compatibility with downstream consumers.
  • HnswConfig is kept as the user-facing config name (it’s a public type). The trait receives a VectorIndexConfig internally; the From<HnswConfig> impl bridges them.

§Backend implementations

  • HnswBackend (in hnsw_backend.rs, gated on feature = "hnsw"): the existing hnsw_rs 0.3 wrapper, behavior-preserving.
  • UsearchBackend (in usearch_backend.rs, gated on feature = "usearch-backend"): the new cxx-bridge to usearch 2.25. This file is the destination of the migration; until it’s wired in it is a stub that returns MemoryError::Unimplemented.

§Backwards compatibility

HnswIndex is renamed to VectorIndex (a thin newtype around Arc<dyn VectorBackend + Send + Sync>). The old name is preserved as a deprecated type alias to avoid breaking downstream consumers like forge-pilot, llm-pipeline, and kernel-conformance that import semantic_memory::hnsw::HnswIndex directly.

Structs§

VectorHit
User-facing hit from a vector search.
VectorIndex
Thread-safe handle to a vector index.
VectorIndexConfig
Configuration for the vector index.

Traits§

VectorBackend
Core vector index operations. All concrete backends implement this.