Skip to main content

ContextStorage

Trait ContextStorage 

Source
pub trait ContextStorage: Send + Sync {
    // Required methods
    fn save<'life0, 'life1, 'async_trait>(
        &'life0 self,
        entry: &'life1 ContextEntry,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_top_k<'life0, 'async_trait>(
        &'life0 self,
        k: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ContextEntry>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_all<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ContextEntry>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear_scope<'life0, 'life1, 'async_trait>(
        &'life0 self,
        scope: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn count<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn save_embedding<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
        embedding: &'life2 [f32],
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn get_unembedded<'life0, 'async_trait>(
        &'life0 self,
        limit: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ContextEntry>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for persisting and retrieving context entries.

Implementations must be thread-safe (Send + Sync) to support concurrent access from multiple worker threads.

Required Methods§

Source

fn save<'life0, 'life1, 'async_trait>( &'life0 self, entry: &'life1 ContextEntry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Persist a single entry.

§Security

Implementations persist entry.content verbatim — secret scrubbing happens only in ContextForge::save. Callers writing through this trait directly are responsible for scrubbing first (see scrub_secrets).

§Errors

Returns an error if the underlying storage write fails.

Source

fn get_top_k<'life0, 'async_trait>( &'life0 self, k: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<ContextEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the top-k entries (most recent or highest priority).

§Errors

Returns an error if the underlying storage read fails.

Source

fn get_all<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ContextEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return every stored entry.

§Errors

Returns an error if the underlying storage read fails.

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete an entry by id. Returns true if an entry was removed.

§Errors

Returns an error if the underlying storage delete fails.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove all entries. Returns the number of entries removed.

§Errors

Returns an error if the underlying storage delete fails.

Source

fn clear_scope<'life0, 'life1, 'async_trait>( &'life0 self, scope: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove all entries within a given scope. Returns the number of entries removed.

§Errors

Returns an error if the underlying storage delete fails.

Source

fn count<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the total number of stored entries.

§Errors

Returns an error if the underlying storage read fails.

Provided Methods§

Source

fn save_embedding<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, embedding: &'life2 [f32], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Persist a dense embedding vector for an already-saved entry.

The default no-op is used by storage backends that do not support vector search. TursoStorage overrides this to write into the embedding column via vector32(?).

§Errors

Returns an error if the underlying write fails.

Source

fn get_unembedded<'life0, 'async_trait>( &'life0 self, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<ContextEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return entries that do not yet have an embedding stored.

Used by the backfill path. The default falls back to get_all(); TursoStorage overrides with an efficient WHERE embedding IS NULL query.

§Errors

Returns an error if the underlying storage read fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§