微信扫码
添加专属顾问
我要投稿
提高 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+中大型企业
2026-05-22
四种索引,一个系统,重新定义 AI 如何理解知识
2026-05-22
腾讯云Agent Memory节省61% Token提升52%成功率的诀窍:Mermaid无限画布×上下文卸载
2026-05-22
企业知识库下半场:从 RAG 到 context architecture
2026-05-22
每个RAG工程师都应该了解的Ranking技术
2026-05-21
清华提出NaviRAG:让RAG学会"主动导航",长文问答F1涨4.8分
2026-05-20
AIOps探索:给不能联网的客户做一个AI运维助手到底有多难?
2026-05-18
别再错过啦,AI Agent记忆革命:95.2%检索率的持久记忆系统深度解析
2026-05-18
有多少人把Agent与RAG的检索策略,简化成了 if-else?
2026-03-23
2026-04-06
2026-03-18
2026-03-20
2026-02-27
2026-03-21
2026-04-27
2026-03-31
2026-04-02
2026-03-17
2026-05-20
2026-05-18
2026-05-11
2026-05-07
2026-05-06
2026-04-27
2026-04-21
2026-03-17