关于 Convex Agents RAG
Convex Agents RAG 是一项技能,可让 Agent 检索自定义内容并据此生成回答,适合构建有内容依据的搜索与问答流程。它提供混合搜索,并支持按命名空间隔离用户或团队数据。
主要功能
- 01将文档导入命名空间
- 02语义搜索内容
- 03结合文本与向量搜索
- 04按文档名称筛选
- 05隔离用户或团队数据
适用场景
- 01依据产品文档生成回答
- 02搜索政策或支持内容
- 03构建 FAQ 和文档搜索
- 04区分用户或团队知识
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ sstobo/ convex-skills --skill convex-agents-rag安装后在 Claude Code 中输入/convex-agents-rag确认已加载。
详细介绍
用途
让 Agent 能够搜索自定义内容和知识库,以提供准确、基于上下文的回答。RAG 将大模型能力与语义搜索相结合。
何时使用此技能
- Agent 需要引用知识库或文档集合
- 将回答基于特定数据(政策、产品文档等)
- 对自定义内容进行语义搜索
- 构建搜索 + 生成系统(FAQ、文档、支持)
- 通过将回答限制在已知信息范围内来减少幻觉
- 管理用户特定或团队特定的知识命名空间
设置
在 convex.config.ts 中安装并配置 RAG:
import { defineApp } from "convex/server";
import agent from "@convex-dev/agent/convex.config";
import rag from "@convex-dev/rag/convex.config";
const app = defineApp();
app.use(agent);
app.use(rag);
export default app;
添加内容
将文档摄取到命名空间中:
import { rag } from "@convex-dev/rag";
export const addContent = action({
args: { userId: v.string(), key: v.string(), text: v.string() },
handler: async (ctx, { userId, key, text }) => {
const namespace = `user:${userId}`;
await rag.addContent(ctx, components.rag, {
namespace,
key,
text,
filters: { filterNames: [filename] },
});
},
});
搜索与生成
将 RAG 与 Agent 配合使用:
export const answerWithContext = action({
args: { threadId: v.string(), userId: v.string(), question: v.string() },
handler: async (ctx, { threadId, userId, question }) => {
const { thread } = await myAgent.continueThread(ctx, { threadId });
const context = await rag.search(ctx, components.rag, {
namespace: `user:${userId}`,
query: question,
limit: 10,
});
const augmentedPrompt = `# Context:\n\n${context.text}\n\n# Question:\n\n${question}`;
const result = await thread.generateText({ prompt: augmentedPrompt });
return result.text;
},
});
关键原则
- 命名空间隔离数据:使用
user:userId或team:teamId以确保多租户安全 - 混合搜索:结合文本搜索和向量搜索以获得更好的结果
- 过滤:使用
filterNames定位特定文档
后续步骤
- 查看 fundamentals 了解基础 Agent 设置
- 查看 context 了解高级上下文自定义
评论
支持 Markdown