2026-04-13 14:03:41 +02:00
|
|
|
|
---
|
2026-04-20 14:25:18 +02:00
|
|
|
|
description: Perfeziona i chunk di un documento (verifica, dry-run, fix, ri-verifica) e li prepara per la vettorizzazione.
|
2026-04-13 14:03:41 +02:00
|
|
|
|
allowed-tools: Read Bash Grep
|
|
|
|
|
|
argument-hint: <stem>
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2026-04-20 14:25:18 +02:00
|
|
|
|
## Passo 0 — Verifica fresca
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-20 14:25:18 +02:00
|
|
|
|
Esegui sempre `verify_chunks.py` per un report aggiornato:
|
2026-04-15 11:39:02 +02:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-04-20 14:25:18 +02:00
|
|
|
|
source .venv/bin/activate && python chunks/verify_chunks.py --stem $ARGUMENTS
|
2026-04-15 11:39:02 +02:00
|
|
|
|
```
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
Leggi il report appena generato:
|
|
|
|
|
|
|
|
|
|
|
|
!`python3 -c "
|
|
|
|
|
|
import json, sys
|
|
|
|
|
|
try:
|
2026-04-20 14:25:18 +02:00
|
|
|
|
r = json.load(open('chunks/$ARGUMENTS/report.json'))
|
2026-04-15 11:39:02 +02:00
|
|
|
|
v = r.get('verdict','?')
|
|
|
|
|
|
s = r.get('stats', {})
|
|
|
|
|
|
t = r.get('thresholds', {})
|
|
|
|
|
|
print(f'Verdict: {v}')
|
|
|
|
|
|
print(f'Totale chunk: {s.get(\"total\",\"?\")} | OK: {s.get(\"ok\",\"?\")}')
|
|
|
|
|
|
print(f'Min: {s.get(\"min_chars\",\"?\")} char Max: {s.get(\"max_chars\",\"?\")} char Media: {s.get(\"avg_chars\",\"?\")} char')
|
|
|
|
|
|
print(f'Soglie: MIN={t.get(\"min_chars\",200)} MAX={t.get(\"max_chars\",800)}')
|
|
|
|
|
|
bl = r.get('blockers', {})
|
|
|
|
|
|
wa = r.get('warnings', {})
|
|
|
|
|
|
for cat, label in [('empty','Vuoti'), ('no_prefix','Senza prefisso'), ('incomplete','Frasi spezzate')]:
|
|
|
|
|
|
items = bl.get(cat, [])
|
|
|
|
|
|
if items:
|
|
|
|
|
|
print(f' 🔴 {label}: {len(items)}')
|
|
|
|
|
|
for c in items[:3]:
|
|
|
|
|
|
print(f' [{c[\"chunk_id\"]}] {c[\"n_chars\"]} char → {c[\"last_text\"][-60:]!r}')
|
2026-04-20 14:25:18 +02:00
|
|
|
|
for cat, label in [('too_short','Troppo corti'), ('too_long','Troppo lunghi'), ('incomplete_math','Math incompleto')]:
|
2026-04-15 11:39:02 +02:00
|
|
|
|
items = wa.get(cat, [])
|
|
|
|
|
|
if items:
|
|
|
|
|
|
print(f' 🟡 {label}: {len(items)}')
|
|
|
|
|
|
for c in items[:3]:
|
|
|
|
|
|
print(f' [{c[\"chunk_id\"]}] {c[\"n_chars\"]} char')
|
|
|
|
|
|
except Exception as e: print(f'ERRORE lettura report: {e}')
|
|
|
|
|
|
" 2>/dev/null`
|
|
|
|
|
|
|
|
|
|
|
|
---
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
|
|
|
|
|
## Se verdict == "ok"
|
|
|
|
|
|
|
2026-04-20 14:25:18 +02:00
|
|
|
|
✅ Nessun problema bloccante. Comunica:
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
|
|
|
|
|
```
|
2026-04-20 14:25:18 +02:00
|
|
|
|
✅ Chunk pronti — procedi con la vettorizzazione:
|
2026-05-11 15:58:54 +02:00
|
|
|
|
python ingestion/ingest.py --stem $ARGUMENTS
|
2026-04-13 14:03:41 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-04-20 14:25:18 +02:00
|
|
|
|
Se ci sono solo 🟡, spiega brevemente i warning e chiedi se l'utente vuole risolverli prima o procedere.
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
---
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
## Se verdict == "warnings_only" o "blocked"
|
|
|
|
|
|
|
|
|
|
|
|
### Passo 1 — Dry-run
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-04-20 14:25:18 +02:00
|
|
|
|
source .venv/bin/activate && python chunks/fix_chunks.py --stem $ARGUMENTS --dry-run
|
2026-04-13 14:03:41 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
Spiega in italiano ogni operazione pianificata:
|
2026-04-20 14:25:18 +02:00
|
|
|
|
|
|
|
|
|
|
- **rimuovi chunk vuoti** — privi di testo, non contribuiscono al retrieval
|
|
|
|
|
|
- **aggiungi prefisso** — `[sezione > titolo]` fornisce contesto all'embedding; senza, il chunk è decontestualizzato
|
2026-04-15 11:39:02 +02:00
|
|
|
|
- **fondi incompleti** — frase spezzata a metà: il chunk corrente e il successivo formano una frase unica
|
2026-04-20 14:25:18 +02:00
|
|
|
|
- **fondi troppo corti** — sotto MIN_CHARS: troppo brevi per portare informazione semantica utile
|
|
|
|
|
|
- **spezza troppo lunghi** — sopra MAX_CHARS×1.5: troppo densi, degradano la precision del retrieval
|
2026-04-15 11:39:02 +02:00
|
|
|
|
|
|
|
|
|
|
Se ci sono solo 🟡 (nessun 🔴), informa che si può procedere anche senza fix e chiedi la preferenza.
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
### Passo 2 — Conferma
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
Chiedi: **"Applico le correzioni?"**
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
Applica solo su risposta affermativa esplicita.
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
### Passo 3 — Applica
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-04-20 14:25:18 +02:00
|
|
|
|
source .venv/bin/activate && python chunks/fix_chunks.py --stem $ARGUMENTS
|
2026-04-13 14:03:41 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
### Passo 4 — Ri-verifica automatica
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-15 11:39:02 +02:00
|
|
|
|
```bash
|
2026-04-20 14:25:18 +02:00
|
|
|
|
source .venv/bin/activate && python chunks/verify_chunks.py --stem $ARGUMENTS
|
2026-04-15 11:39:02 +02:00
|
|
|
|
```
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
2026-04-20 14:25:18 +02:00
|
|
|
|
Leggi il nuovo `chunks/$ARGUMENTS/report.json` e riporta:
|
2026-04-15 11:39:02 +02:00
|
|
|
|
- Nuovo verdict
|
|
|
|
|
|
- Delta chunk (N prima → N dopo)
|
|
|
|
|
|
- Problemi residui se presenti
|
|
|
|
|
|
|
|
|
|
|
|
### Passo 5 — Conclusione
|
|
|
|
|
|
|
|
|
|
|
|
Se verdict finale è `ok` o `warnings_only` senza 🔴:
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
|
|
|
|
|
```
|
2026-04-20 14:25:18 +02:00
|
|
|
|
✅ Chunk pronti in chunks/$ARGUMENTS/chunks.json
|
2026-04-13 14:03:41 +02:00
|
|
|
|
Procedi con la vettorizzazione:
|
2026-05-11 15:58:54 +02:00
|
|
|
|
python ingestion/ingest.py --stem $ARGUMENTS
|
2026-04-13 14:03:41 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-04-20 14:25:18 +02:00
|
|
|
|
Se rimangono 🔴 dopo il fix (testo non spezzabile o struttura anomala nel sorgente):
|
2026-04-13 14:03:41 +02:00
|
|
|
|
|
|
|
|
|
|
```
|
2026-04-15 11:39:02 +02:00
|
|
|
|
🔴 X problemi residui non risolvibili automaticamente.
|
2026-04-20 14:25:18 +02:00
|
|
|
|
Torna a conversione/$ARGUMENTS/clean.md e correggi manualmente le sezioni indicate,
|
2026-04-15 11:39:02 +02:00
|
|
|
|
poi riesegui nell'ordine:
|
2026-04-20 14:25:18 +02:00
|
|
|
|
python chunks/chunker.py --stem $ARGUMENTS --force
|
|
|
|
|
|
python chunks/verify_chunks.py --stem $ARGUMENTS
|
2026-04-13 14:03:41 +02:00
|
|
|
|
```
|