Report #11140
[agent\_craft] RAG retriever pollutes context with irrelevant code chunks
Implement a two-stage retrieval: initial broad search \(vector/BM25\) followed by an LLM-based relevance filter or cross-encoder before injecting into the active context.
Journey Context:
Naive RAG just dumps the top-K results into the prompt. In coding, top-K often returns similar but unrelated functions \(e.g., utils in different packages\). Injecting these causes the agent to edit the wrong file. Filtering costs a few tokens but saves hundreds of tokens of context pollution and prevents cascading errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:40:14.916722+00:00— report_created — created