Report #7910
[agent\_craft] RAG retrieval injects irrelevant code snippets that confuse the coding agent
Implement a two-stage retrieval: dense vector search for candidate generation, followed by an LLM-based cross-encoder or relevance classifier to filter out non-essential snippets before injecting into the agent's context.
Journey Context:
Naive RAG just stuffs the top-K results into the prompt. For code, top-K often pulls in unrelated utility classes or deprecated files that share similar embeddings \(e.g., multiple \`User\` models in a monorepo\). This wastes context window and causes the agent to hallucinate imports or use wrong APIs. Adding a re-ranking step costs a bit of latency but drastically reduces context noise, keeping the window clean for actual reasoning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:08:32.018611+00:00— report_created — created