No description
- Python 95.8%
- Nix 2.9%
- Shell 1.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Previous attempt (
|
||
| docs | ||
| tools | ||
| .gitignore | ||
| AGENTS.md | ||
| flake.nix | ||
| ingest.py | ||
| LICENSE | ||
| mcp_server.py | ||
| module.nix | ||
| pyproject.toml | ||
| rag_service.py | ||
| README.md | ||
| retrieve.py | ||
| shell.nix | ||
| test_rag_service.py | ||
| uv.lock | ||
Siemens RAG
Fully local Retrieval-Augmented Generation over technical Siemens industrial-automation documentation (bilingual DE/EN), built with LlamaIndex, llama.cpp and pgvector. No cloud APIs.
What you get
- MCP server (
:8998/mcp) — exposes the knowledge base as tools for any MCP client (e.g. Open WebUI's agentic mode):search_siemens_docs(query, language="", top_k=8)— hybrid retrieval (pgvector + PostgreSQL full-text search, fused via RRF), language-awareget_document(doc_id)— full chunk by DB id
- RAG service (
:8999) — OpenAI-compatible/v1/chat/completionsendpoint that retrieves relevant chunks behind the scenes (streaming and non-streaming), so any OpenAI-compatible frontend can use it directly.
Architecture
MCP client (e.g. Open WebUI) OpenAI-compatible clients
│ tool calls │ chat requests
▼ ▼
mcp_server.py :8998/mcp rag_service.py :8999/v1/chat/completions
└────────────► retrieve.py ◄────────────┘
hybrid search (vector + FTS via RRF)
│
┌─────────────┼──────────────┐
▼ ▼ ▼
llama.cpp :45757 PostgreSQL 16 llama.cpp :37679
bge-m3 embeddings + pgvector LLM (chat generation)
Requirements
- Python 3.13 + uv
- PostgreSQL 16 with the
pgvectorextension - A llama.cpp server with a chat model (
:37679) and an embedding model (bge-m3,:45757) — endpoints are env-configurable
Setup
git clone <this repo> && cd rag-system
uv sync
Point the services at your infrastructure via environment variables (see
AGENTS.md for the full table):
export EMBEDDING_BASE_URL=http://127.0.0.1:45757/v1
export LLM_BASE_URL=http://127.0.0.1:37679/v1
export PG_DATABASE_URL=postgresql+psycopg2:///rag?host=/run/postgresql
Ingest documents
# subset for testing
uv run python ingest.py --batch-size 500 --limit 100
# full run (resumable with --no-drop)
uv run python ingest.py --batch-size 500
Expects scraped markdown documents with YAML frontmatter under data/
(see docs/ingest.md and docs/ingest_md_format.md for the format).
Run the services
uv run python mcp_server.py # MCP server on :8998/mcp
uv run uvicorn rag_service:app --port 8999 # RAG service on :8999
Wire up Open WebUI
- RAG service: Admin → Connections → OpenAI-compatible →
http://127.0.0.1:8999/v1(modelsiemens-rag) - MCP server: Admin → Integrations → MCP Streamable HTTP →
http://127.0.0.1:8998/mcp
See docs/open_webui.md and docs/mcp_server.md for details.
Repository layout
| Path | Purpose |
|---|---|
mcp_server.py |
MCP server (search / get_document tools) |
rag_service.py |
FastAPI OpenAI-compatible RAG endpoint |
retrieve.py |
shared retrieval engine (vector / FTS / hybrid RRF) |
ingest.py |
batch ingestion: chunk → embed → pgvector |
docs/ |
setup and operations guides |
tools/ |
one-off maintenance scripts (OCR fixes, URL enrichment) |
Notes
- The services have no authentication — designed for a trusted local network. Do not expose them without adding auth.
- Data is not included; the code expects the corpus under
data/. - German retrieval quality was a design focus (language-aware FTS stemmers, bge-m3 multilingual embeddings).