Grep vs Semantic Search for Coding Agents
When your AI coding agent needs to answer a question about your documentation, it has two options: grep through files and read the matches, or call a semantic search tool. The difference in token cost is dramatic — and we measured it.
A real query, two approaches
We asked an agent: "how does chunking work?" against the Polaris documentation (11 markdown files, 206 indexed chunks).
Grep + Read
docs/polaris-indexing.md:18: chunk_markdown() in indexer.rs...
(16 more matches across 8 files)
The agent reads two entire files. Most of the content is irrelevant — the answer was in one section of one file.
Polaris Semantic Search
→ architecture.md §indexing · score 0.62
Polaris returns two ranked sections, not files. The agent gets exactly the paragraphs about chunking — nothing else.
How they work
| Grep + Read | Polaris | |
|---|---|---|
| Matching | Exact substring | BM25 keywords + vector embeddings |
| Returns | Entire files | Ranked sections (~200–450 tokens each) |
| Synonyms | No — "embed" won't find "vectorize" | Yes — embeddings capture meaning |
| Ranking | None (file order) | RRF fusion + heading boost + MMR diversity |
| Cloud required | No | No — ONNX model runs locally |
| API keys | None | None |
Measured across three real projects
Each row is a real query run against a real codebase. The grep column counts
the tokens the agent actually consumed (grep output + file reads). The Polaris
column is the MCP search response with top_k=2.
Polaris docs
11 docs · 206 chunksQuery: "how does chunking work?"
Mid-size OSS library
~80 docs · ~2k chunksQuery: "how do I add a custom transport?"
React documentation
hundreds of pages · ~10k chunksQuery: "useEffect cleanup with abort signal"
Why this matters for your token bill
A typical coding session involves 30+ documentation lookups. If each grep-and-read costs ~12,000 tokens, that's 360,000 tokens per session just for context-gathering — before the agent even starts reasoning.
With Polaris at ~300 tokens per lookup, the same 30 queries cost 9,000 tokens. That's a 40× reduction in the tokens your agent burns before it even starts thinking.
At current API pricing, this translates to $120–$370 saved per developer per month, depending on codebase size and query volume.
Ready to switch from grep to semantic search?
Install Polaris