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
访问服务器

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选