Embedding and searching code
Indexing a repository by meaning — chunk granularity, cross-language indexes, call graphs and keeping the index fresh.
Searching code by meaning is not searching prose with a different corpus. Code has a grammar, so the boundaries of a useful chunk are discoverable rather than guessed. It has explicit references, so the relationship between two files is a fact you can extract rather than a similarity you have to infer. And it changes in small, precisely described increments — a commit is a machine-readable statement of exactly what is now different — which means an index over a repository can be kept correct far more cheaply than an index over a document store.
These pages work outward from those three properties. Where an embedding is the right tool they say what it retrieves and what it misses; where a parser or a dependency graph does the job better they say so and show the extraction. Most of the difficulty in practice is not model choice but bookkeeping: knowing which chunk corresponds to which bytes of which commit, and noticing when that correspondence has quietly stopped being true.
Detecting Duplicated Code With Embeddings
Which kinds of duplication an embedding actually finds, how to pick a similarity threshold, and why the pair count is the real constraint.
9 min read
Designing a Repo-Scale Code Index That Updates Incrementally
The four stores a code index needs, why content-addressing the chunk is the load-bearing decision, and what full versus incremental re-indexing actually costs.
10 min read
Building a Code Search Engine From Cross-File Dependencies
How to extract an import and reference graph from a repository, and the three specific ways search ranking can use it.
10 min read
Re-Embedding a Codebase Incrementally on Every Commit
A git hook that re-embeds only the files a commit touched, with a content-hash cache and a recorded watermark so the index can prove it is current.
10 min read
Embedding Code Across Multiple Programming Languages in One Index
Why one embedding space ranks the same algorithm differently depending on the language it is written in, and the three mitigations that work.
10 min read
Function-Level and File-Level Code Embeddings: What Each One Retrieves
What a file-level vector actually encodes, why it drags irrelevant code into a result, and when the coarse granularity is the right answer anyway.
9 min read
Semantic Diff: Comparing Two Versions of a Function by Meaning, Not Text
Why a line-based diff overstates a rename and understates a logic change, and what tree-based and embedding-based comparison each recover.
9 min read
Finding Duplicated Business Logic Across a Large Codebase
Detecting the same rule reimplemented in different services and languages, and why the hard part is deciding which findings deserve a human.
10 min read
Choosing a Code Embedding Model for Search
How to build a query set from your own repository and measure retrieval precision, and which model properties actually change the index design.
10 min read
Parsing an Abstract Syntax Tree for Code Analysis
What an AST node actually holds, a walk over a short function shown node by node, and why error recovery decides whether a parser is usable on real repositories.
10 min read
What It Costs to Embed a Large Monorepo
A full derivation of the embedding bill for a 180,000-file repository, and why the vector store rather than the model is the recurring cost.
10 min read
Extracting a Call Graph From a Codebase
A runnable tree-sitter script that builds a caller-to-callee graph from a small Python project, and an honest account of what static extraction misses.
10 min read
Embedding Jupyter Notebooks for Search
How the .ipynb format is actually structured, why cell boundaries are the wrong chunk boundaries, and what to do with outputs.
9 min read
Detecting When a Code Index Has Gone Stale
Search returns a function that no longer exists: how to confirm the index is behind, find which of the five causes it is, and verify by commit hash.
9 min read
Other topics
- LLM fundamentals & architecture
- Tokens, tokenization & context windows
- Prompt engineering
- Reasoning models & test-time compute
- Multimodal AI: vision, audio, video
- RAG & retrieval
- Embeddings & vector search
- AI agents & tool use
- Structured output & function calling
- Fine-tuning & post-training
- Local inference errors, string by string
- Running local models day to day
- Testing code that calls an LLM
- Snapshot and property testing for model output
- Regression suites for prompts
- Eval gates in CI
- Flaky tests against a model
- Determinism and the cost of testing
- Contract and streaming tests
- Testing tool calls and retrieval
- Inference, serving & latency
- Rolling out a prompt change
- Testing AI systems in practice
- Forecasting a time series
- Machine learning on tabular data
- Geospatial data and models
- Understanding audio that is not speech
- Understanding video
- Core computer vision tasks
- Machine learning on graphs
- Point clouds and 3D
- Evaluation, benchmarks & LLM-as-judge
- Sensor and IoT data
- Logs and event streams
- Models over biological sequences
- Machine learning on molecules
- Extracting invoices and purchase orders
- Receipts, statements and tax forms
- Insurance policies and contracts
- Deeds, court filings and patents
- Extracting from medical records
- Observability & LLMOps
- CVs, certificates and identity documents
- Shipping, customs and technical documents
- Meetings, email, chat and filled-in forms
- Building an extraction pipeline
- Business, property and inspection documents
- Contract clauses and insurance claims
- Regulated and compliance documents
- Consumer, travel and closing documents
- Mapping one chat API onto another
- SDK and framework migrations
- Hallucination & failure modes
- Re-embedding and model deprecation
- Cutting over between providers
- Parity gaps, shims and legacy endpoints
- Moving between model versions
- Migrating vector stores and caches
- Mapping capabilities and parameters
- Migrating pipelines and agents
- Contracts, runbooks and rollback
- Auditing a codebase before a cutover
- Compliance and fine-tune migration
- LLM cost engineering
- Routing, cost tracking and multi-tenancy
- What a migration does to your prompts
- AI security & prompt injection
- Privacy, compliance & data residency
- AI governance, policy & society
- Building reliable AI applications
- AI hardware, GPUs & compute
- Open-weight models & local inference
- AI for developers & coding agents
- AI in industry: vertical playbooks
- AGI, superintelligence, alignment & the long future
- Machine learning foundations
- NLP fundamentals & classical tasks
- Data engineering for AI
- Synthetic data & dataset curation
- AI product design & UX
- Search, ranking & recommendation
- Enterprise adoption & change management
- AI careers, skills & teams
- Reading AI research
- AI in science & discovery
- Robotics & embodied AI
- AI economics, markets & business models
- AI myths, hype & media literacy
- Context engineering
- Shipping AI features: patterns & anti-patterns
- Build it: end-to-end AI tutorials
- Python for AI: hands-on recipes
- TypeScript, React and the web
- Frameworks and SDKs
- Errors and troubleshooting
- AI facts, numbers and statistics
- The history of AI
- The maths behind AI
- Architectures beyond the transformer
- Reinforcement learning
- Diffusion and generative media
- Speech, audio and voice engineering
- Benchmarks, one at a time
- AI search visibility
- Infrastructure and operations
- Databases and storage for AI
- Knowledge graphs and structured knowledge
- Classical ML in production
- Regulation, jurisdiction by jurisdiction
- Prompt recipes and pattern library
- AI for people who do not write code
- Writing, media and creative work
- Edge and on-device AI
- Interpretability and model internals
- Field notes
- OpenAI model behaviour
- Claude model behaviour
- Gemini model behaviour
- Llama model behaviour
- Mistral model behaviour
- Qwen model behaviour
- DeepSeek model behaviour
- Cohere model behaviour
- Grok model behaviour
- Small model behaviour
- Hybrid model architectures
- Token cost by language and script
- Transliteration, romanization and script handling
- Locale-correct output
- Multilingual generation quality
- Multilingual pipelines
- The EU AI Act, article by article
- AI under the GDPR and EU data law
- US AI regulation, state and sector
- International AI governance and standards
- AI litigation and enforcement
- Running AI workloads on AWS
- Running AI workloads on Google Cloud
- Running AI workloads on Azure
- AI at the edge: Workers, Vercel and Netlify
- Serving models on Kubernetes
- Operating AI infrastructure
- Quantization formats and what they cost
- llama.cpp, flag by flag
- Ollama and the desktop local-model runtimes
- Local models on Apple Silicon
- Hardware for local inference
- Running speech and embedding models locally
- Model files, adapters and conversion
- VRAM arithmetic for local models