translation/translated/documents/course/03-agent-memory/10-storage-configuration.md

30 lines
1.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 存储配置
对话历史记录依赖存储适配器来持久化消息。默认情况下Mastra 使用 LibSQL 存储,将消息保存到本地数据库。您可以对此进行配置或使用其他存储选项:
```typescript
import { Memory } from "@mastra/memory";
import { LibSQLStore } from "@mastra/libsql";
const memory = new Memory({
// 配置存储
storage: new LibSQLStore({
id: "learning-memory-storage",
url: "file:../../memory.db", // 本地数据库。相对于输出文件夹
}),
options: {
lastMessages: 20,
},
});
```
Mastra 支持多种存储选项,包括:
- LibSQL默认本地 SQLite
- PostgreSQL
- UpstashRedis
存储适配器负责持久化记忆数据,包括对话历史记录和工作记忆。这使得您的智能体即使在应用程序重启后也能记住对话内容。
对于开发和测试,默认的 LibSQL 存储通常就足够了。对于生产应用程序,您可能希望使用更 robust 的存储选项,如 PostgreSQL 或基于云的解决方案如 Upstash。