Concept Flow - Why conversation history improves RAG
User asks question
↓
Retrieve conversation history
↓
Combine history + new question
↓
Use combined input to query knowledge base
↓
Retrieve relevant documents
↓
Generate answer using retrieved docs + context
↓
Return improved, context-aware answer
The system uses past conversation to add context, then retrieves documents and generates a better answer.
Execution Sample
LangChain
history = ['What is AI?', 'Explain RAG.']
new_question = 'How does history help?'
combined_input = history + [new_question]
docs = retriever(combined_input)
answer = generator(docs, combined_input)
print(answer)
This code shows how conversation history is combined with a new question to retrieve documents and generate an answer.
Execution Table
Step
Action
Input
Output
Notes
1
Receive new question
'How does history help?'
new_question = 'How does history help?'
User asks a new question
2
Retrieve conversation history
['What is AI?', 'Explain RAG.']
history = ['What is AI?', 'Explain RAG.']
Past questions stored
3
Combine history and new question
history + [new_question]
combined_input = ['What is AI?', 'Explain RAG.', 'How does history help?']
Context is built
4
Retrieve documents using combined input
combined_input
docs = ['doc1', 'doc2']
Relevant docs found based on full context
5
Generate answer using docs and combined input
docs + combined_input
answer = 'History helps by providing context...'
Answer is context-aware
6
Output answer
answer
'History helps by providing context...'
Final improved answer shown
💡 All steps complete, answer generated with conversation history improving relevance.
Variable Tracker
Variable
Start
After Step 2
After Step 3
After Step 4
After Step 5
Final
history
[]
['What is AI?', 'Explain RAG.']
['What is AI?', 'Explain RAG.']
['What is AI?', 'Explain RAG.']
['What is AI?', 'Explain RAG.']
['What is AI?', 'Explain RAG.']
new_question
''
''
'How does history help?'
'How does history help?'
'How does history help?'
'How does history help?'
combined_input
[]
[]
['What is AI?', 'Explain RAG.', 'How does history help?']
['What is AI?', 'Explain RAG.', 'How does history help?']
['What is AI?', 'Explain RAG.', 'How does history help?']
['What is AI?', 'Explain RAG.', 'How does history help?']
docs
[]
[]
[]
['doc1', 'doc2']
['doc1', 'doc2']
['doc1', 'doc2']
answer
''
''
''
''
'History helps by providing context...'
'History helps by providing context...'
Key Moments - 3 Insights
Why do we combine conversation history with the new question before retrieving documents?
Combining history with the new question (see Step 3 in execution_table) gives the retriever more context, so it finds documents that better match the full conversation, not just the last question.
What happens if we don't use conversation history in retrieval?
If history is not used, the retriever only sees the new question (Step 1), so it might miss important context, leading to less relevant documents and a weaker answer (compare Step 4 with and without history).
How does the answer generation use the conversation history?
The answer generator uses both the retrieved documents and the combined input (Step 5) to produce an answer that fits the whole conversation, making it more accurate and coherent.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 3. What does combined_input contain?
AOnly the new question
BOnly the conversation history
CConversation history plus the new question
DRetrieved documents
💡 Hint
Check the 'Output' column at Step 3 in the execution_table.
At which step does the system retrieve documents based on the combined input?
AStep 2
BStep 4
CStep 5
DStep 6
💡 Hint
Look for the step where 'Retrieve documents' is the action in the execution_table.
If we removed conversation history, how would the 'docs' variable change at Step 4?
AIt would contain more documents
BIt would be empty
CIt might contain less relevant documents
DIt would be the same
💡 Hint
Refer to the key_moments explanation about the importance of history in retrieval.
Concept Snapshot
Why conversation history improves RAG:
- Combine past conversation with new question
- Use combined input to retrieve documents
- Generate answer using docs + full context
- History adds important context
- Leads to more relevant retrieval and better answers
Full Transcript
This visual execution shows how conversation history improves Retrieval-Augmented Generation (RAG). First, the system receives a new question. Then it retrieves past conversation history. It combines the history with the new question to create a richer input. This combined input is used to retrieve relevant documents from the knowledge base. Finally, the answer generator uses both the retrieved documents and the combined input to produce a context-aware answer. Using conversation history helps the system understand the question better and find more relevant information, resulting in improved answers.