微信扫码
添加专属顾问
我要投稿
提高 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-04-30
聊聊AI智能体框架MetaGPT下的RAG实践
2025-04-30
如何用大模型+RAG给宠物做一个AI健康助手(干货分享)?
2025-04-30
HiRAG:基于层级知识索引和检索的高精度RAG
2025-04-29
教程|通义Qwen 3 +Milvus,混合推理模型才是优化RAG成本的最佳范式
2025-04-29
RAG开发框架LangChain与LlamaIndex对比解析:谁更适合你的AI应用?
2025-04-29
RAG性能暴增20%!清华等推出“以笔记为中心”的深度检索增强生成框架,复杂问答效果飙升
2025-04-29
超神了,ChatWiki 支持GraphRAG,让 AI 具备垂直深度推理能力!
2025-04-29
AI 产品思维:我如何把一个 AI 应用从基础 RAG 升级到 multi-agent 架构
2024-10-27
2024-09-04
2024-07-18
2024-05-05
2024-06-20
2024-06-13
2024-07-09
2024-07-09
2024-05-19
2024-07-07
2025-04-30
2025-04-29
2025-04-29
2025-04-26
2025-04-25
2025-04-22
2025-04-22
2025-04-20