pub struct EmbeddingIndex<P> { /* private fields */ }Implementations§
Source§impl<P: Projection> EmbeddingIndex<P>
impl<P: Projection> EmbeddingIndex<P>
pub fn builder(projection: P) -> EmbeddingIndexBuilder<P>
pub fn insert(&mut self, id: impl Into<String>, embedding: &Embedding)
Sourcepub fn insert_with_radius(
&mut self,
id: impl Into<String>,
embedding: &Embedding,
r: f64,
)
pub fn insert_with_radius( &mut self, id: impl Into<String>, embedding: &Embedding, r: f64, )
Insert with an explicit radial value, overriding the projection’s RadialStrategy. The angular coordinates (theta, phi) are still determined by the projection. Use this for metadata-driven radius: recency scores, importance weights, etc.
Sourcepub fn search_nearest(
&self,
query: &Embedding,
k: usize,
) -> Vec<NearestResult<EmbeddingItem>>
pub fn search_nearest( &self, query: &Embedding, k: usize, ) -> Vec<NearestResult<EmbeddingItem>>
Find the k embeddings whose projected directions are closest to the query.
Sourcepub fn search_similar(
&self,
query: &Embedding,
min_cosine_similarity: f64,
) -> SpatialQueryResult<EmbeddingItem>
pub fn search_similar( &self, query: &Embedding, min_cosine_similarity: f64, ) -> SpatialQueryResult<EmbeddingItem>
Find all embeddings whose projected cosine similarity to the query
is at least min_cosine_similarity.
Internally maps cos(sim) → angular distance and uses within_distance.
pub fn search_region( &self, region: &Region, ) -> SpatialQueryResult<EmbeddingItem>
pub fn remove(&mut self, id: &str) -> Option<EmbeddingItem>
pub fn get(&self, id: &str) -> Option<&EmbeddingItem>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn projection(&self) -> &P
pub fn all_items(&self) -> Vec<&EmbeddingItem>
Sourcepub fn concept_path(
&self,
source_id: &str,
target_id: &str,
k: usize,
) -> Option<ConceptPath>
pub fn concept_path( &self, source_id: &str, target_id: &str, k: usize, ) -> Option<ConceptPath>
Find the shortest semantic path between two items through a k-NN graph.
Builds a k-nearest-neighbor graph over all indexed embeddings, then runs Dijkstra’s algorithm weighted by angular distance. The resulting path traces the chain of closest intermediate concepts connecting the source to the target.
Complexity: O(n^2 * k) — the k-NN graph is rebuilt from scratch on every call. Not suitable for large indices (>5000 items) without caching.