What is a codebase knowledge graph?
How a local graph of code, docs, and work gives coding agents memory that dumping files into context cannot.
By Trellis

Coding agents are good at writing patches once they understand the problem. The hard part is almost never syntax — it is orientation. Where does this symbol live? Which service owns the side effect? What decision did the team already make in that ADR last spring? Agents without durable memory re-discover the same facts every session, burn tokens on the wrong files, and confidently invent structure that is almost right.
A codebase knowledge graph is a structured map of a software system and the work around it: files, symbols, documents, tickets, pull requests, and the relationships between them. It is not a chat log. It is not a bigger context window. It is memory you can query, update, and keep on the machine that already has the code.
The problem with “just put more files in context”
The default workflow for many agent setups is a variant of stuffing: open a folder, paste paths, hope the model notices the right imports. When that fails, people reach for retrieval — embeddings over a file tree — and ask for “relevant” chunks.

Both approaches share the same blind spot. Code is not a bag of documents. A function call is an edge. A re-export is an edge. A ticket that closed when a PR merged is an edge. A comment that says “see ADR-014” is an edge that search often misses because the words never co-occur in the same file.
Context stuffing also does not scale with honesty. You can fit less of a real monorepo than product demos suggest. Even when you fit more, the model still has to rebuild the graph in working memory every time: which package depends on which, which types are public API, which tests guard which invariants. That reconstruction is expensive, lossy, and non-deterministic across runs.
Search helps find text. It does not, by itself, answer multi-hop questions like “which open tickets touch modules that import this broken util?” Those answers live in joins across code and work systems.
What a knowledge graph actually stores
Think of three layers that most teams already have, but rarely connect for agents:
- Code structure — repositories, packages, files, symbols, imports, call sites, tests, generated stubs.
- Narrative structure — READMEs, ADRs, runbooks, design docs, inline comments that encode intent.
- Work structure — issues, PRs, review comments, deploy notes, ownership, and “who last changed this.”
A codebase knowledge graph materializes those entities as nodes and the relationships as typed edges: IMPORTS, DEFINES, DOCUMENTS, IMPLEMENTS, MENTIONS, OWNED_BY, MERGED_IN, and so on. The exact schema matters less than the commitment: facts are first-class, not buried only in prose the model might re-read.
That structure unlocks queries agents cannot reliably do with grep:
- “Show every public export of this package that has no test reference.”
- “What docs mention the payment webhook, and which services still call the old handler?”
- “For this failing CI job, which recent PRs touched the same symbols?”
You can still use full-text or vector search on top of the graph. The graph’s job is orientation and join, not synonym matching.
How this differs from an index or a vector store
An index answers “which chunks look like this string or embedding?” A knowledge graph answers “how are these things connected?” Those are complementary, not substitutes.
| Approach | Strength | Weakness for agents | | --- | --- | --- | | Context dump | Simple | Loses structure; size-capped; rebuilt every turn | | Search / embeddings | Finds similar text | Weak multi-hop joins; poor typed relationships | | Knowledge graph | Explicit entities & edges | Needs extraction and maintenance |
The practical win for coding agents is stable intermediate memory. Instead of re-deriving “auth middleware lives here and is referenced from these three gateways” from raw files every session, the agent can load a compact neighborhood of the graph, then open only the files that matter.
Graphs also age better under change. When a file moves, you update nodes and edges. When a PR merges, you attach work history to the symbols it touched. Chat transcripts do not do that unless someone curates them by hand.
Local-first is not a slogan here
Codebases often contain secrets, customer logic, and unreleased product shape. Shipping the whole tree to a remote “memory service” is a non-starter for many teams — and even when policy allows it, latency and trust still matter.
A local knowledge graph keeps the authoritative map next to the repo: built by connectors that read git, the filesystem, and optional work trackers; queried by the agent runtime over a controlled interface (for example MCP tools). Remote models can still write code; they do not need permanent custody of the entire organizational memory.
Local-first also means the graph can include private edges: the half-finished refactor branch, the draft ADR, the incident note that never left the team channel export. Those are exactly the facts that make an agent useful and exactly the ones you do not want in a shared multi-tenant index by default.
What “good” looks like for agent workflows
A useful graph is not a perfect ontology of computer science. It is current enough, typed enough, and small enough to steer tool use:
- Current enough — rebuilt or incremented on pull, commit, or a short schedule so agents are not arguing with last month’s tree.
- Typed enough — agents can ask for
symbolvsdocumentvsticketwithout parsing free-form blobs. - Neighborhood-first — retrieval returns a subgraph around a seed (file, error stack, issue id), not the entire company history.
In a typical session, the agent might: (1) parse an error or user ask into seeds, (2) expand a few hops in the graph, (3) open a handful of files, (4) propose a change, (5) write new edges when it learns something durable (“this flag is deprecated; use X”). Step five is where graphs outrun pure RAG: the next session starts wiser without pasting the old chat.
Failure modes worth naming
Graphs are not magic. Bad extraction creates confident wrong edges. Over-eager “AI summarization” into the graph can freeze hallucinations as facts. Giant untyped blobs reintroduce the original problem under a fancier name.
Guardrails that work in practice:
- Prefer deterministic extractors for imports, symbols, and PR file lists; use models for softer links (doc mentions, intent) with lower confidence or review.
- Keep provenance — every node or edge should say which file, commit, or ticket it came from.
- Separate observed structure from inferred advice so agents (and humans) know what was measured vs guessed.
- Treat the graph as memory, not authority — the repo and CI remain the source of truth when they disagree.
Why this matters now
Agent tooling has made it cheap to attempt large edits. It has not made it cheap to understand large systems. Teams that only invest in bigger windows will keep paying for re-orientation. Teams that invest in a maintainable map — code plus docs plus work, preferably local — give every agent the same advantage a senior engineer has after a year on the codebase: not photographic memory of every line, but a reliable sense of what connects to what.
A codebase knowledge graph is that map, made explicit for machines as well as people. Dumping files into context is reading with amnesia. Querying a graph is working with memory.

If you are evaluating agent memory for a real monorepo, start with one painful workflow — onboarding a new service, triaging a flaky integration test, or answering “what still uses this endpoint?” — and ask whether your current stack can answer it with joins, or only with hope and a larger prompt.
Want this for your team?
Trellis builds local-first knowledge graphs for coding agents, and the Free plan runs on your own machine.