docs: comprehensive session handover with full roadmap (Blocks A-G)

Complete instructions for next session including:
- Current quality metrics per document type
- Prioritized action items (NIST fix, citation backfill, missing laws)
- Full Block E-G roadmap with details
- All critical files, DB state, test commands
- Known issues (3 lost NIST PDFs, frontend 500s, D5 script safety)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-02 22:30:50 +02:00
parent ff21bc258a
commit 97a7f6f264
+231 -104
View File
@@ -1,139 +1,257 @@
# Session-Uebergabe: Strukturelles Chunking + Qualitaetssicherung # Session-Instruktionen: Pipeline-Qualitaet + Gesetze
**Datum:** 2026-05-02 **Datum:** 2026-05-02
**Uebergeben von:** Pipeline-Session (01.05 - 02.05.2026, ~20h) **Fuer:** Naechste Claude-Session
**Repo:** breakpilot-core (~/Projekte/breakpilot-core)
## Was wurde erledigt ---
## ZUSAMMENFASSUNG: WO STEHEN WIR
### Was fertig ist (Bloecke A-D)
| Block | Was | Status | | Block | Was | Status |
|-------|-----|--------| |-------|-----|--------|
| **D2** | RAG-Service speichert section/section_title/paragraph/page in Qdrant | ✅ | | Pass 0b | 151.675 atomare Controls, dedupliziert, mit Dependencies | ✅ |
| **D3** | Control Generator nutzt strukturelle Metadaten in source_citation | ✅ | | Block A | v1 Tag, Healthcheck, Textkorrektur, Dependencies (15.291) | ✅ |
| **D4** | BGB § 312k Validierung — kritischen Overlap-Bug gefunden + gefixt | ✅ | | Block B | Review-Verify (67k Paare, 43.527 DUPLIKAT via Haiku) | ✅ |
| **D5** | 430/436 Dokumente re-ingestiert (alle 6 Collections) | ✅ | | Block C | Adversarial Tests (30), Regression Harness (387 Tests) | ✅ |
| **HTML-Fix** | Stripping + Charset-Erkennung (ISO-8859-1), Opening-Block-Tags | ✅ | | **Block D** | **Strukturelles Chunking End-to-End** | ✅ |
| **EUR-Lex** | 20 EU-Verordnungen als HTML ersetzt (DSGVO: 0%→92%) | ✅ |
| **pdfplumber** | Als PDF-Backend hinzugefuegt + PDF_EXTRACTION_BACKEND=auto | ✅ |
| **NIST Regex** | Nummerierte Abschnitte (1.1), Control-IDs (AC-1, PO.1) | ✅ |
| **3 fehlende PDFs** | EDPB Controller/Processor, GL 7, RTBF hochgeladen | ✅ |
| **Frontend-Bug** | requirements.map TypeError in Compliance Admin gefixt | ✅ |
| **Qualitaetsreport** | 500 Controls geprueft: 13% OK, 41% Article-Mismatch | ✅ |
## Commits (breakpilot-core) ### Block D Details (diese Session, 01-02.05.2026)
``` - **D1:** Embedding-Service extrahiert section/section_title/paragraph/paragraph_num/page
93099b2 feat(pipeline): structural metadata end-to-end (Blocks D2-D4) - **D2:** RAG-Service speichert diese Felder im Qdrant-Payload
ddad58f fix(rag): strip HTML tags before chunking + D5 re-ingestion scripts - **D3:** Control Generator liest sie fuer source_citation (section > article > section_title Prioritaet)
a459636 fix(rag): HTML charset detection + opening block tag newlines - **D4:** BGB § 312k Validierung — **kritischen Bug gefunden:** Phase-3-Overlap zerstoerte den [§]-Prefix. Gefixt.
75dda9a feat(embedding): add pdfplumber backend for multi-column PDF extraction - **D5:** 430 von 436 Dokumenten re-ingestiert (alle 6 Compliance-Collections, ~70.000 Chunks)
41183ff fix(docker): set PDF_EXTRACTION_BACKEND to auto (was pymupdf) - **HTML-Fix:** Stripping + Charset-Erkennung (ISO-8859-1) + Opening-Block-Tags → HTML: 0%→97.6% Section-Rate
5a6e588 docs: update session handover - **EUR-Lex:** 20 EU-Verordnungen als HTML ersetzt (DSGVO: 0%→92%, AI Act: 33%→55%)
3009f3d feat(embedding): add NIST/ENISA/standard section numbering to chunker - **pdfplumber:** Als PDF-Backend, PDF_EXTRACTION_BACKEND=auto in docker-compose.yml
``` - **NIST Regex:** Nummerierte Abschnitte (1.1 Title), Control-IDs (AC-1, PO.1)
- **Frontend-Bug:** requirements.map TypeError in breakpilot-compliance gefixt
## Aktuelle Qualitaet ### Aktuelle Qualitaet (Stand 02.05.2026)
### Section-Rate nach Dateityp | Dokumenttyp | Section-Rate | Status |
| Typ | Avg Section-Rate | Anmerkung | |-------------|-------------|--------|
|-----|-----------------|-----------| | DE Gesetze (TXT) | **79-100%** | ✅ Exzellent |
| TXT (DE Gesetze) | **79%** | Exzellent | | HTML (EUR-Lex + gesetze-im-internet) | **40-99%** | ✅ Gut |
| HTML (EUR-Lex + gesetze-im-internet) | **56%** | Gut (Praambeln haben keine Artikel) | | PDF (EDPB/DSK Leitlinien) | **60-98%** | Gut |
| PDF (EDPB/DSK Leitlinien) | **60-98%** | Gut | | PDF (NIST/BSI/ENISA) | **0-10%** | ❌ OFFEN |
| PDF (EU-Amtsblatt) | N/A | Durch EUR-Lex HTML ersetzt | | TXT (OWASP) | **0%** | ❌ OFFEN |
| PDF (NIST/BSI) | **0-10%** | Problematisch — siehe unten | | Legal Templates (JSON/MD) | **0%** | ⚪ Erwartet |
| TXT (OWASP) | **0%** | Eigenes Format, kein §/Artikel |
| Legal Templates (JSON/MD) | **0%** | Erwartet — keine juristische Struktur |
### Qualitaetsreport (500 Controls Stichprobe) **Qualitaetsreport (500 Controls Stichprobe):**
- **13% vollstaendig korrekt** (Artikel gefunden, passt zum Chunk) - 13% vollstaendig korrekt
- **41% Article-nicht-im-Source-Text** — Hauptursache: Controls aus alten kaputten PDF-Chunks generiert - 41% Article-nicht-im-Source-Text (Controls aus alten kaputten Chunks)
- **7% kein Article in Citation** - 7% kein Article in Citation
- **39% sonstige** (Regulation gefunden aber Section-Matching-Issues) - 39% sonstige Matching-Issues
## Offene Probleme (Naechste Session) ---
### 1. NIST/ENISA/BSI PDFs (KRITISCH) ## WAS ALS NAECHSTES ZU TUN IST (PRIORISIERT)
**Problem:** pypdf UND pdfplumber brechen den Text mehrspaliger Dokumente. Section-Nummern landen nicht am Zeilenanfang. Regex-Erweiterung hat nicht geholfen. ### PRIO 1: NIST/ENISA/BSI/OWASP Dokumente sauber ingestieren
**3 NIST PDFs waren kurzzeitig verloren** (Chunks geloescht, Upload Timeout). Wiederherstellung aus MinIO wurde gestartet. **Problem:** pypdf UND pdfplumber brechen den Text mehrspaliger PDFs. Die Regex-Erweiterung fuer NIST-Nummern hat nicht geholfen weil die Nummern nach der PDF-Extraktion gebrochen sind ("1 . 1" statt "1.1", "AC - 1" statt "AC-1").
**Loesung (priorisiert):** **3 grosse NIST-PDFs fehlen in Qdrant** (Chunks geloescht, Upload 500-Error):
- NIST_SP_800_53r5.pdf (6 MB) — 0 Chunks
- nist_sp_800_82r3.pdf (8.5 MB) — 0 Chunks
- nist_sp_800_160v1r1.pdf (8.2 MB) — 0 Chunks
Die Originale sind sicher in MinIO.
1. **Text-Normalisierung** nach PDF-Extraktion: **Loesungsansaetze (in dieser Reihenfolge testen):**
1. **Text-Normalisierung** nach PDF-Extraktion in `embedding-service/main.py`:
```python ```python
def _normalize_multicolumn_text(text): def _normalize_pdf_text(text: str) -> str:
# "1 . 1" → "1.1", "AC - 1" → "AC-1", "GV . OC - 01" → "GV.OC-01" """Fix broken spacing from pypdf/pdfplumber multi-column extraction."""
text = re.sub(r'(\d+)\s*\.\s*(\d+)', r'\1.\2', text) # "1 . 1" → "1.1"
text = re.sub(r'([A-Z]{2})\s*[-\.]\s*([A-Z]{2})\s*-\s*(\d+)', r'\1.\2-\3', text) text = re.sub(r'(\d+)\s+\.\s+(\d+)', r'\1.\2', text)
# "AC - 1" → "AC-1"
text = re.sub(r'([A-Z]{2})\s*-\s*(\d+)', r'\1-\2', text) text = re.sub(r'([A-Z]{2})\s*-\s*(\d+)', r'\1-\2', text)
# "GV . OC - 01" → "GV.OC-01"
text = re.sub(r'([A-Z]{2})\s*\.\s*([A-Z]{2})\s*-\s*(\d+)', r'\1.\2-\3', text)
return text return text
``` ```
Einfuegen in `extract_pdf_pdfplumber()` und `extract_pdf_pypdf()` vor dem Return.
2. **Fehlende Regex-Patterns:** 2. **Fehlende Regex-Patterns** in `_LEGAL_SECTION_RE`:
- `GV.OC-01` (NIST CSF 2.0): `[A-Z]{2}\.[A-Z]{2}-\d{2}` - `GV.OC-01` (NIST CSF 2.0): `[A-Z]{2}\.[A-Z]{2}-\d{2}`
- `A01:2021` (OWASP): `A\d{2}(?::\d{4})?` - `A01:2021` (OWASP Top 10): `A\d{2}(?::\d{4})?`
- `AC-1(1)` (NIST Enhancements): `[A-Z]{2}-\d+\(\d+\)` - `AC-1(1)` (NIST Enhancements): `[A-Z]{2}-\d+\(\d+\)`
3. **Alternative: HTML von NIST/ENISA-Websites** (wie EUR-Lex-Ansatz): 3. **HTML-Download** von NIST/ENISA-Websites (wie bei EUR-Lex):
- NIST: csrc.nist.gov bietet HTML-Versionen - NIST: `https://csrc.nist.gov/pubs/sp/800/53/r5/upd1/final` (HTML-Version)
- ENISA: enisa.europa.eu bietet HTML-Versionen - ENISA: `https://www.enisa.europa.eu/publications/` (HTML)
- Bester Ansatz fuer maximale Qualitaet - Eigenes Script analog zu `control-pipeline/scripts/replace_eu_pdfs_with_html.py`
4. **D5-Script fixen:** Upload ZUERST, Delete NUR bei Erfolg (verhindert Datenverlust bei Timeout) 4. **D5-Script fixen:** `control-pipeline/scripts/reingest_d5.py` Zeile ~170:
**KRITISCH:** Aktuell: Delete-THEN-Upload. Wenn Upload fehlschlaegt, sind Chunks weg.
Fix: Upload ZUERST in temp-Collection oder mit neuem document_id, DANN alte loeschen.
### 2. Citation-Backfill (WICHTIG) **Betroffene Dokumente (105 PDFs mit <50% Section-Rate):**
Vollstaendige Liste in `eu_pdfs_to_replace.json` im Repo-Root.
**Problem:** 41% der Controls haben falsche Article-Citations (aus alten kaputten PDF-Chunks). ### PRIO 2: Citation-Backfill
**Loesung:** Nachtraeglicher Abgleich: **Problem:** 41% der Controls haben falsche source_citation.article weil sie aus alten (kaputten) Chunks generiert wurden. Die Chunks sind jetzt sauber, aber die Controls tragen noch die alten Citations.
1. Fuer jeden Control mit source_citation: Regulation in Qdrant suchen
2. Chunks mit passender Section finden
3. source_citation.article aktualisieren wenn besserer Match
**Script:** `control-pipeline/scripts/quality_report.py` existiert bereits als Basis. **Loesung:**
1. Fuer jeden Control: `source_citation.source` → regulation_code ermitteln
2. In Qdrant nach Chunks mit diesem regulation_code + passender section suchen
3. Wenn Match: `source_citation.article` und `source_citation.paragraph` aktualisieren
4. Wenn kein Match: als "needs_regeneration" markieren
### 3. Fehlende Gesetze (Block E3) **Basis-Script existiert:** `control-pipeline/scripts/quality_report.py`
Muss erweitert werden um UPDATE statt nur Report.
- BEG IV (Viertes Buerokratieentlastungsgesetz, 2024) **Bestehender Backfill-Service:** `control-pipeline/services/citation_backfill.py`
- Weitere aus `project_missing_legal_sources.md` Hat 3-Tier-Matching: Hash → Regex → LLM. Muss fuer neues Chunk-Format angepasst werden.
### 4. Frontend 500-Fehler ### PRIO 3: Fehlende Gesetze ingestieren (Block E)
Das Compliance-Frontend (macmini:3007) zeigt noch 500-Fehler bei: **Neue Gesetze (noch nicht im RAG):**
- **BEG IV** (Viertes Buerokratieentlastungsgesetz, BGBl. 2024 I Nr. 323) — verkuerzte Aufbewahrungsfristen
- ArbZG, MuSchG, NachwG, MiLoG, GmbHG, AktG, InsO
- Gesetz fuer faire Verbrauchervertraege
- CSRD, EU Taxonomy, CSDDD, eIDAS 2.0
- CH: OR, DSV, ISG, ArG
- AT: ArbVG, AngG, AZG, GmbHG-AT, NISG
**Veraltete Gesetze (aktualisieren):**
- BGB: § 312k Kuendigungsbutton seit 01.07.2022 (existiert jetzt als TXT, sollte aktuell sein)
- TMG → ersetzen durch TDDDG
- GwG aktualisieren (Aenderungen 2024)
- HGB aktualisieren (MoPeG 2024)
**Quellen:**
- gesetze-im-internet.de (DE-Gesetze, HTML, charset beachten!)
- eur-lex.europa.eu (EU-Recht, HTML via CELEX-Nummer)
- fedlex.admin.ch (CH-Recht)
- ris.bka.gv.at (AT-Recht)
**Lizenzregeln (KRITISCH — immer pruefen!):**
- Rule 1 (Gesetze, Urteile): Volltext erlaubt
- Rule 2 (CC-BY): Mit Zitation erlaubt
- Rule 3 (Behoerden-Presse, proprietaer): NUR eigene Formulierungen
- VERBOTEN: ISO, beck-online, juris, DIN
### PRIO 4: Frontend 500-Fehler untersuchen
macmini:3007/sdk/control-library zeigt noch 500-Fehler bei API-Aufrufen:
- /controls, /canonical, /control-instances, /findings, /vendors, /contracts - /controls, /canonical, /control-instances, /findings, /vendors, /contracts
Der `requirements.map` TypeError ist gefixt, aber die API-500er deuten auf Backend-Probleme hin die separat untersucht werden muessen. Der `requirements.map` TypeError ist gefixt (commit fe6764d im compliance-repo).
Die 500er koennten vom Compliance-Backend (Port 8002) kommen — separat pruefen.
## Kritische Dateien ---
| Datei | Repo | Aenderung | ## GESAMTPLAN (Bloecke A-G)
|-------|------|-----------|
| `embedding-service/main.py` | core | Overlap-Fix, pdfplumber, NIST-Regex |
| `rag-service/api/documents.py` | core | D2 Payloads + HTML-Stripping |
| `rag-service/html_utils.py` | core | HTML-Strip + Charset (NEU) |
| `rag-service/embedding_client.py` | core | ChunkResult (D2) |
| `control-pipeline/services/rag_client.py` | core | page-Feld (D3) |
| `control-pipeline/services/control_generator.py` | core | section-Prio + page (D3) |
| `control-pipeline/scripts/reingest_d5.py` | core | Re-Ingestion Script |
| `control-pipeline/scripts/replace_eu_pdfs_with_html.py` | core | EUR-Lex Replacement |
| `control-pipeline/scripts/quality_report.py` | core | Qualitaetstest |
| `docker-compose.yml` | core | PDF_EXTRACTION_BACKEND=auto |
| `canonical_control_service.py` | compliance | _ensure_list Fix |
| `ControlDetail.tsx` | compliance | Array.isArray Guard |
## DB-Stand ### ✅ ERLEDIGT
- **Block A:** v1 Abschluss (Healthcheck, Dependencies, v1 Tag)
- **Block B:** Review-Verify (67k Paare)
- **Block C:** Tests (Adversarial + Regression)
- **Block D:** Strukturelles Chunking (D1-D5)
| Collection | Chunks | Dokumente | ### 🔄 IN ARBEIT
|-----------|--------|-----------| - **Block D5+:** NIST/ENISA/BSI Dokumente (Prio 1 oben)
| bp_compliance_ce | ~23.600 | ~55 | - **Block E1:** EU-Verordnungen als HTML (20 von ~50 erledigt)
| bp_compliance_gesetze | ~32.000 | ~98 |
| bp_compliance_datenschutz | ~13.000 | ~107 |
| bp_dsfa_corpus | ~320 | ~20 |
| bp_legal_templates | ~1.460 | ~100 |
| **Gesamt** | **~70.000** | **~430** |
## Tests ### 📋 AUSSTEHEND
**Block E: Gesetze aktualisieren + neue ingestieren**
- E1: Veraltete Quellen aktualisieren (BGB, TMG→TDDDG, GwG, HGB)
- E2: Fehlende DE-Gesetze (ArbZG, MuSchG, NachwG, MiLoG, etc.)
- E3: Fehlende EU-Regulierung (CSRD, EU Taxonomy, CSDDD, eIDAS 2.0)
- E4: Fehlende Standards lizenzgerecht (GoBD, BAIT/VAIT, PCI DSS Rule 3)
- E5: Urteils-Control-Packs (Google Fonts, CNIL, Planet49, Schrems II — 12 Packs)
- E6: CH + AT Gesetze (OR, DSV, ISG, ArG, ArbVG, AngG, etc.)
- E7: Lizenzpruefung bei JEDER neuen Quelle
**Block F: Hardcoded Knowledge Migration (bis Juli 2026)**
- F1: legal_basis_validator.py → Control Library
- F2: 5 weitere Dateien migrieren (service_registry, mandatory_content_checker, etc.)
- F3: Keyword-Synonyme durch LLM ersetzen
**Block G-pre: Master Control Konsolidierung**
- G-pre1: Object-Normalisierung (128k → 15-25k Gruppen)
- G-pre2: Control-Ketten als Master Controls
- G-pre3: Master Control API
**Block G: Compliance Execution Layer (langfristig)**
- G1: Decision Trace
- G2: Compliance Git
- G3: Full Decision Memory
- G4: Pre-Deployment Enforcement
---
## KRITISCHE DATEIEN
### Hauptaenderungen dieser Session (breakpilot-core)
| Datei | Was |
|-------|-----|
| `embedding-service/main.py` | Overlap-Bug-Fix (Phase 3), pdfplumber-Backend, NIST-Regex |
| `embedding-service/requirements.txt` | pdfplumber>=0.11.0 hinzugefuegt |
| `embedding-service/test_d4_bgb.py` | 18 BGB-Validierungstests |
| `embedding-service/tests/fixtures/bgb_312_excerpt.txt` | BGB §§ 312-312k Testfixture |
| `rag-service/api/documents.py` | D2 Payload-Felder + HTML-Erkennung + Encoding |
| `rag-service/html_utils.py` | HTML-Strip + Charset (NEU) |
| `rag-service/embedding_client.py` | ChunkResult Dataclass (D2) |
| `rag-service/tests/` | 32 Tests (D2 + HTML) |
| `control-pipeline/services/rag_client.py` | page: Optional[int] in RAGSearchResult |
| `control-pipeline/services/control_generator.py` | section>article>section_title Prio + page |
| `control-pipeline/services/decomposition_pass.py` | Seitenzahl in _format_citation |
| `control-pipeline/tests/test_d3_metadata.py` | 16 D3-Tests |
| `control-pipeline/scripts/reingest_d5.py` | Re-Ingestion Script (MUSS GEFIXT WERDEN: Upload-before-Delete) |
| `control-pipeline/scripts/reingest_d5_config.py` | Config + Helpers |
| `control-pipeline/scripts/replace_eu_pdfs_with_html.py` | EUR-Lex HTML Replacement |
| `control-pipeline/scripts/quality_report.py` | E2E Qualitaetstest (500 Controls) |
| `docker-compose.yml` | PDF_EXTRACTION_BACKEND=auto |
### Aenderungen in breakpilot-compliance
| Datei | Was |
|-------|-----|
| `backend-compliance/compliance/services/canonical_control_service.py` | _ensure_list() fuer JSONB-Arrays |
| `admin-compliance/app/sdk/control-library/components/ControlDetail.tsx` | Array.isArray() Guard |
---
## DB-STAND
### Qdrant (Mac Mini, Port 6333)
| Collection | Chunks | Dokumente | Section-Rate |
|-----------|--------|-----------|-------------|
| bp_compliance_ce | ~23.600 | ~55 | 47% |
| bp_compliance_gesetze | ~32.000 | ~98 | 86% |
| bp_compliance_datenschutz | ~13.000 | ~107 | 36% |
| bp_dsfa_corpus | ~320 | ~20 | 60% |
| bp_legal_templates | ~1.460 | ~100 | 7% |
| **Gesamt** | **~70.000** | **~430** | **62%** |
### PostgreSQL (Mac Mini, Port 5432)
| Tabelle | Anzahl | Schema |
|---------|--------|--------|
| canonical_controls | ~291.000 | compliance |
| obligation_candidates | ~234.000 | compliance |
| control_dependencies | ~15.300 | compliance |
### MinIO (Hetzner, nbg1.your-objectstorage.com)
Alle Originaldokumente sind sicher in MinIO, Bucket: `breakpilot-rag`.
Pfad-Format: `{data_type}/{bundesland}/{use_case}/{year}/{filename}`
---
## TESTS AUSFUEHREN
```bash ```bash
# Embedding-Service (58 Tests) # Embedding-Service (58 Tests)
@@ -145,16 +263,25 @@ cd rag-service && PYTHONPATH=. python3 -m pytest tests/ -v
# Control-Pipeline (387 Tests) # Control-Pipeline (387 Tests)
PYTHONPATH=control-pipeline python3 -m pytest control-pipeline/tests/ -v PYTHONPATH=control-pipeline python3 -m pytest control-pipeline/tests/ -v
# Qualitaetsreport (500 Controls) # Qualitaetsreport (500 Controls gegen Qdrant)
python3 control-pipeline/scripts/quality_report.py --db-host macmini --sample 500 python3 control-pipeline/scripts/quality_report.py --db-host macmini --sample 500
``` ```
## Empfohlene Reihenfolge naechste Session ---
1. NIST-Wiederherstellung pruefen (3 PDFs aus MinIO) ## MEMORY-DATEIEN (LESEN!)
2. D5-Script fixen (Upload-before-Delete)
3. Text-Normalisierung fuer PDF-Extraktion Alle unter `/Users/benjaminadmin/.claude/projects/-Users-benjaminadmin-Projekte-breakpilot-core/memory/`:
4. NIST/ENISA HTML-Downloads (wie EUR-Lex) - `MEMORY.md` — Index aller Memories
5. Citation-Backfill fuer bestehende Controls - `project_structural_chunking.md` — Architektur-Entscheidung
6. Frontend 500-Fehler untersuchen - `project_control_pipeline_masterplan.md` — Gesamtplan A-G
7. BEG IV + fehlende Gesetze ingestieren - `feedback_batch_api_safety.md` — NIEMALS curl-Retry fuer Batch-Submits
- `feedback_legal_source_licensing.md` — Rule 1/2/3 Lizenzregeln
- `feedback_no_hardcoded_knowledge.md` — Kein hartkodiertes Rechtswissen
- `project_missing_legal_sources.md` — Fehlende Gesetze + 20 Urteile
- `project_test_strategy.md` — 4-Ebenen Teststrategie
## PLAN-DATEI
Vollstaendiger Masterplan: `/Users/benjaminadmin/.claude/plans/jazzy-snacking-creek.md`
Enthaelt Bloecke A-G mit allen Details.