LangChain4j系列:QueryTransformer 让大模型更理解用户意图

# LangChain4j系列:Advanced RAG 核心组件源码分析与实践 文章中介绍了Advanced RAG 增强器组件,本文开始对查询转换器 QueryTransformer 的优化方案进行一一详细解密并实战。

更详细的内容大家参考如下:

查询转换 ??

查询转换将用户输入查询转换为一个或者多个查询,目标是通过修改或扩展原始 Query 来提高检索质量。让大模型更了解用户的真实意图。

目前已知的一些查询转换的方式和技术;

  • 查询压缩 (Query compression)
  • 查询扩展 (Query expansion)
  • 查询重写 (Query re-writing)
  • 后退提示 (Step-back prompting)
  • 假设文档嵌入 (HyDE)

本文将详细介绍每种查询转换技术的技术细节以及在实践中如何使用它们。

查询压缩

在LangChain4j框架中查询压缩的实现方式基于:大模型 + 提示词。

text 复制代码
"""
        Read and understand the conversation between the User and the AI. \
        Then, analyze the new query from the User. \
        Identify all relevant details, terms, and context from both the conversation and the new query. \
        Reformulate this query into a clear, concise, and self-contained format suitable for information retrieval.
        
        Conversation:
        {{chatMemory}}
        
        User query: {{query}}
        
        It is very important that you provide only reformulated query and nothing else! \
        Do not prepend a query with anything!"""

意思就是:从用户会话的上下文中识别与用户查询相关的内容,将用户的查询改写为清晰、准确、自描述的新的查询。

举个例子:

text 复制代码
User: Tell me about John Doe  
AI: John Doe was a ...  
User: Where did he live?

Where did he live?如果不结合历史会话或者说没有查询压缩,那么大模型无法确认 he 是谁。所以经过压缩查询,Where did he live?将会转换为 Where did John Doe live?

查询扩展

学习中,逐步完善

查询重写

学习中,逐步完善

Step-Back Prompting

学习中,逐步完善

HyDE

学习中,逐步完善

相关推荐
持久的棒棒君1 小时前
npm安装electron下载太慢,导致报错
前端·electron·npm
crary,记忆3 小时前
Angular微前端架构:Module Federation + ngx-build-plus (Webpack)
前端·webpack·angular·angular.js
漂流瓶jz4 小时前
让数据"流动"起来!Node.js实现流式渲染/流式传输与背后的HTTP原理
前端·javascript·node.js
SamHou04 小时前
手把手 CSS 盒子模型——从零开始的奶奶级 Web 开发教程2
前端·css·web
我不吃饼干4 小时前
从 Vue3 源码中了解你所不知道的 never
前端·typescript
Georgewu4 小时前
【ModelArts】ModelArts一站式AI开发平台详解(一)
aigc·openai·ai编程
开航母的李大4 小时前
【中间件】Web服务、消息队列、缓存与微服务治理:Nginx、Kafka、Redis、Nacos 详解
前端·redis·nginx·缓存·微服务·kafka
Bruk.Liu4 小时前
《Minio 分片上传实现(基于Spring Boot)》
前端·spring boot·minio
Georgewu4 小时前
【HarmonyOS 5】鸿蒙CodeGenie AI辅助编程工具详解
华为·ai编程·harmonyos
鱼樱前端5 小时前
Vue3+d3-cloud+d3-scale+d3-scale-chromatic实现词云组件
前端·javascript·vue.js