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”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.
Only Gemini, OpenAI, and Local can produce embeddings — a chat provider isn’t necessarily an embedding provider (Anthropic, Groq, DeepSeek, xAI, Qwen, GLM have no embeddings API). If your embedding backend can’t embed, search degrades to keyword-only FTS4 rather than failing. Pick a capable
embeddingModelfor true vector search.
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 calls
search_vector_dbexplicitly. There’s also an opt-in first-turn grounding injection (codebuddy.agent.groundingContext, default OFF) that seeds the agent with keyword-retrieved code before it starts reasoning — it’s first-turn-only and embedding-free, not an always-on enrichment. See Context system → First-turn agent grounding.
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