Semantic Code Search
Start with repository search, symbol indexes, and targeted reads. An index is justified when the corpus is too large, natural-language concepts do not map to identifiers, or repeated discovery cost exceeds indexing cost.
Requirements
- Define queries and relevance judgments before choosing a backend.
- Inventory languages, generated/vendor/secrets paths, repository size, update rate, data boundary, hardware, and latency target.
- Chunk on symbols and syntax boundaries when a verified parser exists; preserve file path, symbol, line range, language, commit/hash, and parent context.
- Use lexical/BM25 and exact identifier matching as a strong baseline. Add embeddings only when evaluation shows a measurable recall gain.
- Prefer local processing for private code. Any external embedding/vector/reranking service requires explicit authorization, retention/privacy review, and secret filtering.
- Keep embedding model/backend configurable and record its exact version, dimensions, tokenizer, normalization, and index schema. Do not choose a provider/model automatically.
- Deduplicate chunks, cap generated/minified content, and exclude secrets before indexing.
- Incrementally update by content hash; delete stale chunks when files disappear or symbols move.
Retrieval pipeline
Normalize the query without destroying identifiers, retrieve lexical and semantic candidates, fuse ranks, rerank only a small bounded set, diversify near-duplicates, and return source-linked snippets. Never answer from vector text without reopening the current source file; the index may be stale.
Evaluation
Create a labeled set of realistic "where/how/what depends on" questions. Measure recall@k, MRR/nDCG, exact-symbol recall, stale-result rate, latency, index size, build time, and privacy failures. Compare lexical-only, semantic-only, and hybrid. Test renamed symbols, cross-language calls, common words, generated code, and deleted files.
Completion gate
- every result links to a current path/symbol/range and commit/hash;
- direct search fallback remains available;
- private code stayed inside the approved boundary;
- index/update/delete behavior was tested;
- chosen complexity beats the baseline on the evaluation set;
- setup, dependencies, rebuild, and removal steps are documented.
1---2name: code-semantic-search3description: Design, evaluate, or operate privacy-aware semantic and hybrid search over a large codebase using structural chunks, lexical retrieval, optional embeddings.4license: MIT5---67# Semantic Code Search89Start with repository search, symbol indexes, and targeted reads. An index is justified when the corpus is too large, natural-language concepts do not map to identifiers, or repeated discovery cost exceeds indexing cost.1011## Requirements12131. Define queries and relevance judgments before choosing a backend.142. Inventory languages, generated/vendor/secrets paths, repository size, update rate, data boundary, hardware, and latency target.153. Chunk on symbols and syntax boundaries when a verified parser exists; preserve file path, symbol, line range, language, commit/hash, and parent context.164. Use lexical/BM25 and exact identifier matching as a strong baseline. Add embeddings only when evaluation shows a measurable recall gain.175. Prefer local processing for private code. Any external embedding/vector/reranking service requires explicit authorization, retention/privacy review, and secret filtering.186. Keep embedding model/backend configurable and record its exact version, dimensions, tokenizer, normalization, and index schema. Do not choose a provider/model automatically.197. Deduplicate chunks, cap generated/minified content, and exclude secrets before indexing.208. Incrementally update by content hash; delete stale chunks when files disappear or symbols move.2122## Retrieval pipeline2324Normalize the query without destroying identifiers, retrieve lexical and semantic candidates, fuse ranks, rerank only a small bounded set, diversify near-duplicates, and return source-linked snippets. Never answer from vector text without reopening the current source file; the index may be stale.2526## Evaluation2728Create a labeled set of realistic "where/how/what depends on" questions. Measure recall@k, MRR/nDCG, exact-symbol recall, stale-result rate, latency, index size, build time, and privacy failures. Compare lexical-only, semantic-only, and hybrid. Test renamed symbols, cross-language calls, common words, generated code, and deleted files.2930## Completion gate3132- every result links to a current path/symbol/range and commit/hash;33- direct search fallback remains available;34- private code stayed inside the approved boundary;35- index/update/delete behavior was tested;36- chosen complexity beats the baseline on the evaluation set;37- setup, dependencies, rebuild, and removal steps are documented.