Skip to main content

SemanticIndex

Struct SemanticIndex 

Source
pub struct SemanticIndex { /* private fields */ }
Expand description

Three-index semantic search over the stage store.

Implementations§

Source§

impl SemanticIndex

Source

pub fn from_stages( stages: Vec<Stage>, provider: Box<dyn EmbeddingProvider>, config: IndexConfig, ) -> Result<Self, EmbeddingError>

Build the index from an owned list of stages (useful in async contexts where holding a &dyn StageStore across .await is not possible).

Source

pub fn build( store: &dyn StageStore, provider: Box<dyn EmbeddingProvider>, config: IndexConfig, ) -> Result<Self, EmbeddingError>

Build the index from all non-tombstoned stages in a store.

Source

pub fn from_stages_batched( stages: Vec<Stage>, cached_provider: CachedEmbeddingProvider, config: IndexConfig, chunk_size: usize, ) -> Result<Self, EmbeddingError>

Build the index in a single pass: collect every signature/description/ example text upfront, dispatch all cache misses through inner.embed_batch in chunks of chunk_size, then assemble the three sub-indexes. Used by noether-cloud’s registry on cold start so that 486 stages × 3 texts = 1458 individual API calls collapse into ~46 batch calls of 32 texts each — well within typical rate limits.

Source

pub fn from_stages_batched_paced( stages: Vec<Stage>, cached_provider: CachedEmbeddingProvider, config: IndexConfig, chunk_size: usize, inter_batch_delay: Duration, ) -> Result<Self, EmbeddingError>

Like from_stages_batched, but waits inter_batch_delay between successive batch calls and commits cache entries to disk after each batch. Use this with rate-limited remote providers (e.g. Mistral free tier ≈ 1 req/s → pass ~1100 ms).

Source

pub fn build_cached( store: &dyn StageStore, cached_provider: CachedEmbeddingProvider, config: IndexConfig, ) -> Result<Self, EmbeddingError>

Build using a CachedEmbeddingProvider for persistent embedding cache.

Source

pub fn add_stage(&mut self, stage: &Stage) -> Result<(), EmbeddingError>

Add a single stage to all three indexes.

Source

pub fn remove_stage(&mut self, stage_id: &StageId)

Remove a stage from all three indexes.

Source

pub fn len(&self) -> usize

Number of stages indexed.

Source

pub fn is_empty(&self) -> bool

Source

pub fn search( &self, query: &str, top_k: usize, ) -> Result<Vec<SearchResult>, EmbeddingError>

Search across all three indexes and return ranked results.

Source

pub fn search_filtered( &self, query: &str, top_k: usize, tag: Option<&str>, ) -> Result<Vec<SearchResult>, EmbeddingError>

Like search, but restricts candidates to stages carrying tag (exact match). Passing tag: None is equivalent to search.

Source

pub fn search_by_tag(&self, tag: &str) -> Vec<StageId>

Return all stage IDs that carry tag (exact match).

Source

pub fn all_tags(&self) -> Vec<String>

Return the set of all known tags across indexed stages.

Source

pub fn check_duplicate_before_insert( &self, description: &str, threshold: f32, ) -> Result<Option<(StageId, f32)>, EmbeddingError>

Check whether a candidate description is a near-duplicate of an existing stage.

Returns Some((stage_id, similarity)) if any existing stage’s semantic embedding exceeds threshold (default 0.92). Returns None if the description is novel enough.

Source

pub fn find_near_duplicates( &self, threshold: f32, ) -> Vec<(StageId, StageId, f32)>

Scan all active stages for near-duplicate pairs.

Returns pairs (id_a, id_b, similarity) where semantic similarity >= threshold. Each pair appears only once (id_a < id_b lexicographically).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more