Skip to content

Improve Context Management in Message Generation #5

@avishek0769

Description

@avishek0769

Summary

Replace naive “last N messages” context assembly with a more robust context strategy for better quality and lower token waste.

Problem

sendMessage currently appends recent messages directly, which can cause context bloat, stale history inclusion, and weaker grounding in long chats.

Expected Solution

Implement improved context window management (for example: rolling summary + recent turns + retrieval context). Ensure token-aware truncation and predictable prompt structure.

Scope

  • backend/controllers/chatMessage.controller.js
  • Optional helper modules under backend/utils/
  • Prompt and retrieval composition logic

Acceptance Criteria

  • Context builder enforces token/length budget before LLM call.
  • Long chats remain coherent without unbounded prompt growth.
  • Regression tests or reproducible checks verify better handling of long sessions.
  • Source grounding behavior remains intact.

Notes

Potential approaches: conversational summarization, semantic memory retrieval, recency weighting, or hybrid strategy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend issuesenhancementNew feature or requestmediumThis is issue is not easy to solve but not hard

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions