---
title: "Tree-sitter + SQLite = The Anti-RAG: How One Tool Indexes 27,732 Files Locally"
description: "RAG was the wrong abstraction for code. Code-Review-Graph builds a deterministic AST graph in SQLite — no embeddings required, no chunking artifacts, no vector DB tax."
canonical: https://callsphere.ai/blog/tree-sitter-sqlite-anti-rag-code-graph
category: "Agentic AI"
tags: ["Tree-sitter", "SQLite", "RAG", "Code Search", "AST", "Agentic AI", "Code Review Graph"]
author: "CallSphere Team"
published: 2026-04-22T00:00:00.000Z
updated: 2026-05-08T17:24:17.167Z
---

# Tree-sitter + SQLite = The Anti-RAG: How One Tool Indexes 27,732 Files Locally

> RAG was the wrong abstraction for code. Code-Review-Graph builds a deterministic AST graph in SQLite — no embeddings required, no chunking artifacts, no vector DB tax.

Half the AI coding industry is rebuilding RAG pipelines for code. Vector DBs, chunkers, hybrid retrievers — every conference talk is an architecture diagram with seven boxes. **Code-Review-Graph** took the opposite bet: parse the code with Tree-sitter, store the AST in SQLite, query it with structural traversal. The result outperforms RAG on every code-relevant metric.

## The Pipeline

```mermaid
flowchart TB
    SRC[Source files23 languages] --> TS[Tree-sitter parser]
    TS --> AST[Abstract Syntax Trees]
    AST --> EXT[Node + Edge extractor]
    EXT --> N[Nodes:functions, classes,imports, modules]
    EXT --> E[Edges:calls, inherits,imports, tests]
    N --> DB[(SQLite +FTS5 index)]
    E --> DB
    DB --> Q1[Structural queriescallers / callees / tests]
    DB --> Q2[Full-text searchname / signature]
    DB --> Q3[Optional vector searchsemantic similarity]
    Q1 & Q2 & Q3 --> AGENT[Agent context]
    style DB fill:#0ea5e9,stroke:#0369a1,color:#fff
    style AGENT fill:#a855f7,stroke:#7e22ce,color:#fff
```

## Why Tree-sitter And Not LSP

LSP gives you semantic precision per language but requires a running server per project. Tree-sitter gives you a uniform AST across 23 languages — Python, TypeScript, Go, Rust, Java, Ruby, C, C++, C#, Kotlin, Swift, Lua, PHP, even Jupyter notebooks and Perl XS files — with a single dependency tree and offline operation.

For a tool that needs to ship to anyone's laptop and parse any repo, Tree-sitter is the only sane choice.

## Why SQLite And Not Neo4j

Graph databases assume your graph is the product. For Code-Review-Graph, the graph is metadata. SQLite gives you transactional updates, FTS5 full-text search, sub-millisecond queries on millions of rows, and a single file you can ignore-list in `.gitignore`.

For export, the tool does emit Neo4j Cypher, GraphML, and Obsidian wikilink vaults. But the operational store is SQLite — and that is why incremental rebuilds on a 1,122-file FastAPI repo finish in 128ms.

## The "Anti-RAG" Argument

| Property | RAG | Code-Review-Graph |
| --- | --- | --- |
| Retrieval primitive | Embedding similarity | Structural graph traversal |
| Determinism | Probabilistic ranking | Exact graph queries |
| Recall on impact | ~70% (chunk artifacts) | 100% |
| Index size | GB-scale vector store | Tens of MB SQLite |
| Update cost | Re-embed chunks | Re-parse changed files |
| Failure mode | Hallucinated retrieval | Empty result set |

## When RAG Still Wins

Natural-language search across docstrings, README files, design docs — those are similarity tasks. Code-Review-Graph supports optional vector embeddings exactly for this case. The hybrid approach gives you structural precision *and* semantic search, with the graph as the trustworthy core.

## Build Speed Receipts

- Express (141 files): **106ms**
- FastAPI (1,122 files): **128ms**
- NextJS monorepo (27,732 files): incremental updates skip **2,900+ unchanged files** on every run

If the rest of your AI stack rebuilt this fast, you would not be reading articles about token costs.

## Tree-sitter + SQLite = The Anti-RAG: How One Tool Indexes 27,732 Files Locally — operator perspective

If you've spent any real time with tree-sitter + SQLite = The Anti-RAG, you already know the cost curve bites before the quality curve. Token spend, latency tail, and tool-call retries compound long before users complain about answer quality. The teams that ship fastest treat tree-sitter + sqlite = the anti-rag as an evals problem first and a modeling problem second. They write the failure cases into the regression set on day one, not after the first incident.

## Why this matters for AI voice + chat agents

Agentic AI in a real call center is a different beast than a single-LLM chatbot. Instead of one model answering one prompt, you orchestrate a small team: a router that decides intent, specialists that own a vertical (booking, intake, billing, escalation), and tools that read and write to the same Postgres your CRM trusts. Hand-offs are where most production bugs hide — when Agent A passes context to Agent B, anything that isn't explicit in the message gets lost, and the user feels it as the agent "forgetting." That's why the systems that hold up under load are the ones with typed tool schemas, deterministic state stored outside the conversation, and a hard ceiling on tool calls per session. The cost story is just as important: a multi-agent loop can quietly burn 10x the tokens of a single-LLM design if you let it think out loud at every step. The fix isn't a smarter model, it's smaller agents, shorter prompts, cached system messages, and evals that fail the build when p95 latency or per-session cost regresses. CallSphere runs this pattern across 6 verticals in production, and the rule has held every time: the agent you can debug in five minutes will out-survive the agent that's "smarter" on a benchmark.

## FAQs

**Q: What's the hardest part of running tree-sitter + SQLite = The Anti-RAG live?**

A: Scaling comes from constraint, not capability. The deployments that hold up keep each agent narrow, cap tool calls per turn, cache the system prompt, and pin a smaller model for routing while reserving the larger model for synthesis. CallSphere's stack — 37 agents · 90+ tools · 115+ DB tables · 6 verticals live — is sized that way on purpose.

**Q: How do you evaluate tree-sitter + SQLite = The Anti-RAG before shipping?**

A: Hard ceilings beat heuristics. A maximum step count, an idempotency key on every tool call, and a fallback to a deterministic script when confidence drops below a threshold are what keep the loop bounded. Evals that simulate noisy inputs catch the rest before they reach a real caller.

**Q: Which CallSphere verticals already rely on tree-sitter + SQLite = The Anti-RAG?**

A: It's already in production. Today CallSphere runs this pattern in IT Helpdesk and Real Estate, alongside the other live verticals (Healthcare, Real Estate, Salon, Sales, After-Hours Escalation, IT Helpdesk). The same orchestrator code path serves voice and chat — the difference is the tool set the router exposes.

## See it live

Want to see sales agents handle real traffic? Spin up a walkthrough at https://sales.callsphere.tech or grab 20 minutes on the calendar: https://calendly.com/sagar-callsphere/new-meeting.

---

Source: https://callsphere.ai/blog/tree-sitter-sqlite-anti-rag-code-graph
