Skip to content

[Feature] Implement Conversation History Persistence and Context Window Management #827

Description

@knoxiboy

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

  1. Store chat sessions in a relational database (e.g., PostgreSQL).
  2. 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.
  3. Pass the combination of summary + recent history + retrieved document chunks to the LLM.

Level: Advanced
Affected Files: backend/history.py, bots/memory.py, migrations/

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssocGirlScript Summer of Code 2026 issue/PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions