Description
To maintain a natural chat flow, the LLM needs to remember previous questions and answers. However, blindly appending the whole history to the prompt will quickly exceed the context window and increase API costs.
Implementation
- Store chat sessions in a relational database (e.g., PostgreSQL).
- Implement a context management strategy in
bots/:
- Keep the last N messages verbatim.
- Use a background LLM call to summarize older parts of the conversation.
- Pass the combination of summary + recent history + retrieved document chunks to the LLM.
Level: Advanced
Affected Files: backend/history.py, bots/memory.py, migrations/
Description
To maintain a natural chat flow, the LLM needs to remember previous questions and answers. However, blindly appending the whole history to the prompt will quickly exceed the context window and increase API costs.
Implementation
bots/:Level: Advanced
Affected Files:
backend/history.py,bots/memory.py,migrations/