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
Notes
Potential approaches: conversational summarization, semantic memory retrieval, recency weighting, or hybrid strategy.
Summary
Replace naive “last N messages” context assembly with a more robust context strategy for better quality and lower token waste.
Problem
sendMessagecurrently 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.jsbackend/utils/Acceptance Criteria
Notes
Potential approaches: conversational summarization, semantic memory retrieval, recency weighting, or hybrid strategy.