MemoryService

Trait MemoryService 

Source
pub trait MemoryService: Send + Sync {
Show 18 methods // Required methods fn store_document<'life0, 'life1, 'async_trait>( &'life0 self, doc: &'life1 Document, ) -> Pin<Box<dyn Future<Output = MemoryResult<Uuid>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn store_chunks<'life0, 'life1, 'async_trait>( &'life0 self, chunks: &'life1 [Chunk], ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<Uuid>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn delete_document<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn update_document<'life0, 'life1, 'async_trait>( &'life0 self, id: Uuid, doc: &'life1 Document, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn search<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, top_k: usize, ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<SearchResult>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn hybrid_search<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, top_k: usize, config: HybridConfig, ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<SearchResult>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_by_id<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = MemoryResult<Option<Document>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_context<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, max_tokens: usize, ) -> Pin<Box<dyn Future<Output = MemoryResult<ContextWindow>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn embed<'life0, 'life1, 'async_trait>( &'life0 self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<f32>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn embed_batch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, texts: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<Vec<f32>>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn create_index<'life0, 'async_trait>( &'life0 self, config: IndexConfig, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn rebuild_index<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_stats<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<IndexStats>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn config(&self) -> &MemoryConfig; fn set_config(&mut self, config: MemoryConfig); fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn flush<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait;
}
Expand description

Core abstraction for memory operations.

This trait is implemented by reasonkit-mem and consumed by reasonkit-core. It provides a unified interface for document storage, retrieval, and embedding.

§Example

use reasonkit::traits::{MemoryService, Document};

async fn example(memory: &impl MemoryService) -> MemoryResult<()> {
    let doc = Document {
        id: None,
        content: "Hello, world!".to_string(),
        metadata: Default::default(),
        source: Some("example".to_string()),
        created_at: None,
    };

    let id = memory.store_document(&doc).await?;
    let results = memory.search("hello", 5).await?;

    Ok(())
}

Required Methods§

Source

fn store_document<'life0, 'life1, 'async_trait>( &'life0 self, doc: &'life1 Document, ) -> Pin<Box<dyn Future<Output = MemoryResult<Uuid>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store a document, returning its assigned ID.

Source

fn store_chunks<'life0, 'life1, 'async_trait>( &'life0 self, chunks: &'life1 [Chunk], ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<Uuid>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store multiple chunks, returning their assigned IDs.

Source

fn delete_document<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete a document and all its chunks.

Source

fn update_document<'life0, 'life1, 'async_trait>( &'life0 self, id: Uuid, doc: &'life1 Document, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update an existing document.

Source

fn search<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, top_k: usize, ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<SearchResult>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Search for relevant chunks using vector similarity.

Search using hybrid retrieval (vector + BM25 with RRF fusion).

Source

fn get_by_id<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = MemoryResult<Option<Document>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a document by its ID.

Source

fn get_context<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, max_tokens: usize, ) -> Pin<Box<dyn Future<Output = MemoryResult<ContextWindow>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a context window optimized for the query and token budget.

Source

fn embed<'life0, 'life1, 'async_trait>( &'life0 self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<f32>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Embed a single text string.

Source

fn embed_batch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, texts: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = MemoryResult<Vec<Vec<f32>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Embed multiple texts in a batch.

Source

fn create_index<'life0, 'async_trait>( &'life0 self, config: IndexConfig, ) -> Pin<Box<dyn Future<Output = MemoryResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new index with the given configuration.

Source

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

Rebuild the index from stored documents.

Source

fn get_stats<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<IndexStats>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get statistics about the current index.

Source

fn config(&self) -> &MemoryConfig

Get the current configuration.

Source

fn set_config(&mut self, config: MemoryConfig)

Update the configuration.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = MemoryResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if the service is healthy and ready.

Source

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

Flush any pending writes to storage.

Source

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

Gracefully shutdown the service.

Implementors§