Stats
51 Downloads
Project Files
README
A production-grade, fully local MCP server for LM Studio. Semantic document retrieval + live web search — all on your machine, no cloud needed.
| Capability | Details |
|---|---|
| 11 embedding models | From fast MiniLM to Stella-1.5B / E5-Mistral — switchable with one flag |
| 4 chunking strategies | paragraph · sentence · semantic · fixed |
| Hybrid retrieval | BM25+ sparse + dense cosine, fused via Reciprocal Rank Fusion |
| Cross-encoder reranking | MiniLM-L6 / L12 / Electra — dramatically improves precision |
| HyDE | Hypothetical Document Embedding — better recall on abstract queries |
| 10 file formats | PDF · MD · TXT · HTML · DOCX · EPUB · CSV · JSON |
| 4 web search providers | DuckDuckGo · Brave · Tavily · Serper |
| Live re-indexing | Add documents and re-index without restarting the server |
| Thread-safe TTL cache | Dedup repeated queries; configurable window |
mcp-rag-server/ ├── server.py ← Entry point — run this ├── config.py ← All constants + embedding model registry ├── requirements.txt ├── README.md └── src/ ├── ingestion/ │ ├── extractors.py ← PDF, MD, HTML, DOCX, EPUB, CSV, JSON │ └── chunker.py ← paragraph / sentence / semantic / fixed ├── retrieval/ │ ├── engine.py ← Unified RAG pipeline orchestrator │ ├── bm25.py ← BM25+ sparse index (zero dependencies) │ ├── fusion.py ← RRF + CombSUM result fusion │ ├── reranker.py ← Cross-encoder reranking │ └── hyde.py ← Hypothetical Document Embedding ├── search/ │ └── providers.py ← DuckDuckGo / Brave / Tavily / Serper ├── tools/ │ ├── rag_tool.py ← rag_search MCP tool │ ├── web_tool.py ← web_search MCP tool │ └── ingest_tool.py ← reindex_documents MCP tool └── utils/ ├── cache.py ← Thread-safe TTL cache └── logging.py ← Structured stderr logging
pip install -r requirements.txt
python server.py --docs /path/to/your/documents
python server.py \ --docs /path/to/your/documents \ --embedding-model bge-large \ --chunk-strategy sentence \ --reranker \ --hyde \ --web-search \ --search-provider tavily \ --tavily-api-key YOUR_KEY
python server.py --list-models
| Key | Tier | Dim | Highlight |
|---|---|---|---|
minilm-l6 | ⚡ fast | 384 | Smallest, lowest RAM |
minilm-l12 | ⚡ fast | 384 | Better than L6, same size |
mpnet | ⚖ balanced | 768 | Strong general-purpose |
gte-base | ⚖ balanced | 768 | Top BEIR at this size |
bge-base | ⚖ balanced | 768 | Default — top MTEB |
bge-large | 🔥 powerful | 1024 | Best English BGE |
gte-large | 🔥 powerful | 1024 | Great on long docs |
e5-large | 🔥 powerful | 1024 | Instruction-aware, top BEIR |
nomic-v1.5 | 🔥 powerful | 768 | 8192-token context |
jina-v3 | 🔥 powerful | 1024 | Multilingual · code + text |
e5-mistral | 🔥 powerful | 4096 | Highest quality · needs GPU |
stella-en-1.5b | 🔥 powerful | 1024 | MTEB SOTA · ~6 GB RAM |
Switching models is safe — each model gets its own ChromaDB collection automatically. Delete
.chroma_dbto force a full re-index.
| Strategy | Best for | Notes |
|---|---|---|
paragraph | General documents | Default — fast, structure-aware |
sentence | Dense prose, QA | Requires nltk |
semantic | Mixed-topic documents | Slowest ingest, highest quality |
fixed | Last resort | No structure awareness |
python server.py --list-rerankers
| Key | Speed | Quality |
|---|---|---|
ms-marco-MiniLM-L-6-v2 | Fastest | Good |
ms-marco-MiniLM-L-12-v2 | Balanced | Better |
ms-marco-electra-base | Slowest | Best |
User Query │ ├──[HyDE]────────────────────────────────────────────────────────────────┐ │ LLM generates a hypothetical passage that would answer the query. │ │ We embed that passage instead of the raw query. │ │ (Greatly improves recall for abstract / jargon-heavy queries) │ └────────────────────────────────────────────────────────────────────────┘ │ ┌────▼──────────────────┐ ┌──────────────────────────────┐ │ Dense Retrieval │ │ BM25+ Sparse Retrieval │ │ ChromaDB cosine sim │ │ Keyword index (in-memory) │ │ top K×4 candidates │ │ top K×4 candidates │ └────────────┬──────────┘ └──────────────┬───────────────┘ │ │ └──────────────┬────────────────┘ │ ┌───────────▼───────────┐ │ Reciprocal Rank │ │ Fusion (RRF) │ │ Combines both lists │ └───────────┬───────────┘ │ ┌───────────▼───────────┐ │ Cross-Encoder │ │ Reranking (optional) │ │ (query, chunk) pairs │ └───────────┬───────────┘ │ ┌───────────▼───────────┐ │ Top-K Results │ │ with source + scores │ └───────────────────────┘
rag_searchSearch the local document knowledge base.
{ "query": "What is the return policy?", "top_k": 5, "min_score": 0.3 }
web_searchSearch the live web (requires --web-search).
{ "query": "latest Python 3.13 features", "max_results": 5 }
reindex_documentsRe-scan and index new documents without restarting.
{}
{ "mcpServers": { "rag": { "command": "python", "args": [ "/absolute/path/to/mcp-rag-server/server.py", "--docs", "/absolute/path/to/your/documents" ] } } }
{ "mcpServers": { "rag": { "command": "python", "args": [ "/absolute/path/to/mcp-rag-server/server.py", "--docs", "/absolute/path/to/your/documents", "--embedding-model", "bge-large", "--chunk-strategy", "sentence", "--reranker", "--hyde", "--web-search", "--search-provider", "duckduckgo" ] } } }
{ "mcpServers": { "rag": { "command": "python", "args": [ "/absolute/path/to/mcp-rag-server/server.py", "--docs", "/absolute/path/to/your/documents", "--embedding-model", "nomic-v1.5", "--chunk-size", "1024", "--chunk-overlap", "128", "--reranker" ] } } }
Documents: --docs PATH Folder to index (required) --collection NAME ChromaDB collection prefix Chunking: --chunk-strategy paragraph | sentence | semantic | fixed --chunk-size INT Target words per chunk (default: 512) --chunk-overlap INT Overlap between chunks (default: 64) Embedding: --embedding-model KEY Model key (default: bge-base) --list-models Print all models and exit Retrieval: --top-k INT Results per query (default: 5) --min-score FLOAT Similarity threshold (default: 0.0) --no-hybrid Dense-only; disable BM25+ Reranking: --reranker Enable cross-encoder reranking --reranker-model KEY Reranker key (default: ms-marco-MiniLM-L-6-v2) --list-rerankers Print all rerankers and exit HyDE: --hyde Enable Hypothetical Document Embedding --hyde-url URL Override LM Studio completions URL Web search: --web-search Enable web_search tool --search-provider duckduckgo | brave | tavily | serper --brave-api-key KEY --tavily-api-key KEY --serper-api-key KEY --web-max-results INT Default results per web query (default: 5)
.chroma_db/ next to your docs folder. Safe to delete to re-index from scratch.http://localhost:1234 (default). It silently falls back to the original query if the LLM is unreachable.--embedding-model.| Problem | Fix |
|---|---|
ModuleNotFoundError: frontmatter | Wrong package. Install python-frontmatter, not frontmatter. |
ValueError: Unknown embedding model | Run --list-models to see valid keys. |
| HyDE does nothing | LM Studio not running at port 1234. Check --hyde-url or disable --hyde. |
| Reranker is slow | Expected on CPU with large pools. Use a smaller --reranker-model. |
| No results returned | Lower --min-score to 0.0 or check that ingest completed at startup. |
| EPUB / DOCX not extracted | Install optional deps: pip install ebooklib python-docx |