Skip to content

feat: document routing for relevant context selection#10

Merged
mrjunos merged 2 commits into
mainfrom
feat/document-router
Apr 8, 2026
Merged

feat: document routing for relevant context selection#10
mrjunos merged 2 commits into
mainfrom
feat/document-router

Conversation

@mrjunos

@mrjunos mrjunos commented Apr 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a lightweight LLM routing step that selects 1-3 relevant documents before building chat context, instead of dumping all documents into every query
  • Includes recent conversation history in routing decision so follow-up questions ("tell me more") route to the correct documents
  • Increases session history limit from 6 to 10 messages for better conversational memory
  • Falls back to all documents if routing fails

Why

Previously, every chat query included summaries from ALL indexed documents. This caused two problems:

  1. Answers referenced irrelevant documents (asking about one topic returned info from all 7+ docs)
  2. Conversation context was lost because document summaries consumed most of the LLM's context window

Test plan

  • 58 existing tests pass
  • Manual: ask about a specific document, verify only relevant sources returned
  • Manual: follow-up question ("tell me more"), verify context is maintained

🤖 Generated with Claude Code

Juan José Cano Duque and others added 2 commits April 8, 2026 09:18
Instead of sending all document summaries to the LLM on every query,
a lightweight routing step now selects 1-3 relevant documents first.
This reduces context noise, improves answer quality, and fixes
conversation memory by freeing context window space for chat history.

Also increases session history limit from 6 to 10 messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests cover:
- _extract_first_summary: truncation, fallbacks, edge cases (7 tests)
- _route_documents: exact match, bullet prefix, fuzzy match, LLM failure
  fallback, empty docs, conversation history, dedup, timeout (10 tests)
- process_chat routing integration: context filtering, history passing,
  session limit (3 tests)

Also fixes a bug where the router could return duplicate doc IDs when
the LLM mentioned the same document name multiple times in its response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mrjunos
mrjunos merged commit 3be7126 into main Apr 8, 2026
1 check passed
@mrjunos
mrjunos deleted the feat/document-router branch April 8, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant