RLM Knowledge Base
An MCP server that enables Claude Desktop to search and read local documents via full-text and fuzzy search, providing direct access to indexed files without chunking.
README
RLM Knowledge Base
Recursive Language Model (RLM) - Eine intelligente Dokumenten-Wissensdatenbank, die LLM-Agents direkten Zugriff auf Unternehmensdokumente gibt.
Was ist das?
Ein lokales System, das:
- Dokumente indexiert (PDF, DOCX, XLSX, TXT, MD) - ohne LLM-Kosten beim Indexieren
- Volltext-Suche via SQLite FTS5 ermöglicht
- LLM-Agent (Claude) intelligent durch die Dokumente navigieren lässt
Der RLM-Ansatz vs. klassisches RAG
Klassisches RAG:
Dokumente → Chunks → Embeddings → Vector-DB → "Hoffentlich relevanter Chunk"
RLM (dieses Projekt):
Dokumente → Volltext in DB → LLM entscheidet selbst was es liest
Der LLM-Agent hat Tools zur Verfügung und entscheidet autonom:
search_documents- FTS5-Volltextsuche mit Snippetslist_documents- Übersicht aller Dokumenteread_document- Liest Dokument (komplett oder Bereichsweise)get_statistics- DB-Statistiken
Vorteile:
- Kein Informationsverlust durch Chunking
- Agent kann gezielt nachfragen/nachlesen
- Transparentes Reasoning (zeigt welche Tools genutzt wurden)
- Indexierung ist blitzschnell (kein LLM/Embedding nötig)
Quick Start
1. Installation
cd C:\Users\chris\Documents\MyProjects\rlm-connector
# Virtual Environment (optional aber empfohlen)
python -m venv venv
venv\Scripts\activate # Windows
# Dependencies installieren
pip install -r requirements.txt
2. Konfiguration
.env Datei mit API-Key:
ANTHROPIC_API_KEY=sk-ant-api03-...
config.yaml - Dokumentenpfade anpassen:
llm:
provider: anthropic
model: claude-sonnet-4-20250514
connectors:
- name: meine_dokumente
type: local
path: D:/Pfad/zu/Dokumenten
include:
- "*.pdf"
- "*.docx"
- "*.xlsx"
- "*.txt"
- "*.md"
exclude:
- ".*"
- "~$*"
- "node_modules"
3. Starten
python -m src.main
Öffnet:
- API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- Chat UI: http://localhost:7860
4. Indexieren
In der UI auf "Index aktualisieren" klicken, oder:
curl -X POST http://localhost:8000/index/refresh
API Endpoints
| Endpoint | Methode | Beschreibung |
|---|---|---|
/ |
GET | Health Check |
/statistics |
GET | DB-Statistiken (Dokumente, Größe, Typen) |
/documents |
GET | Liste aller Dokumente |
/documents/{id} |
GET | Dokument-Metadaten |
/documents/{id}/content |
GET | Dokument-Inhalt (mit Range-Support) |
/search?q=... |
GET | FTS5 Volltextsuche |
/query |
POST | RLM-Query (LLM-gestützte Frage) |
/index/refresh |
POST | Index aktualisieren |
/index/progress |
GET | Indexier-Fortschritt |
/connectors |
GET | Konfigurierte Connectors |
Beispiel: Frage stellen
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{"question": "Erstelle mir eine Liste meiner Projekte"}'
Projektstruktur
rlm-connector/
├── src/
│ ├── api/ # FastAPI REST-API
│ │ ├── app.py # App-Factory, Lifespan, AppState
│ │ └── routes.py # API-Endpoints
│ ├── connectors/ # Datenquellen
│ │ ├── base.py # BaseConnector Interface
│ │ └── local.py # LocalConnector (Dateisystem)
│ ├── database/ # SQLite + FTS5
│ │ ├── models.py # Document, SyncStatus Models
│ │ └── repository.py # DocumentRepository (CRUD, FTS5-Suche)
│ ├── indexer/ # Dokument-Indexierung
│ │ ├── indexer.py # Haupt-Indexer (kein LLM!)
│ │ ├── parser.py # PDF/DOCX/XLSX/TXT Parser
│ │ └── sync.py # SyncManager (Scheduling)
│ ├── rlm_engine/ # LLM-Agent
│ │ └── engine.py # KnowledgeBaseEngine (Tool-Use)
│ ├── ui/ # Gradio Chat-UI
│ │ └── chat.py
│ ├── config.py # AppConfig, load_config()
│ ├── mcp_server.py # MCP Server für Claude Desktop
│ └── main.py # Entry Point
├── data/
│ └── index.db # SQLite Datenbank + FTS5
├── config.yaml # Konfiguration
├── .env # API Keys (nicht committen!)
└── requirements.txt
Technologie-Stack
| Komponente | Technologie |
|---|---|
| Backend | Python 3.12, FastAPI, Uvicorn |
| Datenbank | SQLite + FTS5 (Volltext-Index) |
| LLM | Claude Sonnet 4 (Anthropic API) |
| UI | Gradio |
| Parser | PyMuPDF (PDF), python-docx, openpyxl |
Datenbank-Schema
documents (Haupttabelle)
- id: STRING (SHA256 Hash aus connector:path)
- connector_name, file_path, file_name, file_type
- size_bytes, page_count, content_length
- content_text: TEXT (voller Dokumentinhalt!)
- content_hash: STRING (für Change Detection)
- status: pending|indexed|error|skipped
- indexed_at, created_at, modified_at
documents_fts (FTS5 Virtual Table)
- doc_id, file_name, content
- Tokenizer: unicode61 (Umlaute-Support)
RLM Engine - Wie funktioniert's?
- User stellt Frage → Chat UI oder
/queryAPI - Engine startet Agentic Loop mit Claude + Tools
- Claude entscheidet welche Tools es braucht:
- Meist zuerst
search_documentsmit Suchbegriffen - Dann
read_documentfür Details - Iteriert bis Antwort vollständig
- Meist zuerst
- Antwort mit Quellen wird zurückgegeben
Max 10 Iterationen, danach Abbruch mit Teilergebnis.
Performance & Kosten
Getestet mit ~600k Dateien:
- Scan + Indexierung: ~20 Minuten
- Davon indexiert: Nur lesbare Typen (PDF, DOCX, etc.)
- FTS5-Suche: <100ms
- RLM-Query: 3-15 Sekunden (je nach Komplexität)
Kosten:
| Vorgang | Kosten |
|---|---|
| Indexierung | $0 (kein LLM) |
| Einfache Frage | ~$0.02 |
| Komplexe Frage (viele Iterationen) | ~$0.05-0.10 |
CLI-Befehle
# Alles starten (API + UI)
python -m src.main
# Nur API
python -m src.main api --port 8000
# Nur UI
python -m src.main ui --port 7860
# Index manuell triggern
python -m src.main index
python -m src.main index --full # Force Re-Index
Aktuelle Features
- [X] Lokales Dateisystem indexieren
- [X] PDF, DOCX, XLSX, TXT, MD Parser
- [X] SQLite FTS5 Volltextsuche
- [X] Fuzzy-Suche mit Trigram-Matching
- [X] RLM Tool-Use Agent (Claude)
- [X] REST API mit OpenAPI Docs
- [X] Gradio Chat UI
- [X] MCP Server für Claude Desktop Integration
- [X] Inkrementelles Indexieren (Hash-basiert)
- [X] WAL-Mode für bessere DB-Performance
MCP Server (Claude Desktop Integration)
Der RLM Knowledge Base kann als MCP Server betrieben werden, um die Dokumentensuche direkt in Claude Desktop oder anderen MCP-kompatiblen Clients zu nutzen.
Installation MCP Dependency
pip install mcp>=1.0.0
# oder komplettes Projekt neu installieren:
pip install -e .
Claude Desktop Konfiguration
Füge in %APPDATA%\Claude\claude_desktop_config.json hinzu:
{
"mcpServers": {
"rlm-knowledge-base": {
"command": "python",
"args": ["-m", "src.mcp_server"],
"cwd": "C:\\Users\\chris\\Documents\\MyProjects\\rlm-connector"
}
}
}
Wichtig: Der MCP Server verwendet die gleiche config.yaml und Datenbank wie die Hauptanwendung.
MCP Tools
Claude Desktop hat dann Zugriff auf:
| Tool | Beschreibung |
|---|---|
search_documents |
FTS5 Volltextsuche mit Snippets |
search_fuzzy |
Tippfehler-tolerante Fuzzy-Suche |
list_documents |
Übersicht aller Dokumente |
read_document |
Dokument-Inhalt lesen |
get_statistics |
Datenbank-Statistiken |
Beispiel-Nutzung in Claude Desktop
Nach der Konfiguration kannst du in Claude Desktop fragen:
- "Suche in meinen Dokumenten nach Urlaubsregelungen"
- "Was steht in der Projektdokumentation?"
- "Liste alle PDF-Dateien"
Claude nutzt automatisch die MCP-Tools um in deiner lokalen Dokumentenbasis zu suchen.
MCP Server manuell starten (zum Testen)
python -m src.mcp_server
Geplante Features
- [ ] n8n Custom Node
- [ ] OCR für gescannte PDFs
- [ ] Cleanup-Endpoint für gelöschte Dateien
- [ ] Ollama-Support für lokale LLMs
Bekannte Einschränkungen
- Gescannte PDFs ohne OCR-Layer können nicht gelesen werden
- Sehr große Dokumente (>50k Zeichen) werden in Teilen gelesen
- Rate Limits bei Anthropic API (automatisches Retry)
Projekt-Pfad: C:\Users\chris\Documents\MyProjects\rlm-connector
Stand: Januar 2025
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.