Repository Expert: Roadmap
The repository expert is the narrow, buildable entry point into Code Intelligence: a tool that answers questions about one codebase. Instead of grepping for hours to understand how UserAuth interacts with BillingService, you ask it.
It is repository-grounded, citation-first and read-only: it explains and points to code but does not write new code (see requirements). The stages move context selection, and later action, from the user to the software, one step at a time.
Related notes: requirements, evaluation, deployment.
Stage 0: the pipe (manual context)
Most complications in AI engineering (RAG, vector stores, agents) come from managing context automatically. The first version strips that away: you are the retriever, and the LLM is a pure reasoning engine. This verifies prompt structure and answer quality before retrieval adds its own failure modes.
cat network_handler.py | ask "Is the connect function thread-safe?"Architecture. Unix philosophy: input is a text stream (code context plus instruction), processing is one stateless LLM call, output is Markdown on stdout. Usage patterns: explicit files (-f file.py), piped stdin, or both.
Internal structure. Keep context assembly separate from inference, because retrieval will later fill the same slot.
- Ingestion: read stdin and each
-fargument; warn on missing files and continue. - Formatting: wrap each file as
<file path="...">...</file>so the model can tell instructions from target code. Retrieved chunks will be injected here later. - Inference: build the payload and call the API, with temperature 0 for analysis.
- Output: stream to stdout for perceived speed.
System prompt. Rigid, to prevent chatting: analyze code given in tags; answer strictly from the provided context; if the context is insufficient, say exactly what is missing; dense technical prose; Markdown output.
Why this prepares for RAG. It defines the RAG contract. Today the <context> block is filled by hand; later a retriever fills the same block. Contexts that produced good answers can be saved as the first golden dataset for testing the retriever (see evaluation).
Stage 1: the index
Replace the manual cat with a software component.
- Indexing loop (offline). Walk the repository; chunk by function and class rather than arbitrary text; embed chunks (a hosted embedding model or a local one); store them, at first in a local file, later in a vector database.
- Retrieval loop (run time).
ask "How does the billing service handle retries?"embeds the question, finds the top chunks related to billing and retries, and injects them into the same context block.
Retrieval quality is easy to see at this stage: bad retrieval returns login code for a billing question and the answer is invented; good retrieval returns the exact process_payment function. The hard problems appear quickly: keeping chunks current when code changes, and feeding the dependency graph into the context rather than only keyword matches.
Stage 2: code-native context
Character-count chunking produces orphaned code, so the index becomes structure-aware (Code representation):
- Representation decisions. Current state only (HEAD) or also history (Git log and blame); start with HEAD. Vector search alone, or augmented with a graph of precise relationships (“inherits from”, “calls”).
- AST chunking into classes, functions and methods, keeping the envelope (the class signature of a retrieved method).
- Metadata on every chunk: language, path, line range, parent scope.
- Dependency links between chunks for multi-hop retrieval.
- Hybrid index: dense for concepts, BM25 for exact symbols, plus a summary index of file and module summaries for architectural questions.
- Repository map: a compressed file tree with key signatures, and a symbol table mapping classes, functions and exports to paths and lines.
- Privacy rules: exclude secrets and sensitive files from indexing, aligned with
.gitignore.
Stage 3: orchestration and context expansion
Top-k is rarely enough for code (Context expansion):
- Read-only agent. Instead of being given files, the assistant decides what to read: query decomposition, a repository-walking fallback that lists and reads files when search fails, and a reference graph built while answering to pull in interfaces and base classes.
- Code-aware reranking: definitions above usages.
- Snippet formatting with line numbers, so the model can say “look at line 42”, ordered dependencies first.
Stage 4: continuous indexing
An expert that is two hours out of date is often useless during active development.
- Event-driven re-indexing from CI: on a push to
main, re-parse only changed files. - Branch-aware index, partitioned or tagged by Git reference.
- Pruning of vectors for deleted files.
- A latency monitor for time to index after a commit.
Beyond read-only
A later “active agent” gains tools and write access (running tests, proposing patches). That crosses the read-only boundary in requirements and belongs to the wider design in Hybrid architecture, with risk tiers and validation gates.
What changes compared with generic RAG
Project workstreams and artifacts
Three artifacts constrain everything else and come first:
- the behavior contract, especially no code generation and the grounding and abstention rules;
- the chunking and citation spec, because line-number integrity is the core of trust;
- the golden dataset schema and scoring spec, so that architecture choices serve evaluation rather than the reverse.