M25: expose provenance-aware knowledge statistics

This commit is contained in:
NuklearRabbit
2026-08-10 16:04:39 +02:00
parent 0935901f11
commit 90cc3cf378
22 changed files with 238 additions and 10 deletions
+12
View File
@@ -1,9 +1,12 @@
from __future__ import annotations
from pathlib import Path
import httpx
from app.core.config import get_settings
from app.services.knowledge import EvidenceState, GroundedAnswer, KnowledgeHealth, SourceCard
from app.services.knowledge.procedures import iter_procedure_documents
_GROUNDED_ANSWERABILITY = {"answerable", "partially_answerable"}
@@ -140,6 +143,10 @@ class RAGcoreKnowledgeProvider:
except (httpx.HTTPError, ValueError) as exc:
available = False
detail = f"RAGcore unavailable: {type(exc).__name__}: {exc}"
source_document_count = sum(
document.language == language
for document in iter_procedure_documents(Path(self._settings.knowledge_dir))
)
return KnowledgeHealth(
provider=self.name,
available=available,
@@ -150,6 +157,11 @@ class RAGcoreKnowledgeProvider:
# RAGcore's retrieval API has no corpus-size endpoint. Unknown is explicit
# so the UI never turns this into the misleading claim "0 procedures".
document_count=None,
source_document_count=source_document_count,
reported_synced_document_count=None,
reported_failed_document_count=None,
last_sync_at=None,
statistics_state="not_reported",
)
def ask(self, question: str, correlation_id: str, language: str = "en-GB") -> GroundedAnswer: