六、Session 存储
六、Session 存储
关键点:SQLite 存储会话 + FTS5 全文搜索召回 + context 压缩生成子 session
SQLite 表结构
1
2
3
4
5
~/.hermes/state.db (SQLite, WAL mode)
├── sessions — Session metadata, token counts, billing
├── messages — Full message history per session
├── messages_fts — FTS5 virtual table for full-text search
└── schema_version — Single-row table tracking migration state
- sessions 表:存 system_prompt(稳定) 等元信息,parent_session_id 关联父子 session 关系
- messages_fts 表:是个视图,通过触发器与 messages 表数据保持同步
何时创建子 session
多轮会话,触发 context compression 会重建 system prompt,并新建子 session,用 parent_session_id 字段关联。
亮点
- FTS5 关键字全文搜索:为短期 memory 召回提供支持
- session 分裂和关联:context compression 时触发,保持 system prompt 前缀稳定
- WAL 预写:依赖 SQLite 的 WAL模式
参考
This post is licensed under CC BY 4.0 by the author.