1. Why Naive RAG Fails in Multi-Turn Conversations
Standard (Naive) RAG assumes every question is an isolated, single-turn query. In real-world chat applications ("Chat with your PDF", enterprise support bots), conversations are inherently contextual.
Consider this two-turn conversation:
Turn 1:
User: "What is the warranty period for the Acme X100 server?"
Retriever searches: "What is the warranty period for the Acme X100 server?"
Vector Store returns: Relevant chunk: "Acme X100 includes a 3-year hardware warranty."
AI: "The Acme X100 server comes with a 3-year hardware warranty."
Turn 2:
User: "Can you explain its renewal conditions?"
Retriever searches: "Can you explain its renewal conditions?"
Vector Store returns: IRRELEVANT CHUNKS (Nothing matches "its renewal conditions").
AI: Hallucinates or says "I don't have enough information."
The Root Cause:
The vector retriever has no access to previous conversation turns. It performs semantic search using only the raw string "Can you explain its renewal conditions?". Because pronouns like "it", "its", or "that" lack semantic keywords, the vector search retrieves irrelevant chunks.
2. The Solution: Two-Stage Conversational RAG Architecture
To solve this, production conversational RAG systems decouple retrieval into two specialized sub-chains:
flowchart TB
subgraph S1["1 · Query reformulation"]
H["Chat history + follow-up question"] -- "LLM call: rewrite into a standalone question" --> SQ["Standalone search query<br/><small>'What are the warranty renewal conditions for X100?'</small>"]
end
subgraph S2["2 · Retrieval"]
SQ -- "vector search" --> CH["Relevant document chunks"]
end
subgraph S3["3 · Answer"]
CH --> F["Chunks + chat history + original question"] -- "LLM final call" --> ANS["Grounded answer"]
end
classDef term fill:#0e3b3a,stroke:#0e3b3a,color:#ffffff,font-weight:bold
classDef gate fill:#fdf1ec,stroke:#c9583a,color:#7a2e1a
classDef store fill:#f5f5f4,stroke:#57534e,color:#292524
classDef c0 fill:#d4ecea,stroke:#2a7a79,color:#0e3b3a
classDef c1 fill:#fbe5dc,stroke:#c9583a,color:#7a2e1a
classDef c2 fill:#e3f5ee,stroke:#4aa58a,color:#14463a
classDef c3 fill:#f6f4f0,stroke:#a7a29a,color:#3f3b35
classDef c4 fill:#eef7f7,stroke:#1a5c5b,color:#0e3b3a
class S1 c0
class H c1
class SQ c2
class S2 c3
class CH c4
class S3 c0
class F c1
class ANS c2
style S1 fill:#f4fafa,stroke:#9fcfce,stroke-width:1.5px
style S2 fill:#fdf6f3,stroke:#ecc0ae,stroke-width:1.5px
style S3 fill:#f3faf7,stroke:#9fe0c7,stroke-width:1.5px+-----------------------------------------------------------------------------------+
| CONVERSATIONAL RAG WORKFLOW |
+-----------------------------------------------------------------------------------+
| |
| 1. Query Reformulation Sub-Chain: |
| [Chat History] + [Raw Follow-up Question] |
| │ |
| ▼ (LLM Sub-call: Reformulates pronoun-heavy prompt) |
| [Standalone Search Query: "What are the warranty renewal conditions for X100?"]|
| │ |
| 2. Vector DB Retrieval: |
| ▼ (Vector Store semantic search) |
| [Relevant Document Chunks] |
| │ |
| 3. Final Answer Generation: |
| [Retrieved Chunks] + [Chat History] + [Original Question] |
| │ |
| ▼ (LLM Final call) |
| [Grounded Natural Language Response] |
+-----------------------------------------------------------------------------------+
- Stage 1 (Query Reformulation): A lightweight prompt takes the chat history and the latest user query, rewriting it into a standalone search query that contains all necessary entity names.
- Stage 2 (Grounded Generation): The standalone query retrieves the correct chunks from the vector database. Those chunks, along with conversation history, are passed to the final generator to answer the user.
3. Production Implementation: History-Aware RAG in LangChain
Complete working script combining create_history_aware_retriever, create_retrieval_chain, and ChromaDB:
import os
from dotenv import load_dotenv
load_dotenv()
from langchain_mistralai import ChatMistralAI, MistralAIEmbeddings
from langchain_chroma import Chroma
from langchain_core.documents import Document
from langchain_core.messages import HumanMessage, AIMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.chains import create_history_aware_retriever, create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain
# 1. Initialize LLM and Embedding Model
llm = ChatMistralAI(model="mistral-large-latest", temperature=0.1)
embeddings = MistralAIEmbeddings(model="mistral-embed")
# 2. Setup Vector Store with Sample Knowledge Base
sample_docs = [
Document(
page_content="The Acme X100 server has a standard 3-year hardware warranty covering parts and labor.",
metadata={"source": "warranty_manual.pdf"}
),
Document(
page_content="To renew the Acme X100 warranty, the renewal request must be submitted 30 days prior to expiration and requires a certified hardware inspection.",
metadata={"source": "warranty_manual.pdf"}
)
]
vector_store = Chroma.from_documents(
documents=sample_docs,
embedding=embeddings,
collection_name="warranty_kb"
)
retriever = vector_store.as_retriever(search_kwargs={"k": 2})
# 3. Sub-Chain 1: History-Aware Query Reformulation Prompt
contextualize_q_system_prompt = (
"Given a chat history and the latest user question "
"which might reference context in the chat history, "
"formulate a standalone question which can be understood "
"without the chat history. Do NOT answer the question, "
"just reformulate it if needed and otherwise return it as is."
)
contextualize_q_prompt = ChatPromptTemplate.from_messages([
("system", contextualize_q_system_prompt),
MessagesPlaceholder("chat_history"),
("human", "{input}"),
])
history_aware_retriever = create_history_aware_retriever(
llm, retriever, contextualize_q_prompt
)
# 4. Sub-Chain 2: Question-Answering Prompt Grounded in Context
qa_system_prompt = (
"You are an assistant for question-answering tasks. "
"Use the following pieces of retrieved context to answer "
"the question. If you don't know the answer, say that you "
"don't know. Keep the answer concise.\n\n"
"{context}"
)
qa_prompt = ChatPromptTemplate.from_messages([
("system", qa_system_prompt),
MessagesPlaceholder("chat_history"),
("human", "{input}"),
])
question_answer_chain = create_stuff_documents_chain(llm, qa_prompt)
rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)
# 5. Multi-Turn Interactive Execution Loop
chat_history = []
print("=== CONVERSATIONAL RAG (Type 'exit' to quit) ===\n")
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit"]:
break
# Execute chain with both query and accumulated history
response = rag_chain.invoke({
"input": user_input,
"chat_history": chat_history
})
print(f"\nAI: {response['answer']}\n")
# Update conversational history
chat_history.append(HumanMessage(content=user_input))
chat_history.append(AIMessage(content=response["answer"]))
4. Architectural Comparison: Naive RAG vs. Conversational RAG
| Evaluation Metric | Naive RAG (Single-Turn) | Conversational RAG (Multi-Turn) |
|---|---|---|
| LLM Calls per Request | 1 call (Final answer generation) | 2 calls (1 for query re-writing + 1 for answer generation) |
| Latency Overhead | Lower (\approx 1\times) | Slightly higher (\approx 1.5\times to 2\times) |
| Pronoun Resolution | Fails on words like "it", "they", "that" | Seamlessly resolves pronouns to specific entities |
| Context Grounding | High for standalone queries | High across all turns of long dialogues |
| Production Viability | One-off search bars & documentation lookup | Enterprise AI chat agents, customer support, and PDF copilots |