mindnet/app/routers/query.py
Lars c0979b69e2
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
app/routers/query.py hinzugefügt
2025-10-07 11:31:26 +02:00

39 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
app/routers/query.py — Query-Endpunkte (WP-04)
Zweck:
Stellt POST /query bereit und ruft den passenden Retriever-Modus auf.
Kompatibilität:
Python 3.12+, FastAPI 0.110+
Version:
0.1.0 (Erstanlage)
Stand:
2025-10-07
Bezug:
- app/core/retriever.py
- app/models/dto.py
Nutzung:
app.include_router(query.router, prefix="/query", tags=["query"])
Änderungsverlauf:
0.1.0 (2025-10-07) Erstanlage.
"""
from __future__ import annotations
from fastapi import APIRouter, HTTPException
from app.models.dto import QueryRequest, QueryResponse
from app.core.retriever import hybrid_retrieve, semantic_retrieve
router = APIRouter()
@router.post("", response_model=QueryResponse)
def post_query(req: QueryRequest) -> QueryResponse:
try:
if req.mode == "semantic":
return semantic_retrieve(req)
# default: hybrid
return hybrid_retrieve(req)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))
except Exception as e:
raise HTTPException(status_code=500, detail=f"query failed: {e}")