微信扫码
添加专属顾问
我要投稿
提高 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-03-21
面向手机Agent的记忆系统工程:OPPO的Agentic-RAG实战与演进
2026-03-20
为什么总感觉 Claude Code 比 Cursor 聪明?真正的原因根本不是模型能力!
2026-03-18
从RAG到GraphRAG:货拉拉元数据检索应用实践
2026-03-17
企业AI落地三重门,用友如何破局?
2026-03-16
Java 开发者的轻量级 RAG 方案:MeiliSearch 混合搜索实战
2026-03-11
Embedding相似度虚高,如何用langchain+Milvus搭建CRAG解决?
2026-03-11
上下文腐烂:拖垮企业AI与LLM表现的隐患与对策
2026-03-10
从向量里逆向出原始文本和模型来源
2026-01-15
2026-01-02
2025-12-23
2026-02-13
2026-02-03
2025-12-31
2026-01-06
2026-02-03
2025-12-29
2026-02-06
2026-03-17
2026-03-11
2026-02-22
2026-02-15
2026-02-04
2026-02-03
2026-01-19
2026-01-12