创建RAG实验(快速路径)
使用AutoAI 创建检索增强生成 (RAG) 实验。 上传文档集并将其转换为向量,用于改进大型语言模型的输出。 比较优化的管道,为您的应用选择最佳的 RAG 模式。
准备数据源
在创建RAG实验之前,请准备好您的文档集合和评估数据资产。 文档集合为快速输入的答案提供了上下文。 评估数据是一个包含样本问题和答案的文件,用于衡量 RAG 模式的性能。
文档集合
- 文档集合支持的格式:PDF、HTML、 DOCX、MD、PPTX、JSON、YAML、XML 或纯文本
求值数据
- 支持的评估数据文件格式:JSON
如果您的环境中安装了带有 autoai_rag 功能的 mistral 或 llama 大型语言模型,则可选择上传评估数据。 您可以上传自己的 JSON 文件,或选择 " 使用 LLM 生成 ",让 LLM 最多生成 10 个示例问题和正确答案对。 实验完成后,您可以在 RAG 模式评估结果下查看生成的评估数据。
- 使用 LLM 生成评估数据需要额外的标记。
- 生成基准数据的 LLM 仅支持英语。
JSON 评估文件模板
评估数据文件提供了一系列样题和正确答案,用于评估 RAG 模式的性能。 JSON 文件使用此格式:
您可以引用数据源子目录中的文件。 所有文件 ID 必须使用相对于存储桶根目录的绝对文件路径。 例如, data/doc1.text 或 reports/2026/summary.txt 用于子文件夹。
如果你不使用子文件夹,且所有文件都位于同一路径下,你仍然只需使用文件名即可引用它们。 您无需为项目数据资产指定路径。
[
{
"question": "<text>",
"correct_answer": "<text>",
"correct_answer_document_ids": [
"<filepath>",
"<filepath>"
]
},
{
"question": "<text>",
"correct_answer": "<text>",
"correct_answer_document_ids": [
"<filepath>",
"<filepath>"
]
},
{
"question": "<text>",
"correct_answer": "<text>",
"correct_answer_document_ids": [
"<filepath>",
"<filepath>"
]
}
]
要为一个问题添加多个正确答案,请为每个正确答案提供答案文本和文档 ID。 使用此格式可获得多个正确答案:
[
{
"question": "Question 1",
"correct_answer": "Correct answer 1 for question 1.",
"correct_answer_document_ids": ["data/folder1/id1a1q1", "data/folder1/id2a1q1"]
},
{
"question": "Question 1",
"correct_answer": "Correct answer 2 for question 1.",
"correct_answer_document_ids": ["data/folder1/id1a2q1", "data/folder1/id2a2q1"]
},
{
"question": "Question 2",
"correct_answer": "Correct answer 1 for question 2.",
"correct_answer_document_ids": ["data/folder1/id1a1q2", "data/folder1/id2a1q2"]
}
]
例如,以下是使用watsonx.ai Python库文档训练的模式的示例问题和答案。
[
{
"question": "What foundation models are available in watsonx.ai?",
"correct_answer": "The following models are available in watsonx.ai: \nflan-t5-xl-3b\nFlan-t5-xxl-11b\nflan-ul2-20b\ngpt-neox-20b\ngranite-13b-chat-v2\ngranite-13b-chat-v1\ngranite-13b-instruct-v2\ngranite-13b-instruct-v1\nllama-2-13b-chat\nllama-2-70b-chat\nmpt-7b-instruct2\nmt0-xxl-13b\nstarcoder-15.5b",
"correct_answer_document_ids": [
"data/folder1/5B37710FE7BBD6EFB842FEB7B49B036302E18F81_0.txt"
]
},
{
"question": "What foundation models are available on Watsonx, and which of these has IBM built?",
"correct_answer": "The following foundation models are available on Watsonx:\n\n1. flan-t5-xl-3b\n2. flan-t5-xxl-11b\n3. flan-ul2-20b\n4. gpt-neox-20b\n5. granite-13b-chat-v2 (IBM built)\n6. granite-13b-chat-v1 (IBM built)\n7. granite-13b-instruct-v2 (IBM built)\n8. granite-13b-instruct-v1 (IBM built)\n9. llama-2-13b-chat\n10. llama-2-70b-chat\n11. mpt-7b-instruct2\n12. mt0-xxl-13b\n13. starcoder-15.5b\n\n The Granite family of foundation models, including granite-13b-chat-v2, granite-13b-chat-v1, and granite-13b-instruct-v2 has been build by IBM.",
"correct_answer_document_ids": [
"data/folder1/5B37710FE7BBD6EFB842FEB7B49B036302E18F81_0.txt",
"data/folder1/B2593108FA446C4B4B0EF5ADC2CD5D9585B0B63C_0.txt"
]
},
{
"question": "What is greedy decoding?",
"correct_answer": "Greedy decoding produces output that closely matches the most common language in the model's pretraining data and in your prompt text, which is desirable in less creative or fact-based use cases. A weakness of greedy decoding is that it can cause repetitive loops in the generated output.",
"correct_answer_document_ids": [
"data/folder1/42AE491240EF740E6A8C5CF32B817E606F554E49_1.txt"
]
},
{
"question": "When to tune a foundation model?",
"correct_answer": "Tune a foundation model when you want to do the following things:\n\nReduce the cost of inferencing at scale\nGet the model's output to use a certain style or format\nImprove the model's performance by teaching the model a specialized task\nGenerate output in a reliable form in response to zero-shot prompts\"",
"correct_answer_document_ids": [
"data/folder1/FBC3C5F81D060CD996489B772ABAC886F12130A3_0.txt"
]
},
{
"question": "What tuning parameters are available for IBM foundation models?",
"correct_answer": "Tuning parameter values for IBM foundation models:\nInitialization method\ninitialization text\nbatch_size\naccumulate_steps\nlearning_rate\nnum_epochs\"",
"correct_answer_document_ids": [
"data/folder1/51747F17F413F1F34CFD73D170DE392D874D03DD_2.txt"
]
},
{
"question": "How do I avoid generating personal information with foundation models?",
"correct_answer": "To exclude personal information, try these techniques:\n- In your prompt, instruct the model to refrain from mentioning names, contact details, or personal information.\n- In your larger application, pipeline, or solution, post-process the content that is generated by the foundation model to find and remove personal information.\"",
"correct_answer_document_ids": [
"data/folder1/E59B59312D1EB3B2BA78D7E78993883BB3784C2B_4.txt"
]
},
{
"question": "What is Watson OpenScale?",
"correct_answer": "Watson OpenScale is a tool that helps organizations evaluate and monitor the performance of their AI models. It tracks and measures outcomes from AI models, and helps ensure that they remain fair, explainable, and compliant no matter where the models were built or are running. Watson OpenScale also detects and helps correct the drift in accuracy when an AI model is in production.",
"correct_answer_document_ids": [
"data/folder1/777F72F32FD20E96C4A5F0CCA461FE9A79334E96_0.txt"
]
}
]
选择载体商店
您必须在用于存储和检索问答过程内容的数据库中提供一个存储矢量化文档的位置。 有关可用数据库选项的详细信息,请参阅选择矢量存储。
- 默认的 Chroma 内存数据库是用于运行实验的临时向量存储。 该指数在实验结束后不会继续保持,因此不适合在生产中使用。
- 如果您想要一个永久的矢量存储,请连接或设置一个 Milvus 数据库。 如果计划部署 RAG 模式,请使用此选项。 详情请参阅设置 watsonx.data Milvus 矢量存储
要连接到 Milvus 矢量存储,您可以选择通用 Milvus 连接器类型,或者 watsonx.data Milvus 连接器。
观看此视频,了解如何创建AutoAIRAG 实验。
本视频提供了学习本文档中的概念和任务的直观方法。
创建AutoAIRAG 实验
请按照以下步骤定义并运行实验,使用默认配置设置作为快速路径,为您的用例搜索最佳 RAG 模式。
在watsonx.ai欢迎页面或项目的 "新建资产"页面,单击 "自动构建人工智能解决方案"。
输入实验名称和可选描述,选择配置大小,然后点击创建。 您还必须有一个与项目关联的 watsonx.ai 运行时服务实例。
提示: 如果您在配置实验时遇到错误,请检查您的计划是否具有足够的资源。 如果问题仍然存在,请尝试轮换您的 IBM Cloud 任务凭证。选择 "构建 RAG 解决方案"作为实验类型。
上传或连接文件收集和评估数据。 为文件集选择多达 20 个文件文件夹和文件。 评估数据文件必须是一个单一的 JSON 文件。 您也可以使用现有的知识库,而无需上传文档。 有关详细信息,请参阅 《在 AutoAI RAG实验中使用知识库》。

选择文件集矢量索引的存储位置。
指定要用作评估实验结果基准数据的 JSON 文件。
可选:选择或创建一个部署空间,实验完成后模式将部署到该空间。 若未设置目标空间, AutoAI 系统将自动为图案创建空间。
可选:启用 “运行后自动部署顶部模式 ”功能,可在实验完成后自动部署顶部模式。 若设置目标部署空间,顶部模式将自动部署至该空间。
单击运行实验,使用默认设置创建 RAG 管道:
- 优化指标:针对答案忠实度指标,优化 RAG 模式的创建。
- 要考虑的模型:默认的所有模型类型会考虑所有可用的基础模型,以生成 RAG 模式。
如果您想根据自己的使用情况定制实验,实验设置是可配置的。 请参阅自定义 RAG 实验设置。
查看结果
使用以下工具查看进度和审查结果。
在实验运行过程中,进度图可以直观地显示管道的创建和优化过程。 将鼠标悬停在任何节点上,可查看更多细节。

实验完成后,单击 " 设置重要性 "查看每个设置对创建和排列优化模式的重要性。

查看排行榜,其中显示了根据优化指标结果排名的实验管道。

点击管道名称查看详细信息。 根据示例问题和答案,查看管道在各项指标上的得分情况。

分析完成后,单击 "保存"可自动生成笔记本资产,用于测试和使用 RAG 模式。

查看并运行生成的笔记本,以测试或使用您的 RAG 模式。 详情请参阅保存RAG模式。
后续步骤
- 要编辑配置选项,请参阅自定义 RAG 实验设置。
- 要分析模式,请参阅AutoAIRAG 模式详情。
- 要保存和使用RAG模式,请参阅保存RAG模式。