Expand description
Lightweight, ndarray-native, Arrow-zero-copy compute and rerank layer for embedding vectors.
Bring vectors from any model, compute exactly, deploy anywhere. nabled-embeddings composes
existing nabled-linalg vector kernels and nabled-ml PCA into the post-embedding numerics a
retrieval pipeline needs: normalize, score, rerank, exact brute-force kNN, and PCA compression.
§What this is (and is not)
This is the exact rerank / compute layer that sits next to a vector store, not a vector database. It is deliberately:
- bring-your-own-vectors: it accepts
Array2<T>/ArrayView2<T>(f32/f64viaNabledReal). Any encoder’s dense float vectors plug in unchanged because the crate depends only on shape and dtype, never the model. - numerics-only: no model inference, no tokenizers, no ONNX/candle.
- Arrow-free in the core: Arrow/Lance ingress lives at the
nabled::arrowfacade and inpynabled, never here.
Non-goals: it is not an ANN/vector-search engine (no HNSW/IVF index), not storage, and not a FAISS/HNSW replacement. Use an ANN index for recall, then rerank its candidates here.
§Two rules the math cannot enforce
- Query and corpus must come from the same model and share the same
dim. - You pick the
Metricto match how the model was trained:Metric::Cosine(the default),Metric::Dotfor maximum-inner-product (MIPS) models, orMetric::L2where applicable. Dot on un-normalized vectors favors larger-norm rows by design.
§Feature flags
blas: forwards BLAS acceleration tonabled-linalg/nabled-ml.lapack-provider: enables provider-dispatched PCA paths.openblas-system/openblas-static/netlib-system/netlib-static/magma-system: provider backends forwarded to the lower crates.
§Quick example
use nabled_embeddings::{Metric, rerank};
use ndarray::arr2;
let corpus = arr2(&[[1.0_f64, 0.0], [0.0, 1.0], [0.9, 0.1]]);
let query = arr2(&[[1.0_f64, 0.0]]);
let top = rerank(&query.row(0), &corpus.view(), 2, Metric::Cosine)?;
assert_eq!(top[0].index, 0);Re-exports§
pub use cache::CorpusWorkspace;pub use compress::PcaModel;pub use compress::compress;pub use compress::compress_into;pub use compress::compress_view;pub use compress::fit_pca;pub use error::EmbeddingError;pub use knn::brute_force_knn;pub use metrics::mean_reciprocal_rank;pub use metrics::ndcg_at_k;pub use metrics::recall_at_k;pub use metrics::reciprocal_rank;pub use mmr::mmr;pub use normalize::normalize_rows;pub use normalize::normalize_rows_into;pub use normalize::normalize_rows_view;pub use quantize::QuantizedMatrix;pub use quantize::dequantize;pub use quantize::quantize_rows;pub use rerank::batch_rerank_with_ids;pub use rerank::rerank;pub use rerank::rerank_with_ids;pub use similarity::Metric;pub use similarity::query_corpus_scores;pub use similarity::query_corpus_scores_into;pub use similarity::query_corpus_scores_view;pub use topk::Neighbor;pub use topk::NeighborWithId;pub use topk::attach_ids;pub use topk::top_k;
Modules§
- cache
- Reusable corpus workspace for repeated queries against a static corpus.
- compress
- PCA-based dimensionality reduction for embedding matrices.
- error
- Error taxonomy for embedding retrieval compute.
- knn
- Exact brute-force k-nearest-neighbors over a full corpus.
- metrics
- Offline retrieval-quality metrics over ranked id lists.
- mmr
- Maximal Marginal Relevance (MMR) re-ranking for result diversification.
- normalize
- Row-wise L2 normalization for embedding matrices.
- quantize
- int8 row quantization for embedding matrices (encode/decode + dequantized scoring).
- rerank
- Exact single-query rerank: score candidates, then select the best
k. - similarity
- Query-versus-corpus scoring across the three common retrieval metrics.
- topk
- Direction-aware partial top-k selection over a score vector.