ai-coding large-codebase graph-rag ast retrieval

How do I give AI the context of a 1M-line codebase?

You don't — you give it a graph. Full-codebase context windows are a fantasy; graph-based retrieval is the real answer. bRRAIn ingests code as an AST-annotated graph and surfaces only relevant slices per query.

Why full-codebase context is the wrong goal

Vendors love to wave around 1M-token context windows as the answer to large codebases. They are not. A million tokens is roughly 40,000 lines of code — two per cent of a million-line repo. Even at 10M tokens the maths does not close, and attention across that span degrades rapidly. Worse, stuffing the window with irrelevant code drowns the signal. The question is not "how do I fit the whole codebase in context" but "how do I surface the right 500 lines for this query".

The graph as the retrieval substrate

bRRAIn ingests code as an AST-annotated layer of the POPE graph: Files, Functions, Calls, Tests, Owners, Modules. Each node carries typed edges, so a query like "where is chargeCustomer called and what tests guard it" returns a bounded, precise slice. The Code Sandbox parses and re-parses as commits land, keeping the graph fresh. The model's context window holds only the matched slice plus relevant ADRs — enough to answer the question, small enough to answer it well.

How queries route through the gateway

IDE agents — Cursor, Claude Code, custom Copilot variants — hit the graph through the MCP Gateway. The Embedded SDK provides a simple retrieval API: pass a query or a prompt, receive a graph slice plus cited decisions. The Handler assembles the final prompt with the slice inline, so the model generates against a focused, grounded context. Retrieval is typed and structural, not keyword search — so the slice actually contains the call sites and guards the question needs.

What this unlocks day to day

Senior questions about a million-line codebase become answerable in seconds rather than requiring a grep expedition. The agent reasons about dependencies it can actually see, with the trade-offs and tests that constrain them. New engineers navigate the codebase through the graph rather than through tribal knowledge. Refactors scoped to "every call site of this function" run safely because the graph enumerates them precisely. Graph-based retrieval is not a stopgap — it is the durable answer to scale.

Relevant bRRAIn products and services

  • POPE Graph RAG / Code Layer — AST-annotated graph that surfaces precise slices per query.
  • Code Sandbox — parses and re-parses code as commits land to keep the graph fresh.
  • MCP Gateway — the connector IDE agents use to query the graph.
  • Embedded SDK — simple retrieval API for Cursor, Claude Code, or any agent runner.
  • Handler — assembles the matched slice and ADRs into a focused prompt.
  • Book a demo — see a senior question answered from a million-line repo in seconds.

bRRAIn Team

Contributor at bRRAIn. Writing about institutional AI, knowledge management, and the future of work.

Enjoyed this post?

Subscribe for more insights on institutional AI.