LLM Wiki vs RAG for Internal Codebase Memory: Which Approach Should You Use?
Karpathy's wiki approach uses markdown and an index file instead of vector databases. Here's when each method works best for agent memory systems.
Two Different Bets on How Agents Should Remember Code
When you’re building an AI agent that needs to understand your internal codebase — your file structure, coding conventions, API patterns, architectural decisions — you face a fundamental design question: how does the agent store and retrieve that knowledge?
Two approaches dominate the conversation right now. The first is RAG (Retrieval-Augmented Generation), which most developers reach for by default. The second is what Andrej Karpathy has advocated for: a structured LLM wiki — flat markdown files organized around an index, no vector database required.
Both work. But they work differently, and choosing the wrong one for your use case creates real problems. This article breaks down how each approach works, where each one wins, and how to pick between them for internal codebase memory specifically.
What RAG Actually Does (And What It Doesn’t)
RAG is the dominant pattern for giving LLMs access to external knowledge. The basic flow looks like this:
- You chunk your source documents (code files, docs, READMEs) into pieces.
- You embed those chunks into a vector space using an embedding model.
- At query time, the user’s question gets embedded too, and the system retrieves the closest-matching chunks.
- Those chunks get injected into the LLM’s context window as grounding material.
It’s a clean pattern, and it scales reasonably well. Large codebases with thousands of files are tractable with RAG in ways that would be impossible if you tried to stuff everything into a context window directly.
The Real Strengths of RAG
For certain retrieval tasks, RAG is genuinely hard to beat:
- Semantic search across large corpora. If a developer asks “where do we handle payment retries?”, RAG can surface the right code even if the file isn’t named anything obvious.
- Handling volume. Codebases with tens of thousands of files aren’t a problem — you just need enough compute to embed everything.
- Works well with unstructured or mixed content. If your knowledge base mixes code, Confluence pages, Slack exports, and internal docs, RAG handles the variety.
Where RAG Breaks Down for Codebases
The problems show up fast when you look closely at how RAG performs on actual codebase queries.
Chunking destroys context. Code doesn’t split cleanly at arbitrary token boundaries. A function spans multiple chunks. The class it belongs to is in a different chunk. The interface it implements is somewhere else. When the retriever pulls a chunk, the agent often gets a fragment that’s semantically incomplete.
Cosine similarity isn’t always what you want. Semantic similarity works well for natural language. For code, you often want structural or relational knowledge: “what depends on this module?”, “what’s the project’s error handling pattern?”, “how do we structure API routes?” These questions don’t have obvious embedding neighbors.
Updates are expensive. If a developer refactors a module, you need to re-embed the affected chunks. Managing that pipeline — figuring out what changed, invalidating stale embeddings, re-indexing — adds real operational complexity.
The retrieval process is a black box. When an agent gives wrong advice about your codebase, debugging why is painful. You’re trying to reverse-engineer what chunks got retrieved and whether the embedding model found the right semantic neighborhood.
The LLM Wiki Approach: What Karpathy Proposed
Andrej Karpathy has written and spoken about a simpler alternative for agent memory: a human-readable wiki made of markdown files, organized around a central index.
The core idea is that instead of embedding your knowledge into a vector space that only machines can navigate, you structure it as a document that both humans and LLMs can read, edit, and reason about directly.
How It Works in Practice
The structure is intentionally simple:
- An index file (e.g.,
WIKI.mdorINDEX.md) acts as a table of contents. It describes what topics are covered and where to find them. - Individual markdown files cover specific topics: architecture decisions, module descriptions, coding conventions, API patterns, common pitfalls.
- The LLM reads the index first to orient itself, then reads relevant topic files as needed.
That’s it. No vector database, no embedding pipeline, no retrieval infrastructure. The agent just reads files.
This approach aligns with how Karpathy thinks about agent memory more broadly — the idea that persistent, structured, human-readable notes are more reliable than opaque retrieval systems for knowledge that evolves alongside a codebase.
Why This Works Better Than It Sounds
The wiki approach gets underestimated because it seems too simple. But a few things make it surprisingly effective:
LLMs are good at reading structured text. A well-written markdown page about your authentication module — how it works, what to watch out for, recent changes — is exactly the kind of material modern LLMs handle well. They don’t need embeddings to understand it.
The index solves the navigation problem. You don’t need semantic search if the index tells the agent where to look. “Questions about the database layer → see db-layer.md” is perfectly adequate routing for most codebase queries.
It’s inspectable and editable. When something’s wrong, you fix the wiki. When an agent gives bad advice, you update the relevant page. No pipeline to debug, no embeddings to invalidate. Any developer on the team can open the file and correct it.
Humans maintain it naturally. Engineers already write READMEs, architecture decision records (ADRs), and internal docs. A wiki is just a more structured version of what good teams do anyway.
Direct Comparison: LLM Wiki vs RAG for Codebase Memory
Here’s how the two approaches compare across the dimensions that actually matter for internal codebase use.
| Dimension | LLM Wiki | RAG |
|---|---|---|
| Setup complexity | Low — just markdown files | High — embedding pipeline, vector DB, retrieval layer |
| Maintenance overhead | Medium — requires human curation | Medium — requires re-indexing on changes |
| Scalability (file count) | Up to ~hundreds of files | Thousands to millions |
| Query type | Structured, relational, architectural | Semantic, keyword-adjacent |
| Interpretability | High — human-readable | Low — black box retrieval |
| Update process | Edit a file | Re-embed changed chunks |
| Agent context usage | Reads relevant pages on demand | Injects retrieved chunks |
| Cost | Near-zero infrastructure | Embedding + vector DB costs |
| Debugging | Easy | Difficult |
The clearest pattern: RAG wins on scale, wiki wins on clarity and control.
When to Use the LLM Wiki Approach
The wiki approach works best when:
Your codebase is small to medium-sized. If you have hundreds of files rather than tens of thousands, the index + markdown approach covers everything you need without the overhead of a retrieval pipeline.
Architecture and conventions matter more than code lookup. The wiki excels at capturing why decisions were made, what patterns the team follows, and how different pieces fit together. This is the knowledge that’s hardest to get from RAG.
You want agents and developers to share the same knowledge base. When the wiki is human-readable, it becomes a living document that the team maintains and the agent consumes. There’s no divergence between what the agent knows and what’s documented.
You’re building for a specific, well-defined codebase. Internal tools, product codebases, and proprietary systems have bounded scope. The wiki can cover them comprehensively.
Your team values interpretability. If someone needs to audit why an agent gave a specific recommendation, you can trace it directly to a wiki page. That traceability matters for compliance, onboarding, and debugging.
When RAG Is the Right Choice
RAG earns its complexity in specific scenarios:
You’re working with an enormous codebase. Open-source projects with hundreds of thousands of files, monorepos spanning dozens of teams — these genuinely require automated retrieval. Nobody’s writing and maintaining a wiki at that scale.
Users are searching, not navigating. If the primary workflow is “find code that does X” rather than “understand how system Y works,” RAG’s semantic search is a better fit.
Your knowledge base is mostly unstructured. If you’re ingesting code comments, commit messages, PR descriptions, and documentation that doesn’t follow a clean structure, embedding-based retrieval handles the variety better than a curated wiki.
The team won’t maintain a wiki. The wiki approach requires ongoing human curation. If that’s not realistic for your team’s workflow, RAG with automated re-indexing might be more robust in practice — even if it’s less interpretable.
You need to search across multiple knowledge sources. RAG can pull from code, documentation, and external references simultaneously. The wiki approach works best when it’s the single authoritative source.
Hybrid Approaches Worth Considering
In practice, the best systems often combine elements of both.
One common pattern: use a wiki for architectural knowledge (conventions, patterns, ADRs, module descriptions) and RAG for code search (finding specific implementations, locating where something is defined). The agent consults the wiki to understand context and conventions, then uses retrieval to find specific files.
Another pattern: use the wiki as a routing layer for RAG. The index file tells the agent which retrieval query to run, rather than sending every question through a single vector search. This reduces noise and improves precision.
You can also build the wiki from the codebase automatically — using an LLM to generate initial pages from READMEs, docstrings, and file structure, then having humans edit and maintain from there. This gets you most of the interpretability benefit without requiring the wiki to be written from scratch.
How MindStudio Handles Agent Memory for Codebase Workflows
Building agents that reason about internal codebases — whether using a wiki, RAG, or a hybrid — involves a lot of moving parts: reading files, calling APIs, maintaining state, and routing queries to the right knowledge source.
MindStudio’s visual workflow builder makes it practical to build these kinds of agents without setting up all the infrastructure from scratch. You can wire together a wiki-based codebase assistant — where the agent reads markdown files from a connected data source, consults an index to find relevant pages, and generates responses grounded in those pages — using a visual flow instead of hand-rolled orchestration code.
If you want RAG, MindStudio connects to vector stores and supports retrieval steps within workflows. If you want the wiki approach, you can connect to Notion, Google Drive, or any file store where your markdown lives, and build the index lookup logic visually.
The MindStudio AI agent builder supports both patterns, and lets you mix them — for example, routing architectural questions to a wiki lookup and implementation questions to a retrieval step. You’re not locked into one approach.
For teams building internal developer tools or AI assistants on top of their own codebases, MindStudio’s no-code workflow system cuts the time from idea to working agent significantly. You can try it free at mindstudio.ai.
FAQ
What is the LLM wiki approach to agent memory?
The LLM wiki approach stores knowledge as structured markdown files organized around a central index. Instead of using a vector database and embedding-based retrieval, the agent reads the index to figure out which pages are relevant, then reads those pages directly. Andrej Karpathy has advocated for this pattern as a simpler, more interpretable alternative to RAG for use cases where the knowledge base is bounded and human-maintained.
When should I use RAG instead of a wiki for codebase memory?
Use RAG when your codebase is very large (thousands to hundreds of thousands of files), when users need to search across unstructured content, or when automated re-indexing is more feasible than manual wiki curation. RAG also makes more sense when you need to combine code search with retrieval from external documentation or knowledge sources.
How does Karpathy’s wiki approach differ from traditional documentation?
Traditional documentation is written for humans and often goes stale. The LLM wiki is designed specifically to be consumed by AI agents — it’s structured for navigability (clear index, predictable page structure), kept current as part of the development workflow, and written at the right level of abstraction for an agent to use as grounding material. It’s less a reference manual and more a maintained knowledge base.
Can I combine RAG and a wiki in the same system?
Yes, and many production systems do. A common pattern is using the wiki for architectural and contextual knowledge (conventions, patterns, design decisions) and RAG for code search (finding specific implementations or file locations). The wiki can also serve as a routing layer — the agent consults the index first to decide what kind of retrieval query to run.
What are the main downsides of the wiki approach?
The wiki requires ongoing human curation. If your team doesn’t maintain it, it goes stale fast — and a stale wiki is worse than no wiki, because the agent will confidently give outdated answers. The approach also doesn’t scale well to very large codebases. And it requires someone to initially structure the knowledge into pages, which takes real effort.
How do I get started with a codebase wiki for an AI agent?
Start with a single index file that maps major areas of your codebase to short descriptions. Then create one page per major module or subsystem, covering what it does, how it’s structured, common pitfalls, and recent changes. Let an LLM generate first drafts from your existing READMEs and docstrings, then have developers review and edit. Keep the pages short and focused — one concept per page is better than long, sprawling documents.
Key Takeaways
- RAG excels at scale and semantic search but struggles with code chunking, structural queries, and interpretability.
- The LLM wiki approach — markdown files plus an index — works better for bounded codebases where architectural knowledge matters more than raw code search.
- Karpathy’s wiki approach prioritizes human readability and editability over retrieval sophistication, making debugging and maintenance much simpler.
- Hybrid systems often make the most sense in practice: wiki for context and conventions, RAG for code search.
- The right choice depends on your codebase size, team maintenance capacity, and the types of questions your agents need to answer.
- Tools like MindStudio let you implement either approach — or a combination — without building the retrieval infrastructure from scratch.