Every retrieval decision is a cost decision. And most teams are making it badly.

The AI agent community has settled into a comfortable consensus: embed your documents, shove them into a vector database, run approximate nearest neighbour search, and feed the results to your LLM. It works. It scales. It is also wildly over-engineered for the majority of production agent workloads, and its costs compound in ways that only become visible at scale.

Traditional RAG: The Baseline Everyone Knows

The classic pipeline: chunk documents, generate vector embeddings, store in a vector database, run ANN search at query time, pass top-k chunks to the LLM.

It works. But the costs are real:

Infrastructure cost. You are running an embedding model, a vector database, and an LLM. Three systems to keep alive, monitor, and pay for.

Ingest latency. Every new document must pass through the embedding pipeline before it becomes searchable.

Approximation by design. ANN search is approximate. Fine for “find me some relevant blog posts.” Not fine for “retrieve the exact operational procedure for deploying this service.”

Opacity. Ask your vector DB why document X ranked higher than document Y. It will point at cosine similarity scores between high-dimensional vectors. Good luck debugging it at 3am.

Traditional RAG remains the right choice for large-scale, open-ended search across unstructured corpora.

Agentic RAG: The New Hotness

The OpenAI Cookbook published a pattern that dispenses with embeddings entirely: let the LLM itself navigate the document. Split into coarse chunks, let the model select relevant chunks, recursively subdivide, generate the answer with citations, verify with a separate LLM-as-Judge step.

It has one genuinely impressive property: zero-ingest latency. Query a brand-new document immediately.

But the cost you are signing up for: multiple LLM calls per query (5-10 easily), single-document focus, and latency that scales with depth. A single retrieval can burn 5-10 LLM calls. If your agent runs thousands of queries per day, you are paying reasoning tax on every single one.

The fundamental problem: production agents need to minimise per-query reasoning cost for known work. The 1,000th execution of the same workflow should cost nearly nothing. Agentic RAG maximises reasoning per query, every time.

Graph Embeddings via Aho-Corasick Automata

At Terraphim, we build a knowledge graph indexed with Aho-Corasick automata for sub-millisecond deterministic matching.

The core data structure is the RoleGraph:

pub struct RoleGraph {
    pub role: RoleName,
    nodes: AHashMap<u64, Node>,
    edges: AHashMap<u64, Edge>,
    documents: AHashMap<String, IndexedDocument>,
    pub thesaurus: Thesaurus,
    pub ac: AhoCorasick,
    pub ac_reverse_nterm: AHashMap<u64, NormalizedTermValue>,
}

At query time, input text is scanned in a single pass. Every matching concept ID is extracted. Those IDs traverse the graph: nodes to edges to documents, ranked by weighted combinations of node rank, edge rank, and document frequency.

There is also a graph connectivity check that verifies matched terms are actually connected in the knowledge graph, not just co-occurring in text. It eliminates false positives that plague keyword-based systems.

Head-to-Head Comparison

PropertyTraditional RAGAgentic RAGGraph Embeddings
Query latency~50-200ms~2-10s<1ms
Per-query costEmbedding + DB5-10 LLM callsZero
DeterminismApproximateNon-deterministicFully deterministic
ExplainabilityCosine scoresNL reasoningExact graph path
Ingest latencyMinutesZeroSeconds
Runs on edgeNoNoYes (WASM)

The Layered Architecture

The right answer is layering them correctly:

Layer 1: Graph embeddings. Every query hits the knowledge graph first. Sub-millisecond, deterministic, zero cost. If high-confidence results return, the agent acts immediately.

Layer 2: LLM reasoning. When the graph returns nothing, escalate to LLM-based reasoning for genuinely novel queries.

Layer 3: Learning capture. When LLM reasoning succeeds, capture the successful pattern. New thesaurus entries are created. The graph grows. Next time, the same query hits Layer 1.

This architecture has a critical economic property: it gets cheaper as it learns. The first execution pays full LLM cost. Subsequent executions cost nearly nothing.

Stop paying reasoning tax on problems your agent has already solved.