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.
The k-NN graph is memoized per k: the first call at a given k
builds it in O(n · log n · k) (index-assisted) and every
subsequent call reuses the snapshot until the index mutates.
Dijkstra itself is O((n + E) · log n) via a binary heap.
Sourcepub fn concept_path_bridged(
&self,
source_id: &str,
target_id: &str,
k: usize,
categories: &HashMap<&str, usize>,
bridge_strengths: &HashMap<(usize, usize), (f64, BridgeClassification)>,
) -> Option<ConceptPath>
pub fn concept_path_bridged( &self, source_id: &str, target_id: &str, k: usize, categories: &HashMap<&str, usize>, bridge_strengths: &HashMap<(usize, usize), (f64, BridgeClassification)>, ) -> Option<ConceptPath>
Find a semantic path that prefers hops with strong conceptual bridges.
Like concept_path, but when a hop crosses a
category boundary, the edge weight is penalized based on the bridge’s
classification:
-
BridgeClassification::Genuine:angular_dist / (strength + 0.1) -
BridgeClassification::Weak:angular_dist / (strength + 0.01) -
BridgeClassification::OverlapArtifact:angular_dist * 2.0(shared-territory bridges are actively discouraged — they aren’t real connectors). -
categories: maps item ID → category index. -
bridge_strengths: maps(cat_a, cat_b) → (max_bridge_strength, classification). Missing entries are treated as a weak no-bridge (strength 0, Weak).
Same-category hops use raw angular distance.
Auto Trait Implementations§
impl<P> !Freeze for EmbeddingIndex<P>
impl<P> RefUnwindSafe for EmbeddingIndex<P>where
P: RefUnwindSafe,
impl<P> Send for EmbeddingIndex<P>where
P: Send,
impl<P> Sync for EmbeddingIndex<P>where
P: Sync,
impl<P> Unpin for EmbeddingIndex<P>where
P: Unpin,
impl<P> UnsafeUnpin for EmbeddingIndex<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for EmbeddingIndex<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more