Part 5: Boosting Travel AI Chatbot with RAG – Anaphora Resolution and Query Rewriting

This article explains how to enhance a travel‑focused AI customer‑service system by importing structured and unstructured data into a RAG pipeline, then applying anaphora resolution and query rewriting techniques—illustrated with FastGPT workflows, prompt templates, and practical examples—to improve retrieval accuracy and answer relevance.

Ubiquitous Tech
Ubiquitous Tech
Ubiquitous Tech
Part 5: Boosting Travel AI Chatbot with RAG – Anaphora Resolution and Query Rewriting

Overview

The piece walks through the fifth step of building an AI‑driven travel customer‑service bot, focusing on two RAG optimisation techniques—anaphora resolution and query rewriting—and shows how to integrate them into a FastGPT workflow.

Data Import for RAG

Data import is the foundation of any Retrieval‑Augmented Generation system. Both structured data (e.g., database tables) and unstructured data (PDFs, Word documents, images, web pages) must be harvested and loaded into the knowledge base.

In the previous episode the author used the open‑source automation tool N8N to crawl scenic‑spot pages from Tongcheng Travel, summarise them with a large model, and store the results as Markdown.

What Is Anaphora Resolution?

Anaphora resolution (or "指代消解") teaches a model to infer the real referent of pronouns such as “it”, “he”, or “here”. In conversational AI, failing to resolve these pronouns leads to irrelevant or incorrect answers, especially in RAG where the retrieved context must match the user’s intent.

What Is Query Rewriting?

Query rewriting (查询重写) transforms a user’s raw question into a clearer, more expressive form that aligns better with the terminology of the knowledge base. For example, rewriting “它开放吗?” to “Is the Great Wall open now?” improves retrieval precision.

5W1H of Anaphora Resolution

What: Identify the true target of pronouns in text.

Why: Prevent information mixing and boost recall/accuracy in RAG.

When: Essential for complex texts with multiple pronoun references.

Where: Used in QA systems, dialogue bots, machine translation, information extraction, etc.

Who: Adopted by AI‑customer‑service platforms and research labs.

How: Steps include candidate entity detection, feature extraction, model inference, and post‑processing.

Implementation Steps

Detect candidate entities that a pronoun might refer to.

Extract contextual features from chat history and semantics.

Use a large‑model (e.g., GPT‑4o) to decide the best referent.

Post‑process the result to ensure overall accuracy.

FastGPT Workflow Example

The author adds a single AI node to the FastGPT workflow that runs a prompt to perform both anaphora resolution and query rewriting before the RAG retrieval step.

Sample prompt used for the AI node:

## 角色
你是用户问题的文案转换专家,能够根据用户的问题进行指代消解,根据用户问题重写为一个新问题。定位并解析代词(如“它”、“这个”,"刚才")的具体指向,将用户问题转换为为没有代词的问题,并且补全问题中缺失的历史上下文主题与关键词
本轮问题如下:
xxxxxx
请根据用户问题,进行问题转换,强制需要包含景点名称,不要对用户的问题进行回答,需要对用户的问题重写。

A more detailed prompt for production use includes role definition, task description, context bridging, intelligent anaphora handling, intent decomposition, information completion, and cross‑turn filling.

### 角色
你是xxx公司一个专业的用户问题重写专家,具备多维对话状态建模能力,精准识别本轮用户问题中的显性/隐性需求,你的任务是结合对话上下文聊天记录和本轮的问题,对用户本轮问题进行准确、自然、流畅的表达进行用户文案重写,以提升后续处理的准确性。
### 任务
1. **上下文桥梁**:解析历史对话中的实体、事件和状态信息,确保重写问题与上下文语境一致。
2. **智能指代消解**:示例表格展示代词→实体的替换逻辑。
3. **意图解构**:区分表层提问与深层需求。
4. **信息补全**:为省略主语的句子补全实体。
5. **跨轮补全机制**:回溯最近5轮对话,提取最后出现的核心实体并替换代词。
### 重写规则
- 保留用户原意、语气、情绪。
- 只返回重写后的问题,不包含解释。

Query Transformation Techniques

Query transformation in RAG includes three common strategies: query rewriting, query expansion, and query decomposition. The author shows a diagram (sourced from the LangChain repo) illustrating these methods.

These techniques modify the input query to enhance retrieval results, reducing semantic gaps between the user's wording and the documents in the knowledge base.

Conclusion

By integrating anaphora resolution and query rewriting into the RAG pipeline—implemented via simple FastGPT prompts and workflow nodes—developers can markedly improve recall rates and answer relevance for AI customer‑service applications. The author encourages further exploration of these “detail” capabilities to achieve smarter, more accurate AI assistants.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

prompt engineeringRAGAI chatbotQuery RewritingFastGPTAnaphora Resolution
Ubiquitous Tech
Written by

Ubiquitous Tech

A ubiquitous public account for pirate enthusiasts, regularly sharing curated experiences, tech learning, and growth insights. Currently publishing articles on AI RAG customer service, AI MCP technology, and open-source design. Personal free Knowledge Planet: Awakening New World Programmer.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.