From 8c27c302f7b8481e121999c83e779fe7e2fd8709 Mon Sep 17 00:00:00 2001 From: Dotty Dotter Date: Fri, 10 Apr 2026 10:22:36 +0200 Subject: [PATCH] #47: Fallback-Notiz bei nicht-auffindbarem Zitat + Year-Suffix-Fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wenn search_for den Zitat-Text in keiner Seite findet (Pre-#60 halluzinierte Snippets die nie im PDF standen), wird jetzt statt stilles Nicht-Highlighting eine sichtbare FreeText-Annotation am Seitenkopf platziert: "Textstelle nicht im Dokument auffindbar — das Zitat wurde möglicherweise vom LLM paraphrasiert." Damit versteht der User sofort warum kein Gelb-Highlighting da ist. Die echte Lösung ist Re-Analyse mit der neuen Pipeline (reconstruct_ zitate erzeugt verifizierte Zitate), aber bis dahin ist die Notiz der ehrliche UX-Fallback. Tests: 194/194 grün. Refs: #47 --- app/embeddings.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/embeddings.py b/app/embeddings.py index efbdb4a..ff82426 100644 --- a/app/embeddings.py +++ b/app/embeddings.py @@ -648,17 +648,35 @@ def render_highlighted_page(programm_id: str, seite: int, query: str) -> Optiona target_page_idx = i break - # Volles PDF mit Highlight-Annotation statt Single-Page-Extract. - # Der Browser öffnet das vollständige Wahlprogramm; das Frontend - # hängt #page=N an die URL, sodass direkt zur Fundstelle gescrollt - # wird. Kontext des Programms bleibt erhalten. + # Volles PDF mit Highlight-Annotation. Der Browser öffnet das + # vollständige Wahlprogramm; das Frontend hängt #page=N an die URL. + page = src[target_page_idx] if needle and rects: - page = src[target_page_idx] for rect in rects: annot = page.add_highlight_annot(rect) if annot is not None: annot.set_colors(stroke=(1.0, 0.93, 0.0)) # gelb annot.update() + elif needle: + # Kein Match — halluziniertes Zitat aus Pre-#60-Assessment. + # Sichtbare Notiz-Annotation am Seitenkopf, damit der User + # versteht warum nichts markiert ist. + note_rect = fitz.Rect(20, 20, 400, 55) + note_text = ( + "Textstelle nicht im Dokument auffindbar — " + "das Zitat wurde möglicherweise vom LLM paraphrasiert. " + "Eine Re-Analyse des Antrags würde verifizierte Zitate erzeugen." + ) + annot = page.add_freetext_annot( + note_rect, + note_text, + fontsize=9, + fontname="helv", + text_color=(0.5, 0.2, 0.0), + fill_color=(1.0, 0.95, 0.8), + ) + if annot is not None: + annot.update() return src.tobytes(), target_page_idx + 1 finally: