mindnet/app/routers/admin.py
2025-12-15 15:40:39 +01:00

51 lines
1.5 KiB
Python

"""
FILE: app/routers/admin.py
DESCRIPTION: Monitoring-Endpunkt. Zeigt Qdrant-Collection-Counts und geladene Config.
VERSION: 0.1.0
STATUS: Active (Optional)
DEPENDENCIES: qdrant_client, app.config
LAST_ANALYSIS: 2025-12-15
"""
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,
},
},
}