Summary
A ranked repository map is a technique for providing LLMs with a compact, context-relevant overview of a codebase. It works by extracting code symbols via tree-sitter, building a call/reference graph, applying a graph-centrality algorithm (e.g., PageRank) to rank symbols by importance, and then selecting the top-ranked symbols to fit within a token budget (typically ~1024 tokens). This ensures the LLM receives the most relevant structural context without exceeding context limits.
Key Points
- Used by Aider to provide high-quality context for code generation and modification.
- Combines structural parsing (tree-sitter) with graph analysis (PageRank) to identify the most referenced symbols.
- The ranking is token-budget-aware, truncating less important symbols when the prompt is near the limit.
- Implementation requires symbol extraction, graph construction, centrality computation, and budget-aware selection.
- Provides a significant improvement over simple truncation or limit-based approaches.
Concepts
- Tree-sitter: A parsing library used to extract code symbols (functions, classes, variables) with structural accuracy.
- Call/reference graph: A graph where nodes are symbols and edges represent calls or references between them.
- PageRank: A graph centrality algorithm that measures the importance of a node based on the number and importance of incoming edges.
- Token budget: The maximum number of tokens allowed for the repository map in the LLM prompt.
- Symbol extraction: The process of identifying named code elements from source files.