cd ~/series/demystifying-ai
Grep vs Vector Search - 93.1% vs 76.7% accuracy in agent benchmarks
EP 02 arXiv Jul 8, 2026 5 min

Is Grep All You Need?

A research team tested grep vs vector search inside AI agent loops. Grep won across every harness-model pair. But the real finding? The harness matters more than your retrieval method.

Share:
// TL;DR

Inline grep beats vector retrieval in every agent harness tested. But switching harnesses caused a bigger accuracy swing (16 points) than switching retrieval methods. The architecture wrapping your search matters more than the search itself.

# The Experiment

116 questions from LongMemEval. Four agent harnesses. Two retrieval methods. The setup nobody had tested before.

Grep (Lexical)
✓ Exact pattern matching
✓ Zero hallucinated context
✓ Instant, deterministic results
✓ No GPU, no embeddings
Vector (Semantic)
~ Approximate matching
~ Can surface paraphrases
~ Semantic range = noise in tight loops
~ Requires embeddings + index

# The Numbers

93.1%
Best: Grep + Chronos
76.7%
Same model, diff harness
16pt
Gap from harness alone

The punchline: Switching from vector to grep improved accuracy. But switching harnesses with the same retrieval method caused an even bigger swing. The architecture wrapping your search is the real variable.

# Why Grep Wins in Agent Loops

⚡

Speed

Agent loops iterate fast. Grep returns in milliseconds. No embedding computation, no index lookup, no network round-trip.

🎯

Precision

When it hits, it hits exactly. No "close but not quite" results polluting the context window with noise.

💰

Token Efficiency

Grep returns only matching lines. Vector search returns full chunks with surrounding context you don't need.

🔬

Determinism

Same query, same results, every time. No embedding drift, no index staleness, no similarity threshold tuning.

# The Real Insight: Harness > Retrieval

The paper tested four harnesses with the same model and retrieval. The harness made the difference, not grep vs vector.

Chronos
93.1%
Codex
86.2%
Gemini
82.8%
Claude
76.7%

All using the same model (Claude Opus 4.6) + inline grep. The only variable is the agent harness. Dynamic prompts, tool-calling style, and how results are presented to the model created a 16-point accuracy gap.

# The Plot Twist: File-Based Results

When results were written to files instead of inlined into the context window, vector search came back. It beat grep in 5 out of 10 configurations.

Inline Results

Results appended directly into context window.

Grep wins. Precision matters when context is crowded.

File-Based Results

Results written to files, agent reads separately.

Vector competitive. Semantic range becomes an asset when agent reasons deliberately.

# When to Use What

Tight agent loops grep

Precision + speed + token efficiency

File-based results vector

Semantic range is an asset here

Known patterns (IDs, errors) grep

Exact match = zero noise

Conceptual questions vector

Needs semantic understanding

Production system harness

16pt gap from harness > retrieval

// Bottom Line

Don't default to vector search. Inside tight agent loops, grep is faster, cheaper, and more predictable. But the real lesson: stop obsessing over retrieval and start investing in your agent harness. The prompts, tool-calling patterns, and result delivery format matter more than whether you use grep or embeddings.

Enjoyed this?

New episodes Mon, Wed, Sat.