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):
| Backend | Crate | Feature | Role |
|---|---|---|---|
InMemoryVectorBackend | (std only) | always | brute-force cosine, tests/tiny sets |
SqliteVecBackend | sqlite-vec | sqlite | exact KNN via vec0, mobile/small |
UsearchBackend | usearch | usearch | HNSW + mmap + pre-filter |
TantivyBm25Backend | tantivy + tantivy-jieba | tantivy | CJK BM25 |
[BgeM3Embedder] | ort | ort | local BGE-M3 dense embeddings |
[BgeRerankerOnnx] | ort | ort | local bge-reranker-v2-m3 cross-encoder |
StandardRetrievalPipeline | (composes the above) | default | BM25+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 anyEmbeddingService(the ones inoneai-rag, orBgeM3Embedderwhenortis on).ort— local ONNX embedder + reranker. Off by default becauseort-sysdownloads a prebuiltlibonnxruntimeblob 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 —
RetrievalBackendcomposed from aVectorBackend+KeywordBackend+ optionalEmbeddingService+ optionalRerankerProvider. - sqlite_
vec VectorBackendbacked by [sqlite-vec] exact KNN.- tantivy_
bm25 KeywordBackendbacked bytantivy+ [tantivy-jieba] CJK BM25.- usearch_
backend VectorBackendbacked byusearchHNSW 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.