{
  "schema": "vedokrok.public-item.v1",
  "release_id": "MHC-RPUB-20260920-75ad787a",
  "url": "/knowledge/retrieve-code-before-sending-code",
  "id": "MHC-D-RESEARCH-1170",
  "version": "0.1.0",
  "title": "Retrieve code before sending code",
  "summary": "The cheapest token is the irrelevant file you never send.",
  "kind": "protocol",
  "body": "Build a local or privacy-appropriate code retrieval layer that combines complementary search signals, rejects weak matches and supplies only likely relevant fragments. Measure recall on known tasks before relying on the savings; a tiny context that omits the dependency is not efficient.",
  "limits": [
    "Repository structure matters. Retrieval that works on one codebase can miss generated code, dynamic links or cross-cutting configuration elsewhere."
  ],
  "topics": [
    "union-ai-runtime-verification-2026"
  ],
  "intents": [],
  "source_ids": [
    "RS-E45EC996E3B1A3AA"
  ],
  "evidence": [
    {
      "claim": "A local code-retrieval layer can select relevant repository fragments before model inference instead of repeatedly sending broad code context.",
      "source_id": "RS-E45EC996E3B1A3AA",
      "role": "supports",
      "note": "Retrieval can miss dependencies or return plausible irrelevant code. The reported headline token reduction is case-specific and is not a universal expectation.",
      "locator": "Architecture sections on local retrieval, complementary searches, relevance rejection and benchmark comparison"
    }
  ],
  "use_when": [
    "A coding assistant repeatedly receives large repository dumps or oversized file context to answer narrow questions."
  ],
  "avoid_when": [
    "Repository structure matters. Retrieval that works on one codebase can miss generated code, dynamic links or cross-cutting configuration elsewhere."
  ],
  "example": "For a failing API endpoint, retrieve the route, service and referenced model instead of uploading the whole repository tree to every coding turn.",
  "check": "Known-task benchmarks show that the reduced context still retrieves the dependencies needed for correct answers.",
  "steps": [
    "Create a benchmark of code questions with known relevant files or symbols.",
    "Combine lexical and semantic search when they cover different misses.",
    "Reject low-relevance candidates instead of filling the context quota.",
    "Measure retrieval recall, task success and total context cost together."
  ],
  "sources": [
    {
      "id": "RS-E45EC996E3B1A3AA",
      "title": "We Cut 94% of Our AI Coding Tokens With a Local Code Index. Here's the Architecture.",
      "url": "https://ai.engineer/talks/dRmWYHuIJxM-we-cut-94-our-ai-coding-tokens"
    }
  ],
  "relations": [
    {
      "from": "MHC-D-RESEARCH-1170",
      "to": "MHC-D-RESEARCH-0702",
      "type": "useful_with",
      "url": "/knowledge/treat-context-as-a-budget-not-a-transcript"
    }
  ],
  "collections": [
    {
      "id": "RC-ACD6385FB70207D3",
      "title": "Operate AI agents as systems you can replay, verify and constrain",
      "url": "/collections/operate-ai-agents-as-systems-you-can-replay-verify-and-constrain"
    }
  ]
}
