Skip to main content
Code Guide
T14 Intermediate Technical

Grepai — Semantic Search

Finding code by intent, not by regex

PDF
← All cards

Principle: search by intent

Native Grep (ripgrep) is ideal when you know the exact text to find. Grepai takes over when you are looking for “the code that handles X” without knowing the exact function or variable names. It relies on local embeddings via Ollama and the nomic-embed-text model, which guarantees full privacy: no data leaves the machine.

Token savings: ~4K tokens with grepai vs ~15K doing raw grep + reading full files.

The 4 main tools

grepai_search: search by natural language description. Short queries (1-3 keywords) yield better results than long phrases.

grepai_search("payment flow")
grepai_search("JWT validation")
grepai_search("rate limiting middleware")

grepai_trace_callers: finds all functions that call a given symbol.

grepai_trace_callees: lists what a function calls internally.

grepai_index_status: checks that the index is up to date before running searches.

Call graph in practice

The most powerful use case for grepai is dependency analysis. Before refactoring a function, knowing who calls it prevents silent regressions.

# Who calls validateJWT?
grepai_trace_callers("validateJWT")
→ ApiGateway, AdminPanel, UserController
# What does validateJWT do internally?
grepai_trace_callees("validateJWT")
→ decodeToken, checkExpiry, verifySignature

Recommended depth: 2 by default, 3 at most for complex analyses.

Grepai vs native Grep

SituationRecommended tool
Exact pattern known ("authenticate")Native Grep (~20ms)
Search by concept or intentGrepai (~500ms)
Call graph analysisGrepai (trace_callers)
Multi-file refactoringGrepai + Serena
Advanced regex on AST structureast-grep

Simple rule: if you can write the regex, use Grep. Otherwise, grepai.

Setup

Terminal window
# Install grepai
curl -sSL https://raw.githubusercontent.com/yoanbernabeu/grepai/main/install.sh | sh
# Initialize in the project (choose: ollama, nomic-embed-text)
grepai init
# Check status
grepai status

Prerequisites: Ollama installed with the nomic-embed-text model available. If “connection refused” error: brew services start ollama.

Best practices

Always call grepai_index_status at the start of a session if the codebase has changed since the last indexing. Limit results to 5 by default and increase only if the first results are not relevant. Grepai discovers files, then native Grep refines with a precise regex: both tools complement each other naturally.

Enter your email to read the full card and get the complete PDF bundle.

All content is free and open-source. We just ask for your email.

PDF: