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.
One question, two approaches
We asked an agent: "how does chunking work?" against this site's own documentation. The token totals below are the measured average across all 23 searches in that project.
Grep + Read
docs/reference/README.md
(4 matches across 2 files)
The agent reads whole files when the answer lives in one section of one of them. That is what the averages above are measuring.
Polaris Semantic Search
Polaris returns a ranked section, not a whole file. The agent gets exactly the paragraph 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 the measured average across every search in that project. The
grep column estimates the tokens an equivalent grep-and-read loop would
have consumed; the Polaris column is what the MCP search response actually delivered.
polaris
62 searches · since May 7Query: "hybrid ranking fusion"
polaris-ingest
25 searches · since May 8Query: "pdf heading detection"
polaris-site
23 searches · since May 20Query: "how does chunking work"
What that adds up to
Across those three projects over roughly three months (110 documentation searches), Polaris delivered 58,594 tokens where grep-and-read would have consumed 1,399,878.
At $5 per million input tokens (the Opus 4.7 / 4.8 / 5 input rate), that is $6.71 saved, about $0.06 per search. Measured totals, not projections.
Run polaris savings in your own repo
to get yours.
Ready to switch from grep to semantic search?
Install Polaris