Semantic Search
Search your code by meaning, not exact text. Powers context retrieval in both Ask and Agent modes. Agent mode can call search_vector_db explicitly.
Related: Code indexing covers the indexer side; this page covers the query side.
Quick start
Section titled “Quick start”CodeBuddy: Index Workspace for Semantic SearchOnce indexed, both modes auto-retrieve relevant code. Files matching .codebuddyignore are excluded — run CodeBuddy: Init .codebuddyignore for a starter file.
Query pipeline
Section titled “Query pipeline”
graph TB
Q["Query"] --> V["Vector search<br/>Pre-normalized query, cosine similarity<br/>Top candidates from up to 5000 rows"]
Q --> K["FTS4 keyword search<br/>Tokenized query, BM25 via matchinfo"]
V --> SF["Score fusion<br/>vector × 0.7 + text × 0.3"]
K --> SF
SF --> TD["Temporal decay (optional)<br/>score × e^(−λ × age)"]
TD --> MMR["MMR diversity re-rank (optional)<br/>Jaccard similarity"]
MMR --> TK["Top-K (default 10)"]
Fallback ladder — if hybrid fails or returns nothing:
- Hybrid (vector + FTS4)
- FTS4 keyword only
- Legacy vector (simpler cosine scan)
- Legacy keyword (basic text matching)
- Common files (README, package.json, entry points)
Embedding providers
Section titled “Embedding providers”| Provider | Setting value | Model / endpoint |
|---|---|---|
| Gemini (default) | "gemini" | text-embedding-004 |
| OpenAI | "openai" | text-embedding-3-small |
| Local | "local" | /embeddings on local server (e.g. nomic-embed-text) |
Set via codebuddy.vectorDb.embeddingModel. Local embedding needs a model that speaks the OpenAI embeddings API.
Perf notes
Section titled “Perf notes”- Pre-normalized query vectors + aligned
Float32Arrayfor fast cosine similarity. - Time-budgeted vector scans — yields every 8 ms to keep UI responsive.
- Prepared statements — FTS4 uses cached prepared statements with
reset()reuse. - Workspace switch safety — mid-scan workspace switch is detected and aborted cleanly.
- Background reindex — file changes trigger re-index after the debounce delay via worker threads.
Settings
Section titled “Settings”Full list in Settings Reference. Key knobs:
Vector DB:
| Setting | Default | Purpose |
|---|---|---|
codebuddy.vectorDb.enabled | true | Master toggle |
codebuddy.vectorDb.embeddingModel | "gemini" | gemini / openai / local |
codebuddy.vectorDb.maxTokens | 6000 | Max tokens per chunk |
codebuddy.vectorDb.searchResultLimit | 8 | Top-K for results |
codebuddy.vectorDb.performanceMode | "balanced" | balanced / performance / memory |
codebuddy.vectorDb.fallbackToKeywordSearch | true | Keyword fallback when vectors fail |
codebuddy.vectorDb.cacheEnabled | true | Cache search results |
Hybrid search tuning:
| Setting | Default | Purpose |
|---|---|---|
codebuddy.hybridSearch.vectorWeight | 0.7 | Semantic weight (0–1) |
codebuddy.hybridSearch.textWeight | 0.3 | Keyword weight (0–1) |
codebuddy.hybridSearch.topK | 10 | Max results (1–50) |
codebuddy.hybridSearch.mmr.enabled | false | Diversity re-ranking |
codebuddy.hybridSearch.mmr.lambda | 0.7 | 0 = max diversity, 1 = max relevance |
codebuddy.hybridSearch.temporalDecay.enabled | false | Recency bias |
codebuddy.hybridSearch.temporalDecay.halfLifeDays | 30 | Score half-life (days, 1–365) |
Weights auto-normalize to sum to 1.0.
Context integration
Section titled “Context integration”- Ask mode —
ContextEnhancementServiceretrieves relevant chunks, adds them to the system prompt alongside@-mentions. - Agent mode — the LLM can call
search_vector_dbexplicitly; the system prompt is also enriched with auto-retrieved context before reasoning starts.
Related
Section titled “Related”- Code indexing — how content gets into the index
- Context system — where search fits in the per-turn budget
- Memory — separate system for user-explicit facts