docs/fix: aggiorna README e fix ingest per embedding robusto

README riscritto per rispecchiare la pipeline attuale:
- rimossi riferimenti a Stage 1, md_optimizer, fix_chunks
- pipeline semplificata: MinerU .md → chunker → ingest → rag
- tabelle parametri aggiornate (SKIP_HEADINGS, SKIP_PRE_HEADING,
  MERGE_SHORT_PARAGRAPHS, EMBED_MAX_CHARS al posto dei vecchi)
- struttura repo corretta

ingest.py: strip tag HTML ed entità prima dell'embedding per evitare
HTTP 500 da Ollama su chunk con tabelle HTML grezze; aggiunto
EMBED_MAX_CHARS (default 6000) in config.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 14:29:06 +02:00
parent c93e2e8494
commit 98a8eaa9fb
3 changed files with 112 additions and 264 deletions
+15 -2
View File
@@ -21,6 +21,7 @@ Uso:
import argparse
import json
import re
import sys
import time
import urllib.error
@@ -37,16 +38,28 @@ CHUNKS_DIR = project_root / "chunks"
CHROMA_DIR = project_root / "chroma_db"
sys.path.insert(0, str(project_root))
from config import EMBED_MODEL, OLLAMA_URL # noqa: E402
from config import EMBED_MODEL, EMBED_MAX_CHARS, OLLAMA_URL # noqa: E402
EMBED_ENDPOINT = f"{OLLAMA_URL}/api/embeddings"
# ─── Ollama ────────────────────────────────────────────────────────────────────
_HTML_TAG = re.compile(r"<[^>]+>")
_HTML_ENT = re.compile(r"&[a-zA-Z0-9#]+;")
def _clean_for_embed(text: str) -> str:
"""Rimuove tag HTML ed entità prima dell'embedding; tronca al limite del modello."""
text = _HTML_TAG.sub(" ", text)
text = _HTML_ENT.sub(" ", text)
text = re.sub(r" {2,}", " ", text)
return text[:EMBED_MAX_CHARS]
def embed(text: str, model: str) -> list[float]:
"""Chiama Ollama /api/embeddings e ritorna il vettore."""
payload = json.dumps({"model": model, "prompt": text}).encode()
payload = json.dumps({"model": model, "prompt": _clean_for_embed(text)}).encode()
req = urllib.request.Request(
EMBED_ENDPOINT,
data=payload,