Expand description
Matryoshka Representation Learning Support
Implements adaptive-dimension embedding search inspired by Matryoshka Representation Learning (MRL). Full-dimensional embeddings are stored once, but searches can be performed at any prefix dimension—smaller prefixes run faster while larger ones are more accurate.
§Two-Phase Funnel Search
The flagship feature is MatryoshkaIndex::funnel_search, which:
- Filters candidates at a low dimension (fast, coarse)
- Reranks the survivors at full dimension (slower, precise)
This typically yields the same recall as full-dimension search at a fraction of the cost.
§Example
use ruvector_core::advanced_features::matryoshka::*;
use ruvector_core::types::DistanceMetric;
let config = MatryoshkaConfig {
full_dim: 8,
supported_dims: vec![2, 4, 8],
metric: DistanceMetric::Cosine,
};
let mut index = MatryoshkaIndex::new(config).unwrap();
index.insert("v1".into(), vec![1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], None).unwrap();
let results = index.search(&[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 4, 10).unwrap();
assert_eq!(results[0].id, "v1");Structs§
- Funnel
Config - Configuration for the multi-phase funnel search.
- Matryoshka
Config - Configuration for a Matryoshka embedding index.
- Matryoshka
Index - Matryoshka embedding index supporting adaptive-dimension search.