Dokumentation » API » Chat

Chat API

Erstellt: 2025-12-20 | Aktualisiert: 2025-12-31

RAG-basierter Chat mit Vektorsuche und LLM-Integration. Verwendet lokale Embeddings (Ollama), Vektorsuche (Qdrant) und Claude (Anthropic) oder Ollama als LLM.

Endpoints-Übersicht

MethodePfadControllerBeschreibung
POST/api/v1/chatApi\ChatControllerEinfache Chat-Anfrage (JSON)
GET/api/v1/chat/searchApi\ChatControllerChunk-Suche
GET/api/v1/chat/statsApi\ChatControllerPipeline-Statistiken
POST/chat/{uuid}/messageChatControllerChat-Nachricht senden (HTML/HTMX)

JSON API: POST /api/v1/chat

Einfache Chat-Anfrage mit festen Einstellungen.

ControllerController\Api\ChatController
ServiceInfrastructure\AI\ChatService

Request

POST /api/v1/chat
Content-Type: application/json

{
    "message": "Was ist systemische Therapie?"
}
ParameterTypBeschreibung
messagestringBenutzer-Frage (required)

Hinweis: Dieser Endpunkt verwendet feste Einstellungen: Claude Opus 4.5, Collection "dokumentation_chunks", Limit 5. Für konfigurierbare Optionen den HTML-Endpunkt verwenden.

Response

{
    "answer": "Systemische Therapie ist ein psychotherapeutischer Ansatz...",
    "sources": [
        {
            "title": "Einführung in die systemische Therapie",
            "content": "...",
            "score": 0.89,
            "path": "/Documents/therapie/einfuehrung.pdf"
        }
    ],
    "model": "claude-opus-4-5-20251101",
    "tokens": 1234
}

HTML-Endpunkt: POST /chat/{uuid}/message

Vollständig konfigurierbarer Chat mit Session-Unterstützung.

ControllerController\ChatController

Request

POST /chat/{uuid}/message
Content-Type: application/x-www-form-urlencoded

message=Was+ist+systemische+Therapie%3F
&model=anthropic
&collections[]=documents
&collections[]=dokumentation
&contextLimit=5
&systemPromptId=1
&structureId=2
&qualityCheck=1

Parameter

ParameterTypDefaultBeschreibung
messagestringrequiredBenutzer-Frage
modelstring"anthropic""anthropic" (Claude) oder "ollama" (lokal)
collections[]string[]["documents"]Qdrant Collections (Array)
contextLimitint5Max. Kontext-Chunks (3/5/10/15)
systemPromptIdintnullSystem-Prompt aus content_config
structureIdintnullOutput-Struktur
qualityCheckint0Qualitätsprüfung aktivieren
author_profile_idintnullAutorenprofil für Schreibstil

GET /api/v1/chat/search

Suche nach relevanten Chunks ohne LLM-Anfrage.

GET /api/v1/chat/search?q=systemische+therapie&limit=5

Response

{
    "results": [
        {"id": 42, "score": 0.89, "payload": {...}}
    ]
}

GET /api/v1/chat/stats

Pipeline-Statistiken (Doc2Vector).

{
    "dokumente": 15,
    "seiten": 120,
    "chunks": 450,
    "tokens": 125000,
    "analyzed": 400,
    "synced": 380
}

RAG-Pipeline

1. Embedding erstellen (OllamaService)
   question → mxbai-embed-large → [1024-dim vector]

2. Vektorsuche (QdrantService)
   vector → Qdrant :6333 → top-k similar chunks

3. Kontext aufbauen (ChatService)
   chunks → formatierter Kontext mit Quellenangaben
   max. 3000 tokens (~12000 chars)

4. LLM-Anfrage (ClaudeService oder OllamaService)
   system_prompt + rag_prompt + context → answer

5. Response zusammenstellen (ChatService)
   answer + sources + metadata + usage

Fehlerbehandlung

HTTP CodeBedeutung
400Fehlende oder ungültige Parameter
500Service-Fehler (Ollama, Qdrant, Claude)
503Service nicht verfügbar
]]>