公开 API

MemoryStore 公开 API

聚合根 MemoryStore 上仅 6 个核心方法;一切可失败操作返回 Result,全库禁 panic。

方法语义返回
open(path, config?)打开或创建记忆库Result[MemoryStore, MoomemError]
add(user_id, text)提取→去重→冲突→双索引→落盘Result[AddSummary, MoomemError]
recall(user_id, query, top_k?)混合检索(仅 Active / Unstructured)Result[Array[MemoryEntry], MoomemError]
forget(user_id, target)软删除 ById(id) / AllResult[Int, MoomemError]
stats()计数 / 字节 / 截断恢复 / 提取模式Result[StoreStats, MoomemError]
close()flush 后关闭(幂等)Result[Unit, MoomemError]

辅助:export_jsonl / import_jsonl / list_entries(user_id)。

user_id:非空、≤64 字符、字符集 [A-Za-z0-9_\-.],入口强制校验(含路径穿越拒绝)。

注入点

trait缺省(离线)生产替换
EmbedderHashingEmbedder(256 维词袋哈希)宿主 / vcdb 嵌入
ExtractorRawExtractor(原文 unstructured 入库)src/llm_extractor 的 LlmExtractor
ConflictJudgeSimilarityJudge(余弦 + Jaccard,阈值 0.82)LlmConflictJudge
PersistenceBackendnative FsBackend;wasm/js MemoryBackendIndexedDB 胶水等
ClockLogicalClock系统时钟 / 测试用 FixedClock
let cfg : Config = Config::{
  ..Config::default(),
  judge : Some(MyLlmJudge::new() as &ConflictJudge),
  clock : Some(FixedClock::new(42L) as &Clock),
}
let store = MemoryStore::open("./memory", config=cfg).unwrap()

更多:

CLI

LLM 注入