1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Memory(记忆)实现模块
//!
//! # 概述
//!
//! 本模块包含 Memory 的具体实现,用于存储和检索长期记忆。
//!
//! # 支持的 Memory 类型
//!
//! | 类型 | 说明 | 使用场景 |
//! |------|------|----------|
//! | [`InMemoryMemory`] | 进程内记忆存储 | 测试、临时会话 |
//! | [`FileMemory`] | 文件记忆存储 | 持久化、简单场景 |
//!
//! # 使用示例
//!
//! ## InMemoryMemory
//!
//! ```rust,no_run
//! use rucora::memory::InMemoryMemory;
//! use rucora_core::memory::{Memory, MemoryItem};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let memory = InMemoryMemory::new();
//!
//! // 添加记忆
//! memory.add(MemoryItem {
//! id: "user_name".to_string(),
//! content: "Alice".to_string(),
//! metadata: None,
//! }).await?;
//!
//! // 检索记忆
//! let results = memory.query(rucora_core::memory::MemoryQuery {
//! text: "user".to_string(),
//! limit: 10,
//! }).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## FileMemory
//!
//! ```rust,no_run
//! use rucora::memory::FileMemory;
//! use rucora_core::memory::{Memory, MemoryItem};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let memory = FileMemory::new("memory.json");
//!
//! // 添加记忆(会自动保存到文件)
//! memory.add(MemoryItem {
//! id: "preference".to_string(),
//! content: "喜欢 Rust".to_string(),
//! metadata: None,
//! }).await?;
//! # Ok(())
//! # }
//! ```
//!
//! # 记忆分类
//!
//! 记忆可以通过 ID 前缀进行分类:
//!
//! - `core:`: 永久记忆(用户偏好、基本信息)
//! - `daily:`: 会话记忆(当天对话主题)
//! - `conversation:`: 对话上下文(最近的对话内容)
//!
//! ```rust
//! use rucora_core::memory::MemoryItem;
//!
//! // 永久记忆
//! let core = MemoryItem {
//! id: "core:user_name".to_string(),
//! content: "Alice".to_string(),
//! metadata: None,
//! };
//!
//! // 会话记忆
//! let daily = MemoryItem {
//! id: "daily:last_topic".to_string(),
//! content: "Rust 编程".to_string(),
//! metadata: None,
//! };
//! ```
pub use FileMemory;
pub use InMemoryMemory;