Skip to main content

Module matryoshka

Module matryoshka 

Source
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.

The flagship feature is MatryoshkaIndex::funnel_search, which:

  1. Filters candidates at a low dimension (fast, coarse)
  2. 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§

FunnelConfig
Configuration for the multi-phase funnel search.
MatryoshkaConfig
Configuration for a Matryoshka embedding index.
MatryoshkaIndex
Matryoshka embedding index supporting adaptive-dimension search.