Performance: Why conversation history improves RAG
This concept affects the responsiveness and relevance of retrieval-augmented generation by managing how much data is processed and rendered during interactions.
const recentHistory = chatLog.slice(-5).join(' '); const response = await ragModel.generate({ query: userInput, context: recentHistory });
const conversationHistory = fullChatLog.join(' '); const response = await ragModel.generate({ query: userInput, context: conversationHistory });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full conversation history as context | Minimal DOM changes | 0 | Low paint cost | [X] Bad due to slow input processing |
| Limited recent history as context | Minimal DOM changes | 0 | Low paint cost | [OK] Good balance of relevance and speed |
history = [
{"role": "user", "content": "What is AI?"},
{"role": "assistant", "content": "AI means Artificial Intelligence."}
]
query = "Explain AI applications."
retrieved_docs = retriever.get_relevant_documents(history + [{"role": "user", "content": query}])
print(len(retrieved_docs))
If the retriever returns 3 documents when given full history plus query, but only 1 document when given query alone, what does this show?history = [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi! How can I help?"}
]
# Later code
retriever.get_relevant_documents(history)
Why might this cause an error or poor retrieval?Pass the test and this pattern moves unknown