61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
|
|
"""
|
|||
|
|
app/routers/admin.py — Admin-/Monitoring-Endpunkte (optional)
|
|||
|
|
|
|||
|
|
Zweck:
|
|||
|
|
Liefert einfache Kennzahlen zu Collections (Counts) und Config.
|
|||
|
|
Kompatibilität:
|
|||
|
|
Python 3.12+, FastAPI 0.110+, qdrant-client 1.x
|
|||
|
|
Version:
|
|||
|
|
0.1.0 (Erstanlage)
|
|||
|
|
Stand:
|
|||
|
|
2025-10-07
|
|||
|
|
Bezug:
|
|||
|
|
- Qdrant Collections: *_notes, *_chunks, *_edges
|
|||
|
|
Nutzung:
|
|||
|
|
app.include_router(admin.router, prefix="/admin", tags=["admin"])
|
|||
|
|
Änderungsverlauf:
|
|||
|
|
0.1.0 (2025-10-07) – Erstanlage.
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
from fastapi import APIRouter
|
|||
|
|
from qdrant_client import QdrantClient
|
|||
|
|
from app.config import get_settings
|
|||
|
|
|
|||
|
|
router = APIRouter()
|
|||
|
|
|
|||
|
|
@router.get("/stats")
|
|||
|
|
def stats():
|
|||
|
|
s = get_settings()
|
|||
|
|
client = QdrantClient(url=s.QDRANT_URL, api_key=s.QDRANT_API_KEY)
|
|||
|
|
notes = f"{s.COLLECTION_PREFIX}_notes"
|
|||
|
|
chunks = f"{s.COLLECTION_PREFIX}_chunks"
|
|||
|
|
edges = f"{s.COLLECTION_PREFIX}_edges"
|
|||
|
|
|
|||
|
|
def _count(col: str) -> int:
|
|||
|
|
try:
|
|||
|
|
return client.count(collection_name=col, exact=True).count
|
|||
|
|
except Exception:
|
|||
|
|
return -1
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
"collections": {
|
|||
|
|
"notes": {"name": notes, "count": _count(notes)},
|
|||
|
|
"chunks": {"name": chunks, "count": _count(chunks)},
|
|||
|
|
"edges": {"name": edges, "count": _count(edges)},
|
|||
|
|
},
|
|||
|
|
"config": {
|
|||
|
|
"qdrant": s.QDRANT_URL,
|
|||
|
|
"prefix": s.COLLECTION_PREFIX,
|
|||
|
|
"vector_size": s.VECTOR_SIZE,
|
|||
|
|
"distance": s.DISTANCE,
|
|||
|
|
"retriever": {
|
|||
|
|
"w_sem": s.RETRIEVER_W_SEM,
|
|||
|
|
"w_edge": s.RETRIEVER_W_EDGE,
|
|||
|
|
"w_cent": s.RETRIEVER_W_CENT,
|
|||
|
|
"top_k": s.RETRIEVER_TOP_K,
|
|||
|
|
"expand_depth": s.RETRIEVER_EXPAND_DEPTH,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
}
|