Skip to main content

Crate oneai_vector

Crate oneai_vector 

Source
Expand description

OneAI default retrieval backend stack.

Implements the retrieval-backend traits declared in [oneai-core::traits] (VectorBackend, KeywordBackend, RetrievalBackend, RerankerProvider) using the P0-spike-verified library set (2026-07-26):

BackendCrateFeatureRole
InMemoryVectorBackend(std only)alwaysbrute-force cosine, tests/tiny sets
SqliteVecBackendsqlite-vecsqliteexact KNN via vec0, mobile/small
UsearchBackendusearchusearchHNSW + mmap + pre-filter
TantivyBm25Backendtantivy + tantivy-jiebatantivyCJK BM25
[BgeM3Embedder]ortortlocal BGE-M3 dense embeddings
[BgeRerankerOnnx]ortortlocal bge-reranker-v2-m3 cross-encoder
StandardRetrievalPipeline(composes the above)defaultBM25+dense → RRF → rerank

§The non-negotiable default pipeline

StandardRetrievalPipeline runs BM25 + dense → RRF(k=60) → rerank (top-150 → top-K), which Anthropic’s “Contextual Retrieval” evaluation showed cuts top-20 retrieval failure rate by 67%. An app that implements its own [RetrievalBackend] (e.g. Qdrant, which does hybrid natively) bypasses this pipeline — the trait docs in oneai-core say explicitly that skipping the keyword/sparse leg degrades Chinese short queries and unique-identifier lookups, so dropping BM25 is an informed decision.

§Feature flags

  • default = ["sqlite", "usearch", "tantivy"] — the storage backends + BM25 + the pipeline all build without network access. The pipeline can take any EmbeddingService (the ones in oneai-rag, or BgeM3Embedder when ort is on).
  • ort — local ONNX embedder + reranker. Off by default because ort-sys downloads a prebuilt libonnxruntime blob and the embedder needs ONNX model files at runtime. Enable with --features ort.

§Design principle

These implementations must NOT leak storage-internal types — an app that brings Qdrant/Milvus/pgvector/Elasticsearch implements against the public oneai-core trait surface, not against these internals. Backends here are the reference embedded stack.

unsafe is confined to the sqlite-vec static-registration shim (a single FFI transmute required to register sqlite3_vec_init as a SQLite auto extension; every other backend is pure safe Rust over its crate’s API).

Re-exports§

pub use fusion::dbsf_fuse;
pub use fusion::rrf_fuse;
pub use in_memory::InMemoryVectorBackend;
pub use pipeline::StandardRetrievalPipeline;
pub use pipeline::StandardRetrievalPipelineBuilder;
pub use pipeline::StandardRetrievalPipelineConfig;
pub use sqlite_vec::SqliteVecBackend;
pub use tantivy_bm25::TantivyBm25Backend;
pub use usearch_backend::UsearchBackend;

Modules§

fusion
Fusion helpers for multi-leg retrieval.
in_memory
In-memory brute-force cosine VectorBackend.
pipeline
The reference hybrid retrieval pipeline — RetrievalBackend composed from a VectorBackend + KeywordBackend + optional EmbeddingService + optional RerankerProvider.
sqlite_vec
VectorBackend backed by [sqlite-vec] exact KNN.
tantivy_bm25
KeywordBackend backed by tantivy + [tantivy-jieba] CJK BM25.
usearch_backend
VectorBackend backed by usearch HNSW ANN.

Functions§

cosine
Cosine similarity between two equal-length vectors. Both must be non-empty and the same length; returns 0.0 for a zero-norm query (degenerate, no direction) rather than dividing by ~0.