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

$ grep -rni "chunk" docs/reference/
docs/reference/polaris-indexing.md
docs/reference/README.md
(4 matches across 2 files)
$ cat docs/reference/polaris-indexing.md
$ cat docs/reference/README.md
Avg / search: 15,222 tokens

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 search "how does chunking work"
components.md §HowItWorks · 1.00
Avg / search: 700 tokens (21.8× cheaper)

Polaris returns a ranked section, not a whole file. The agent gets exactly the paragraph about chunking, nothing else.

How they work

Grep + ReadPolaris
MatchingExact substringBM25 keywords + vector embeddings
ReturnsEntire filesRanked sections (~200–450 tokens each)
SynonymsNo, "embed" won't find "vectorize"Yes, embeddings capture meaning
RankingNone (file order)RRF fusion + heading boost + MMR diversity
Cloud requiredNoNo, ONNX model runs locally
API keysNoneNone

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 7

Query: "hybrid ranking fusion"

grep + read 10,706 tok
polaris 487 tok
22.0×

polaris-ingest

25 searches · since May 8

Query: "pdf heading detection"

grep + read 15,440 tok
polaris 492 tok
31.3×

polaris-site

23 searches · since May 20

Query: "how does chunking work"

grep + read 15,222 tok
polaris 700 tok
21.8×

See the interactive step-by-step demo on the home page →

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