微信扫码
添加专属顾问
我要投稿
提高 RAG 推理能力的一个好方法是添加查询理解层 ——在实际查询向量存储之前添加查询转换。以下是四种不同的查询转换:
HyDE来自于Precise Zero-Shot Dense Retrieval without Relevance Labels,这篇文章主要做zero-shot场景下的稠密检索,通过借助LLM的力量不需要Relevance Labels,开箱即用。作者提出Hypothetical Document Embeddings (HyDE)方法,即“假设”文档嵌入。具体的做法是通过GPT生成虚构的文档,并使用无监督检索器对其进行编码,并在其嵌入空间中进行搜索,从而不需要任何人工标注数据模型结构如下图所示,HyDE将密集检索分解为两个任务,即 instruction-following的LM生成任务和对比编码器执行的文档相似性任务。
paper:https://arxiv.org/pdf/2212.10496
code:https://github.com/texttron/hyde
典型的密集信息检索过程包括以下步骤:
我们在LangChain上实际使用一下。
from langchain.embeddings import OpenAIEmbeddings
from langchain.chains import LLMChain, HypotheticalDocumentEmbedder
from langchain.prompts import PromptTemplate
from langchain.chat_models import ChatOpenAI
from dotenv import load_dotenv
# set the environment variables
load_dotenv()
# prepare the prompt template for document generation
Prompt_template = """回答问题。
问题:{question}
回答:”””
llm = ChatOpenAI()
# multi_llm = ChatOpenAI(n=4)
prompt = PromptTemplate(input_variables=["question"], template=prompt_template)
llm_chain = LLMChain(llm=llm, prompt=prompt, verbose=True)
# initialize the hypothetical document embedder
base_embeddings = OpenAIEmbeddings()
embeddings = HypotheticalDocumentEmbedder(llm_chain=llm_chain, base_embeddings=base_embeddings)
result = embeddings.embed_query("塞尔达传说的主角是谁?")
len(result)
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-07-01
qodo如何构建大型代码仓库的RAG?
2025-07-01
爆改RAG!让你的AI检索“见人说人话,见鬼说鬼话”——自适应检索的魔法揭秘
2025-07-01
RAG系统的“聪明药”:如何用反馈回路让你的AI越用越聪明?
2025-06-30
EraRAG:突破传统GraphRAG限制,实现动态语料库的高效检索增强生成
2025-06-30
GraphRAG的索引动态更新解法-分桶+局部更新及“上下文工程”新概念?
2025-06-30
RAG搭建个人LLM知识库助手,很多人第一步就走错了...
2025-06-29
你的RAG系统安全么?
2025-06-28
Dify+RAG合同生成:条款级工作流案例拆解
2025-04-13
2025-04-19
2025-04-09
2025-04-16
2025-05-08
2025-04-05
2025-04-23
2025-04-08
2025-04-10
2025-04-09
2025-07-01
2025-07-01
2025-06-30
2025-06-29
2025-06-20
2025-06-19
2025-06-13
2025-06-09