Skip to content

Code Search

Find code by what it does.

Industry Level Difficulty Recommended mode
Software engineering 1 of 5 Beginner flat
  • Naming conventions hide functionality.
  • Large repos are hard to navigate.
  • Proprietary code can’t leave.
  1. Functions and doc sections are embedded with a code model.
  2. Questions find matching code.
  3. Runs locally or in CI.
  4. Changes indexed with upsert and delete.
Today With Code Search on SrvDB
grep for names Search by behaviour
Tribal knowledge Searchable codebase
Cloud indexing Local index
  1. Parse repo.
  2. Embed chunks.
  3. Search.
  4. Update on commit.
  5. Share the index.
  • Exact search (flat): every query compares against every stored vector, so results are exact and explainable.
  • upsert: inserts new items and replaces changed ones, so the knowledge base stays current.
  • delete and compact(): remove items immediately from search, then reclaim disk space.
  • Crash-safe persist(): after it returns, data survives a crash or power loss and reopens exactly as committed.
  • “Where do we validate tokens?”
  • Find examples of an API
  • Locate error handling
  • Find config loaders
  • Onboarding
  • Refactoring scope

embed() is your embedding model (for example sentence-transformers, or a function that turns your records into feature vectors).

import json
import srvdb
db = srvdb.Database("./code-search-db", dimension=768)
def ingest(items):
"""items: list of (id, text, metadata dict)"""
db.upsert(
ids=[i for i, _, _ in items],
embeddings=[embed(t) for _, t, _ in items],
metadatas=[json.dumps(m) for _, _, m in items],
)
db.persist() # crash-safe checkpoint
def where_is(question, k=5):
hits = db.search(embed(question), k)
return [(json.loads(db.get(i)), round(score, 3)) for i, score in hits]
  • Embedding model choice matters for code.
  1. Prototype: load a sample of real data with flat mode and check that searches return what an expert expects.
  2. Measure: if you move to an approximate mode, compare its results with flat on the same queries (recall).
  3. Pipeline: add continuous upsert and decide when to call persist().
  4. Harden: test restarts and crashes, add logging, review every output path with domain experts.
  5. Deploy: ship the database directory with the application or service.
Level Project What it does
1 · Beginner Code Search (this page) Find code by what it does.
2 · Intermediate Codebase Q&A Ask how the system works and get answers citing files.
3 · Advanced Bug Dedup Engine Links duplicate bug reports and similar stack traces.
4 · Expert Coding Agent Memory Long-term, crash-safe memory for autonomous coding agents.
5 · Frontier Air-gapped Dev Copilot A self-hosted developer assistant for isolated environments.

See also: Use cases · Live examples (coming soon)