Skip to main content

MemoryStore

Trait MemoryStore 

Source
pub trait MemoryStore: Send + Sync {
    // Required methods
    fn add<'life0, 'life1, 'async_trait>(
        &'life0 self,
        conversation_id: &'life1 str,
        message: Message,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_conversation<'life0, 'life1, 'async_trait>(
        &'life0 self,
        conversation_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_conversation<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        conversation_id: &'life1 str,
        messages: &'life2 [Message],
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided method
    fn query<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _conversation_id: &'life1 str,
        _query: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

抽象的记忆存储接口。

为了保持 MVP 简洁,所有方法的语义都尽量宽松,仅用于占位和后续扩展。

Required Methods§

Source

fn add<'life0, 'life1, 'async_trait>( &'life0 self, conversation_id: &'life1 str, message: Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

追加一条消息到某个会话中。

Source

fn get_conversation<'life0, 'life1, 'async_trait>( &'life0 self, conversation_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

获取某个会话的完整消息列表。

Source

fn save_conversation<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, conversation_id: &'life1 str, messages: &'life2 [Message], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

覆盖保存整个会话的消息列表。

Provided Methods§

Source

fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _conversation_id: &'life1 str, _query: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

按简单字符串 query 查询相关消息。

约定:实现可以根据 conversation_id 做范围限定,也可以忽略它并全局搜索。

Implementors§