How codebase-index finds and ranks relevant code for a query.
The retrieval pipeline combines multiple search strategies into a single ranked result set.
User query
↓
Intent detection (keyword / symbol / impact / general)
↓
┌─────────────────────────────────────────┐
│ Parallel Retrievers │
├─────────────────────────────────────────┤
│ 1. Exact symbol match │
│ 2. Path-based search │
│ 3. SQLite FTS5 lexical search │
│ 4. Vector search (optional embeddings) │
│ 5. Graph expansion (from seed results) │
└─────────────────────────────────────────┘
↓
Reciprocal Rank Fusion (RRF)
↓
Reranking (boosts for symbol match, recency, file type)
↓
Token budget enforcement
↓
Ranked retrieval packet with confidence score
Trigger: Query matches a known symbol name exactly or with minor variation.
Process:
- Look up the symbol in the
symbolstable - Return the definition file and line range
- Include all reference locations from the
edgestable
Score boost: Highest priority — exact symbol matches are ranked first.
Trigger: Query contains file path fragments or recognizable path patterns.
Process:
- Match query terms against file paths in the
filestable - Use substring matching with path segment awareness
Score boost: Moderate — path matches indicate the user knows where to look.
Trigger: General keyword queries.
Process:
- Build an FTS5 query from the user's text
- Tokenize: split
snake_case, expandcamelCaseat query time - Search the
fts_chunksvirtual table - Return matching chunks with BM25-style scores
Score: Based on FTS5 rank — higher for more term matches and rarer terms.
Trigger: Enabled when embeddings.backend is not "noop".
Process:
- Embed the query using the configured backend
- Search
vec_chunksfor nearest neighbors - Return chunks with cosine similarity scores
Score: Cosine similarity (0.0 to 1.0).
Indexing note: chunk embeddings are reused across rebuilds via a content-addressed
vec_cache(keyed by model + content SHA-256), so only new or changed chunks are re-embedded. See DATABASE_SCHEMA.md and SCHEMA.md for details.
Trigger: After initial results are found.
Process:
- For each seed result, traverse the dependency/call graph
- Find related files: callers, callees, imports, inheritors
- Add related files with a decay factor (distance from seed)
Score: Decreases with graph distance — direct connections score higher.
Combines results from multiple retrievers:
RRF_score(d) = Σ (1 / (k + rank_r(d)))
Where:
kis a constant (default 60)rank_r(d)is the rank of documentdin retrieverr- Sum is over all retrievers that returned
d
This ensures documents that appear in multiple retrievers rank higher.
After fusion, apply additional boosts:
| Factor | Boost | Rationale |
|---|---|---|
| Exact symbol match | +0.3 | User named a specific symbol |
| File type relevance | +0.1 | .ts for TypeScript queries, etc. |
| Recency | +0.05 | Recently modified files may be more relevant |
| File size | -0.05 per 10KB | Prefer focused files over large ones |
The final confidence score (0.0 to 1.0) determines how Claude should proceed:
| Confidence | Meaning | Action |
|---|---|---|
| 0.8 - 1.0 | High | Read recommended ranges and answer directly |
| 0.5 - 0.8 | Medium | Read ranges; optionally confirm with one Grep |
| 0.0 - 0.5 | Low | Use fallback suggestions (ripgrep, Glob) |
The output is capped at a configurable token budget:
- Results are sorted by final score
- Snippets are included until the budget is reached
- Remaining results are listed without snippets
- The
recommended_readsfield contains only the most critical line ranges
Default budget: 2000 tokens (configurable in .codeindex.json).
When confidence is low, the pipeline generates fallback strategies:
- ripgrep patterns: Extracted keywords from the query, formatted for
rg - likely paths: Common directories to search based on query terms
- broaden query: Suggestions for rewording the query
These are included in the response so Claude can fall back gracefully.