RLM Knowledge Base

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.

Category
Visit Server

README

RLM Knowledge Base

Python 3.12+ License: MIT FastAPI MCP Platform

🇬🇧 English Version

Recursive Language Model (RLM) - Eine intelligente Dokumenten-Wissensdatenbank, die LLM-Agents direkten Zugriff auf Unternehmensdokumente gibt.

Was ist das?

Ein lokales System, das:

  1. Dokumente indexiert (PDF, DOCX, XLSX, TXT, MD) - ohne LLM-Kosten beim Indexieren
  2. Volltext-Suche via SQLite FTS5 ermöglicht
  3. 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 Snippets
  • list_documents - Übersicht aller Dokumente
  • read_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?

  1. User stellt Frage → Chat UI oder /query API
  2. Engine startet Agentic Loop mit Claude + Tools
  3. Claude entscheidet welche Tools es braucht:
    • Meist zuerst search_documents mit Suchbegriffen
    • Dann read_document für Details
    • Iteriert bis Antwort vollständig
  4. 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

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured