持久化 ChatMemory - SQLite 后端
把中立消息(见 core/llm/message)按 conversation-id 持久化到 SQLite, 进程重启后仍可恢复历史(配合 create-agent 的 :conversation-id 实现按用户恢复)。
消息以 EDN 字符串存储(中立消息是纯 Clojure 数据,EDN 可无损往返)。
表结构: chat_messages(id INTEGER PK AUTOINCREMENT, conversation_id TEXT, content TEXT)
用法: (require '[im.ttalk.agent.memory.sqlite :as sqlite]) (def store (sqlite/sqlite-store "agent.db")) (create-agent {:provider p :memory store :conversation-id "user-123"})
持久化 ChatMemory - SQLite 后端
把中立消息(见 core/llm/message)按 conversation-id 持久化到 SQLite,
进程重启后仍可恢复历史(配合 create-agent 的 :conversation-id 实现按用户恢复)。
消息以 EDN 字符串存储(中立消息是纯 Clojure 数据,EDN 可无损往返)。
表结构:
chat_messages(id INTEGER PK AUTOINCREMENT, conversation_id TEXT, content TEXT)
用法:
(require '[im.ttalk.agent.memory.sqlite :as sqlite])
(def store (sqlite/sqlite-store "agent.db"))
(create-agent {:provider p :memory store :conversation-id "user-123"})(close-store! store)关闭 store 持有的数据库连接,释放资源。
关闭 store 持有的数据库连接,释放资源。
(sqlite-store db-path)创建 SQLite 后端的 ChatMemory。
参数:
返回: 实现 ChatMemory + java.io.Closeable 的 store(首次调用自动建表)。 持有单个常开连接,用完请 (close-store! store) 或用 (with-open [s ...] ...) 释放。
创建 SQLite 后端的 ChatMemory。 参数: - db-path: SQLite 文件路径(如 "agent.db";":memory:" 为进程内库) 返回: 实现 ChatMemory + java.io.Closeable 的 store(首次调用自动建表)。 持有单个常开连接,用完请 (close-store! store) 或用 (with-open [s ...] ...) 释放。
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |