sqlite-rag-mcp
Offline RAG MCP server that indexes documents into SQLite with hybrid vector and lexical search, and enables natural language queries via Claude.
README
sqlite-rag-mcp
100% offline RAG as an MCP server — index your documents into SQLite (sqlite-vec + FTS5, hybrid RRF search, local Ollama embeddings) and search them from Claude. Your documents never leave your machine.
🇺🇸 English
Why
Most RAG stacks ship your documents to a hosted vector database and an embeddings API. This one doesn't. Everything — storage, vectors, lexical index, embeddings — runs locally:
- One SQLite file is the whole index. No services to run, nothing to babysit. Back it up with
cp. - Hybrid search: sqlite-vec vector KNN + FTS5 BM25, fused with Reciprocal Rank Fusion (RRF) — better recall than either alone.
- Local embeddings via Ollama (
nomic-embed-textby default). - Graceful degradation: if Ollama isn't running, indexing and search still work in lexical (FTS5) mode with an explicit warning. Search never breaks.
Architecture
flowchart LR
subgraph Claude["Claude Code / Claude Desktop"]
C[MCP client]
end
subgraph Server["sqlite-rag-mcp (stdio)"]
T1[index_documents]
T2[search]
T3[get_chunk]
T4[stats]
F{{RRF fusion}}
end
subgraph Local["Your machine only"]
DB[(SQLite<br/>chunks + FTS5 + vec0)]
O[Ollama<br/>nomic-embed-text]
MD[/your .md / .txt files/]
end
C <-->|MCP over stdio| T1 & T2 & T3 & T4
T1 --> MD
T1 --> O
T1 --> DB
T2 --> F
F -->|semantic KNN| DB
F -->|lexical BM25| DB
T2 -.->|embed query| O
O -.->|offline? fall back to FTS5| F
Install
Requires Python ≥ 3.10. Not yet published to PyPI — install from a clone of this repository:
git clone https://github.com/giuseppeferretti/sqlite-rag-mcp
cd sqlite-rag-mcp
pip install .
For semantic search, also install Ollama and pull the embedding model:
ollama pull nomic-embed-text # optional — lexical search works without it
Configure Claude Code / Claude Desktop
Add to your MCP settings (claude mcp add or claude_desktop_config.json):
{
"mcpServers": {
"sqlite-rag": {
"command": "sqlite-rag-mcp",
"env": {
"SQLITE_RAG_DB": "~/.local/share/sqlite-rag-mcp/index.db"
}
}
}
}
Or with Claude Code CLI:
claude mcp add sqlite-rag -- sqlite-rag-mcp
| Environment variable | Default | Purpose |
|---|---|---|
SQLITE_RAG_DB |
~/.local/share/sqlite-rag-mcp/index.db |
Index database path |
OLLAMA_HOST |
http://localhost:11434 |
Ollama endpoint |
SQLITE_RAG_EMBED_MODEL |
nomic-embed-text |
Embedding model |
SQLITE_RAG_CHUNK_TOKENS |
800 |
Chunk size (approx. tokens) |
SQLITE_RAG_CHUNK_OVERLAP |
100 |
Chunk overlap (approx. tokens) |
Tools
index_documents(path, glob="**/*.md") — index text/markdown files from a directory. Unchanged files (same SHA-256) are skipped, changed files are re-chunked and re-embedded.
"Index everything under ~/notes" →
index_documents(path="~/notes")→{"files_indexed": 42, "chunks_added": 310, "chunks_embedded": 310, "warnings": []}
search(query, k=8, mode="hybrid") — search the index. Modes: hybrid (RRF fusion, default), semantic (vector KNN), lexical (FTS5 BM25). With Ollama offline, hybrid/semantic fall back to lexical and the response carries a warning — it never errors.
"How do I rotate API tokens?" →
{"mode_used": "hybrid", "results": [{"chunk_id": 17, "score": 0.0325, "snippet": "Generate a token with…", "source": "…/authentication.md", "title": "Authentication and API Tokens", "matched_by": "semantic+lexical"}]}
get_chunk(chunk_id) — full text + source of a chunk returned by search.
stats() — document/chunk/embedding counts, DB path and size, Ollama availability.
CLI indexing (outside MCP)
python -m sqlite_rag_mcp.index ~/notes --glob "**/*.md"
python -m sqlite_rag_mcp.index ~/docs --glob "**/*.txt" --db /tmp/docs.db
How search works
- The query is embedded locally (Ollama) and run against the
vec0KNN index; in parallel a sanitized, OR-expanded prefix query runs against FTS5 (BM25). - Both rankings are fused with Reciprocal Rank Fusion:
score(chunk) = Σ 1/(60 + rank + 1)across the two lists — a rank-based method that needs no score calibration between BM25 and cosine distance. - Top-k fused chunks are returned with snippet, source path, and which ranker(s) matched them.
Provenance
This server is the extracted, genericized search core of a production RAG system that indexes and answers questions over a company's document corpus — fully offline, on commodity hardware. Case study at portfolio.iterlabs.com.br.
Development
pip install -e ".[dev]"
pytest # includes a real stdio smoke test that spawns the server and drives it with the MCP SDK client
🇧🇷 Português
RAG 100% offline como servidor MCP — indexe seus documentos em SQLite (sqlite-vec + FTS5, busca híbrida RRF, embeddings locais via Ollama) e pesquise-os a partir do Claude. Seus documentos nunca saem da sua máquina.
Por quê
- Um único arquivo SQLite é o índice inteiro — sem serviços externos; backup com
cp. - Busca híbrida: KNN vetorial (sqlite-vec) + BM25 (FTS5), fundidos com Reciprocal Rank Fusion.
- Embeddings locais via Ollama (
nomic-embed-text). - Degradação graciosa: sem Ollama, indexação e busca continuam funcionando em modo lexical (FTS5) com aviso explícito — a busca nunca quebra.
Instalação e configuração
Ainda não publicado no PyPI — instale a partir de um clone deste repositório:
git clone https://github.com/giuseppeferretti/sqlite-rag-mcp
cd sqlite-rag-mcp
pip install .
ollama pull nomic-embed-text # opcional — busca lexical funciona sem
No Claude Code / Claude Desktop:
{
"mcpServers": {
"sqlite-rag": { "command": "sqlite-rag-mcp" }
}
}
Banco em ~/.local/share/sqlite-rag-mcp/index.db por padrão (configurável via SQLITE_RAG_DB).
Ferramentas
index_documents(path, glob)— indexa arquivos texto/markdown de um diretório (arquivos inalterados são pulados).search(query, k, mode)—hybrid(padrão),semanticoulexical; com Ollama offline, cai paralexicalcom aviso.get_chunk(chunk_id)— texto completo de um trecho.stats()— contagens e estado do índice.
CLI: python -m sqlite_rag_mcp.index <dir> --glob "**/*.md".
Origem
Núcleo de busca extraído e generalizado de um sistema RAG em produção que responde perguntas sobre o corpus documental de uma empresa — totalmente offline. Case em portfolio.iterlabs.com.br.
Built with AI-assisted development; designed, verified, and operated by Giuseppe Ferretti.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。