Skip to main content

SemanticService

Struct SemanticService 

Source
pub struct SemanticService {
    pub provider: Box<dyn EmbeddingProvider>,
    /* private fields */
}
Expand description

Main semantic embedding service for the memory system

Coordinates embedding generation, storage, and semantic search across episodes and patterns. Integrates with the existing storage backends.

Fields§

§provider: Box<dyn EmbeddingProvider>

Embedding provider for text-to-vector conversion

Implementations§

Source§

impl SemanticService

Source

pub fn new( provider: Box<dyn EmbeddingProvider>, storage: Box<dyn EmbeddingStorageBackend>, config: EmbeddingConfig, ) -> Self

Create a new semantic service with the specified provider and storage

Source

pub fn config(&self) -> &EmbeddingConfig

Get the embedding configuration

Source

pub async fn with_local_provider( storage: Box<dyn EmbeddingStorageBackend>, config: EmbeddingConfig, ) -> Result<Self>

Get the embedding provider type

Source

pub async fn default(storage: Box<dyn EmbeddingStorageBackend>) -> Result<Self>

Create a semantic service with default local provider

Source

pub async fn with_fallback( storage: Box<dyn EmbeddingStorageBackend>, config: EmbeddingConfig, ) -> Result<Self>

Create a semantic service with automatic provider fallback

Tries providers in order: Local → OpenAI → Mock (with warnings) This ensures maximum reliability by falling back to simpler options if preferred ones fail.

Source

pub async fn embed_episode(&self, episode: &Episode) -> Result<Vec<f32>>

Generate and store embedding for an episode

Creates a semantic representation of the episode by combining:

  • Task description
  • Context information (domain, language, framework)
  • Key execution steps
  • Outcome summary
Source

pub async fn embed_pattern(&self, pattern: &Pattern) -> Result<Vec<f32>>

Generate and store embedding for a pattern

Creates a semantic representation based on:

  • Pattern description
  • Context where the pattern was extracted
  • Pattern metadata and effectiveness metrics
Source

pub async fn find_similar_episodes( &self, query: &str, context: &TaskContext, limit: usize, ) -> Result<Vec<SimilaritySearchResult<Episode>>>

Find semantically similar episodes for a query

Uses vector similarity to find episodes that are semantically related to the query, going beyond keyword matching to understand meaning.

Source

pub async fn find_similar_patterns( &self, context: &TaskContext, limit: usize, ) -> Result<Vec<SimilaritySearchResult<Pattern>>>

Find semantically similar patterns for a context

Identifies patterns that are semantically relevant to the given context, enabling better pattern reuse and recommendation.

Source

pub async fn text_similarity(&self, text1: &str, text2: &str) -> Result<f32>

Calculate similarity between two texts

Source

pub async fn find_episodes_by_embedding( &self, embedding: Vec<f32>, limit: usize, threshold: f32, ) -> Result<Vec<SimilaritySearchResult<Episode>>>

Find episodes similar to a pre-computed embedding vector

This method allows searching with a pre-computed embedding, useful when the embedding has been generated externally or cached.

§Arguments
  • embedding - Pre-computed embedding vector to search with
  • limit - Maximum number of results to return
  • threshold - Minimum similarity score (0.0-1.0)
§Returns

Vector of similar episodes with their similarity scores

Source

pub async fn find_patterns_by_embedding( &self, embedding: Vec<f32>, limit: usize, threshold: f32, ) -> Result<Vec<SimilaritySearchResult<Pattern>>>

Find patterns similar to a pre-computed embedding vector

This method allows searching with a pre-computed embedding, useful when the embedding has been generated externally or cached.

§Arguments
  • embedding - Pre-computed embedding vector to search with
  • limit - Maximum number of results to return
  • threshold - Minimum similarity score (0.0-1.0)
§Returns

Vector of similar patterns with their similarity scores

Source

pub async fn get_embeddings_batch( &self, episode_ids: &[Uuid], ) -> Result<Vec<Option<Vec<f32>>>>

Get embeddings for multiple episodes in batch

This method retrieves embeddings for multiple episode IDs efficiently. For backends that don’t support batch operations, it falls back to individual lookups.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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
Source§

impl<T> SendAlias for T

Source§

impl<T> SendAlias for T

Source§

impl<T> SyncAlias for T

Source§

impl<T> SyncAlias for T