translation/translated/documents/course/03-agent-memory/18-advanced-configuration-s...

30 lines
1.1 KiB
Markdown
Raw Normal View History

# 语义回忆的高级配置
我们可以通过为 `semanticRecall` 选项设置选项来更详细地配置语义回忆:
```typescript
const memory = new Memory({
storage: new LibSQLStore({
id: "learning-memory-storage",
url: "file:../../memory.db", // 相对于 `.mastra/output` 目录的相对路径
}),
vector: new LibSQLVector({
connectionUrl: "file:../../vector.db", // 相对于 `.mastra/output` 目录的相对路径
}),
embedder: openai.embedding("text-embedding-3-small"),
options: {
semanticRecall: {
topK: 3,
messageRange: {
before: 2,
after: 1,
},
},
},
});
```
`topK` 参数控制检索多少条语义相似的消息。较高的值将检索更多消息,这可能对复杂主题有帮助,但也可能包含不太相关的信息。默认值为 `4`
`messageRange` 参数控制为每次匹配包含多少上下文。这很重要,因为仅匹配的消息可能无法提供足够的上下文来理解对话。包含匹配消息之前和之后的消息有助于智能体理解匹配消息的上下文。