Report #15435
[agent\_craft] Agent retrieves too many code snippets and gets confused, trying to use APIs from unrelated files
Implement a strict relevance threshold and a hard limit on the number of files injected into the context. Prefer 1-3 highly relevant files over 10 marginally relevant ones.
Journey Context:
RAG systems often use top-K retrieval where K is set too high. In coding tasks, marginally relevant code often contains similar variable names or outdated APIs, leading the LLM to mix up contexts and hallucinate imports. High precision is far more important than high recall for in-context code generation. If the right file isn't in the top 3, the agent should refine its search query rather than drown in noise.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:12:16.014248+00:00— report_created — created