terraphim_grep
Intelligent hybrid grep with RLM (Retrieval-Language Model) fallback and knowledge-graph curation.
Overview
terraphim_grep is a search crate that combines local code search, knowledge-graph (KG) concept boosting, and optional LLM synthesis into a single pipeline. It runs code retrieval and KG concept lookup in parallel, applies KG-aware boosting so chunks matching your thesaurus rank above generic matches, and falls back to an LLM only when local sufficiency is below threshold.
Features
- Hybrid Search: Parallel execution of code search and KG concept lookup
- KG-Aware Boosting: Chunks matching thesaurus concepts rank higher than generic matches
- Sufficiency Judging: Heuristic-based decision on whether results are sufficient or need LLM synthesis
- RLM Fallback: Graceful degradation to search-only mode when no LLM is configured
- KG Curation: Optional extraction and indexing of new concepts from LLM responses
- CLI Binary: Standalone
terraphim-grepbinary with JSON output support
Installation
Add to your Cargo.toml:
[]
= { = "../terraphim_grep" }
Feature Flags
| Feature | Default | Description |
|---|---|---|
llm |
Yes | Enable LLM integration via terraphim_service |
code-search |
Yes | Enable fff-search code retrieval backend |
openrouter |
No | Enable OpenRouter provider for live LLM tests |
Note:
code-searchis enabled by default so the tool greps file contents out of the box. If you build with--no-default-featuresand omitcode-search, file-content search is disabled and every query returns no matches; the binary logs a warning on the first search to make this obvious.
Usage
Library
use Arc;
use ;
use Thesaurus;
async
CLI
# Basic search
# Search with context lines and JSON output
# Force LLM synthesis
# Search specific paths
Architecture
Query
│
▼
┌──────────────────┐
│ HybridSearcher │──→ Code search (fff-search) ──┐
│ (parallel) │──→ KG concept lookup ────────┤
└──────────────────┘ │
│ ▼
▼ ┌──────────────────┐
┌──────────────────┐ │ RetrievedChunk │
│ SufficiencyJudge │◄─────────────────│ + KgConcept │
│ (heuristics) │ └──────────────────┘
└──────────────────┘
│
├── Sufficient ──→ Return chunks (SearchOnly)
├── NeedsSynthesis ──→ RLM fallback (if LLM configured)
├── NeedsExpansion ──→ RLM fallback with additional chunks
└── Insufficient ──→ Preserve retrieved chunks + KG metadata (RlmInsufficient)
Key Types
TerraphimGrep— Main entry point combining search, sufficiency judging, and optional LLMHybridSearcher— Parallel code search and KG concept lookup with boostingSufficiencyJudge— Heuristic thresholds for deciding if results need LLM synthesisGrepOptions— Query configuration (haystack, context lines, max results, force RLM)GrepResult— Search output with chunks, optional answer, concepts, and stats
Testing
# Run all tests
# Run with code-search feature
# Run benchmarks
License
MIT