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§
Sourcefn 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_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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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,
Search using hybrid retrieval (vector + BM25 with RRF fusion).
Sourcefn 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_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.
Sourcefn 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 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.
Sourcefn 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<'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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn rebuild_index<'life0, 'async_trait>(
&'life0 self,
) -> 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,
Rebuild the index from stored documents.
Sourcefn 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 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.
Sourcefn config(&self) -> &MemoryConfig
fn config(&self) -> &MemoryConfig
Get the current configuration.
Sourcefn set_config(&mut self, config: MemoryConfig)
fn set_config(&mut self, config: MemoryConfig)
Update the configuration.
Sourcefn 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 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.