lyonzin/knowledge-rag
Local RAG server for Claude Code, Cursor and other MCP clients: hybrid BM25 + vector search with cross-encoder reranking on by default, 13 MCP tools, 33 file types including code, re-indexing on file changes. One Python process with embedded ChromaDB and FastEmbed ONNX: no Docker, database server or API key; offline after the first model download.
What it solves
knowledge-rag is a local retrieval-augmented generation (RAG) server for the Model Context Protocol (MCP). It indexes the documents and code on your machine and gives MCP clients (Claude Code, Cursor, VS Code, and others) 13 tools to search them. It solves the problem of AI coding assistants having no access to your local files: instead of sending data to the cloud, the assistant can search your own documents and code. Everything runs in one Python process with embedded ChromaDB and FastEmbed ONNX models — no Docker, no database server, no API key — and indexing and search work offline once the models are cached.
How it works
- Ingest. Files under
documents/are parsed by format: code files get their function, class, and import names as metadata; notebooks keep only Markdown and code cells; PDFs contribute their text. Markdown is split at##/###sections; every other format is cut into 1,000-character chunks with 200 characters of overlap. Chunks are de-duplicated by SHA-256, embedded with FastEmbed (defaultBAAI/bge-small-en-v1.5, 384 dimensions), and stored in an embedded ChromaDB. - Watch. While the server runs, a watcher re-indexes changed files after 10 seconds without new changes. Full rebuilds fill a staging collection and swap it in after validation, so searches keep using the current index.
- Search.
search_knowledgechecks a query cache (100 entries, 5-minute TTL), runs BM25 over an inverted index and vector search, fuses both rankings with weighted reciprocal rank fusion (hybrid_alpha, default 0.3, leaning towards keywords), and reranks the top candidates with a cross-encoder. An opt-in FTS5 fast path sends identifier-like queries (CVE IDs, ticket keys, hashes) to SQLite FTS5 first. - Answer. Results go back to the MCP client with the file path, chunk index, snippet, and scores. The client's model writes the answer; knowledge-rag never calls an LLM itself.
- Serve. Over stdio for one client, or as one Streamable HTTP or SSE server for many. HTTP mode answers health probes first, then checks the bearer token. Every tool call passes through the optional rate limiter and metrics.
config.yamland five presets configure all of it.
Who it's for
Developers using MCP-compatible AI coding tools — Claude Code, Claude Desktop, Cursor, Windsurf, VS Code Copilot, opencode, and others — who want their assistant to search local documents and code. It suits people who want local, offline RAG without cloud services, Docker, or a database server. It runs on Windows, Linux, and macOS, needs Python 3.11+ (and Node.js 16+ for the npx launcher), and supports NVIDIA CUDA GPUs.
Highlights
- Hybrid search with reranking: BM25 keywords plus vector similarity fused via weighted reciprocal rank fusion, with cross-encoder reranking on by default.
- Fast: 11.1 ms median uncached hybrid query on CPU, 6.1 ms on CUDA; 0.03 ms for a repeated cached query.
- 13 MCP tools: search, document add/update/remove, reindexing, listing, category listing, index stats, and retrieval evaluation.
- Local and offline: one Python process, embedded ChromaDB, FastEmbed ONNX models; no Docker, database server, or API key; works offline once models are cached.
- Auto-indexing watcher: new and changed files in
documents/are indexed automatically after 10 seconds of quiet. - Flexible serving: stdio for one client, or one Streamable HTTP/SSE server shared by many clients on one index.
- Configurable and observable:
config.yamlplus five presets; optional bearer-token auth, rate limiting, Prometheus metrics, structured JSON logs, and health endpoints. - Proven at scale: a full rebuild of 75,016 chunks from 5,889 documents completed; 1,500+ tests with 84% line coverage across 9 OS × Python CI cells.
- Easy install: via npx launcher, pip in a virtual environment, or Docker; cross-platform with NVIDIA CUDA support.
Related
- Project
- Project
- Project
- Project
- Project