Zoekt: Why Trigram Search Beats Vector Search for Code
Zoekt uses trigrams to index and search code at speeds that embarrass most vector-based tools. For teams that need fast, accurate code search without GPU costs, this is the right approach.
- Zoekt is an open-source trigram-based code search engine from Sourcegraph that indexes repositories for sub-second search.
- Trigram search is significantly faster and cheaper than vector embedding search for exact-match and regex queries.
- Developers can integrate Zoekt into local development environments and CI pipelines to reduce code navigation time.
- The tradeoff is lower semantic understanding, but for most code search tasks, exact matches are what developers need.
What Makes Trigram Search Faster Than Vector Search for Code?
According to Sourcegraph's documentation for Zoekt, trigram indexing works by breaking every file into overlapping three-character sequences (trigrams) and building an inverted index mapping each trigram to its file locations. On query, the engine finds the intersection of trigrams from the search term—a set operation that modern CPUs handle in microseconds. In contrast, vector embedding search requires converting queries into dense vectors via a neural network, then performing approximate nearest neighbor search across potentially millions of vectors. The Hacker News discussion around Zoekt's December 2025 resurgence highlighted benchmarks showing trigram search completing in under 100ms for repositories with over 100,000 files, while vector search often takes 500ms to 2 seconds for comparable tasks.
This speed difference matters because developers perform code search dozens of times per day. A 2024 GitHub survey found that developers spend 30% of their time navigating code—reducing that by even 20% through faster search translates to significant productivity gains.
Who Actually Benefits From Using Zoekt Today?
Individual developers and small-to-medium engineering teams benefit most immediately. Zoekt can be run locally via a command-line interface or as a service with minimal setup—no GPU required. According to a Hacker News comment from a Sourcegraph engineer, the project has been used internally at Sourcegraph for years and is now being packaged for easier standalone use. Teams that use monorepos or large codebases with thousands of files will see the biggest wins. Conversely, teams relying on semantic code search (e.g., finding functions by their purpose rather than name) may still need vector embeddings, but they should layer Zoekt as a first-pass filter.

What Are the Operational Tradeoffs of Trigram Search?
The primary tradeoff is that trigram search excels at exact match and regex queries but cannot understand synonyms or conceptual similarity. If a developer searches for "user authentication" and the codebase uses "login verification," trigram search will miss it. Sourcegraph's Zoekt documentation acknowledges this limitation and recommends combining trigram search with other techniques for semantic queries. However, for the vast majority of code search tasks—finding variable definitions, function calls, error messages—exact match is exactly what developers want. The operational cost is also lower: Zoekt's index is typically 10-20% of the raw source size, whereas vector indexes can be 2-5x larger.
| Feature | Zoekt (Trigram) | Vector Search |
|---|---|---|
| Query Speed (100k files) | <100ms | 500ms-2s |
| Hardware Requirements | CPU only | GPU recommended |
| Index Size | 10-20% of source | 200-500% of source |
| Semantic Understanding | None | High |
| Exact Match Accuracy | 100% | ~95% (ANN errors) |
| Open Source | Yes | Varies |
| Verdict | Best for exact-match code search | Best for semantic search |
How Should Teams Adopt Zoekt in Their Workflow?
Teams should start by integrating Zoekt into their local development environment. The project provides a simple command-line tool that indexes a local repository and starts a local HTTP server for querying. According to the Zoekt README, setup takes under five minutes. For CI pipelines, teams can run Zoekt as a sidecar service that indexes the repository on each commit, enabling fast code search for code reviews and automated refactoring. The key adoption guidance is to treat Zoekt as a complement to, not a replacement for, existing search tools. Use Zoekt for fast exact matches and fall back to vector search or grep for semantic queries.
My thesis is that trigram-based code search is the unsung hero of developer tooling, and Zoekt's resurgence proves that simple algorithms still beat complex ML for most practical tasks. In the short term, teams that adopt Zoekt will see immediate speed gains in code navigation, especially for large monorepos. In the long term, I expect Sourcegraph to integrate Zoekt more deeply into its commercial products, potentially as a default search backend. The losers here are vendors selling over-engineered vector search solutions for code—they will need to demonstrate clear semantic advantages to justify their cost. My concrete prediction is that by Q2 2026, at least three major code hosting platforms will adopt trigram-based search as their primary exact-match engine, citing Zoekt's performance.
Predictions
- By Q2 2026, GitHub will integrate trigram-based search (possibly via Zoekt) as an optional backend for large repositories.
- By Q4 2026, at least two AI code search startups will pivot to hybrid trigram+vector architectures after failing to justify GPU costs for exact-match queries.
- Sourcegraph will release Zoekt 2.0 with native support for semantic trigram ranking by Q3 2026, combining speed with basic similarity.
- 2016Zoekt initial release
Sourcegraph open-sources Zoekt, a trigram-based code search engine.
- 2025-12-05Zoekt resurfaces on Hacker News
Discussion of Zoekt's performance benchmarks leads to renewed interest in trigram search.
- Q2 2026 (predicted)GitHub integration
Prediction: GitHub will adopt trigram search as an optional backend for large repositories.
Article Summary
- Trigram search is the fastest and cheapest way to find exact code matches at scale, outperforming vector search for most developer tasks.
- Zoekt is production-ready today and can be integrated into local and CI workflows in minutes.
- The tradeoff of no semantic understanding is acceptable for the majority of code search use cases.
- Adoption of trigram search will increase as teams realize they don't need GPUs for basic code navigation.
Source and attribution
Hacker News
Fast trigram based code search
Discussion
Add a comment