M17: ground knowledge and integration evidence

This commit is contained in:
NuklearRabbit
2026-08-10 12:27:17 +02:00
parent 686795a452
commit 8030753dbc
15 changed files with 480 additions and 74 deletions
+17 -3
View File
@@ -17,9 +17,10 @@ _GROUNDED_ANSWERABILITY = {"answerable", "partially_answerable"}
_LEAD_ANSWER_TEMPLATE = {
"en-GB": 'Per "{title}": {excerpt}',
"nl-BE": 'Volgens "{title}": {excerpt}',
"fr-BE": 'Selon « {title} » : {excerpt}',
"fr-BE": "Selon « {title} » : {excerpt}",
}
_DEFAULT_LANGUAGE = "en-GB"
_MAX_SOURCE_CARDS = 3
_DOMAIN_CONCEPTS: dict[str, tuple[str, ...]] = {
"damage": ("damage", "damaged", "schade", "beschadigd", "dommage", "endommagé"),
@@ -48,14 +49,26 @@ def _question_concepts(question: str) -> set[str]:
def _deduplicate_sources(sources: list[SourceCard]) -> list[SourceCard]:
seen: set[tuple[str, str]] = set()
"""Collapse duplicate chunks and re-uploaded document versions.
RAGcore document/version UUIDs change across uploads, so they are not useful
deduplication keys. Human-visible citation identity is the normalized title,
section and excerpt.
"""
seen: set[tuple[str, str, str]] = set()
unique: list[SourceCard] = []
for source in sources:
key = (source.document_id, source.section)
key = (
source.title.strip().casefold(),
source.section.strip().casefold(),
" ".join(source.excerpt.split()).casefold(),
)
if key in seen:
continue
seen.add(key)
unique.append(source)
if len(unique) == _MAX_SOURCE_CARDS:
break
return unique
@@ -193,6 +206,7 @@ class RAGcoreKnowledgeProvider:
)
for citation in citations.values()
]
sources = _deduplicate_sources(sources)
answerability = body.get("answerability", "not_answerable")
is_grounded = answerability in _GROUNDED_ANSWERABILITY and sources
evidence_state: EvidenceState = "grounded" if is_grounded else "insufficient"