1. Learn
  2. /
  3. 课程
  4. /
  5. 使用 LangChain 的 Retrieval Augmented Generation (RAG)

Connected

道练习

构建检索链

来到本章的收官环节!您将使用 LangChain 的表达式语言(LCEL)创建一个检索链。它会把您先前加载的 RAG 论文所生成的嵌入文档分块的向量存储、提示模板和一个 LLM 组合起来,这样您就可以开始与文档对话。

下面是您在上一个练习中创建并可直接使用的 prompt_template 提醒:

Use the only the context provided to answer the following question. If you don't know the answer, reply that you are unsure.
Context: {context}
Question: {question}

您之前创建的嵌入文档分块的 vector_store 也已为您加载好,同时还包含所有必需的库和类。

说明

100 XP
  • 将 Chroma 的 vector_store 转换为可在 LCEL 检索链中使用的检索器对象。
  • 创建 LCEL 检索链,组合 retriever、prompt_template、llm 与字符串输出解析器,使其能够回答输入问题。
  • 在给定的问题上调用该链。