feat(step-7,8): leggi modello da config.py, allinea EMBED_MODELS al README

- step-8/ingest.py: rimuove EMBED_MODEL e OLLAMA_URL hardcoded;
  li importa da step-9/config.py (fonte di verita unica)
- step-7/check_env.py: aggiorna EMBED_MODELS con tutti i modelli
  del README (aggiunge qwen3-embedding, nomic-embed-text-v2-moe,
  paraphrase-multilingual); mostra il modello configurato in config.py
  e verifica proprio quello, non un qualsiasi modello embedding
- step-8/README.md: creato
This commit is contained in:
2026-04-14 18:22:05 +02:00
parent 92182a2cd4
commit 05946bb93f
3 changed files with 145 additions and 37 deletions
+54 -15
View File
@@ -18,11 +18,36 @@ Uso:
import shutil
import subprocess
import sys
from pathlib import Path
# Modelli riconosciuti come embedding (basta che uno sia presente)
# Tutto il resto viene considerato LLM
EMBED_MODELS = ["bge-m3", "nomic-embed-text", "mxbai-embed-large", "all-minilm"]
# ─── Lista canonica di modelli embedding supportati ───────────────────────────
# Ordine: prima scelta → ultima scelta (come da README step-7)
EMBED_MODELS = [
"qwen3-embedding",
"nomic-embed-text-v2-moe",
"bge-m3",
"nomic-embed-text",
"mxbai-embed-large",
"paraphrase-multilingual",
"all-minilm",
]
def _is_embed(model_name: str) -> bool:
"""True se il modello è riconosciuto come embedding (lista canonica o keyword)."""
base = model_name.split(":")[0].lower()
return any(base == e or base.startswith(e) for e in EMBED_MODELS) or "embed" in base
# ─── Modelli configurati in step-9/config.py ─────────────────────────────────
# Per spostare config.py alla root: cambia solo la riga qui sotto.
sys.path.insert(0, str(Path(__file__).parent.parent / "step-9"))
try:
from config import EMBED_MODEL as CONFIGURED_EMBED, OLLAMA_MODEL as CONFIGURED_LLM
except Exception:
CONFIGURED_EMBED = None
CONFIGURED_LLM = None
REQUIRED_LIBS = ["chromadb"]
@@ -83,25 +108,39 @@ def _match(model_name: str, available: list[str]) -> str | None:
def check_embed_model(available: list[str]) -> bool:
"""Verifica che almeno un modello di embedding sia presente."""
for candidate in EMBED_MODELS:
found = _match(candidate, available)
"""Verifica che il modello di embedding configurato sia disponibile."""
if CONFIGURED_EMBED:
print(f" modello configurato (step-9/config.py): {CONFIGURED_EMBED}")
found = _match(CONFIGURED_EMBED, available)
if found:
print(f" modello embedding trovato: {found}")
print(f"✅ embedding disponibile: {found}")
return True
print(f"{CONFIGURED_EMBED} non trovato in Ollama")
print(f" → ollama pull {CONFIGURED_EMBED}")
return False
# fallback: config.py non leggibile
found = next((m for m in available if _is_embed(m)), None)
if found:
print(f"✅ modello embedding trovato: {found}")
return True
print("❌ nessun modello di embedding trovato")
print(f"Consigliato per italiano: ollama pull bge-m3")
print(f" → Alternativa leggera: ollama pull nomic-embed-text")
print(f"Prima scelta: ollama pull qwen3-embedding:0.6b")
return False
def check_llm_model(available: list[str]) -> bool:
"""Verifica che almeno un modello non-embedding sia presente."""
llm_candidates = [
m for m in available
if not any(m == e or m.startswith(e + ":") or m.startswith(e + "-")
for e in EMBED_MODELS)
]
"""Verifica che il modello LLM configurato sia disponibile."""
if CONFIGURED_LLM:
print(f" modello configurato (step-9/config.py): {CONFIGURED_LLM}")
found = _match(CONFIGURED_LLM, available)
if found:
print(f"✅ LLM disponibile: {found}")
return True
print(f"{CONFIGURED_LLM} non trovato in Ollama")
print(f" → ollama pull {CONFIGURED_LLM}")
return False
# fallback: config.py non leggibile
llm_candidates = [m for m in available if not _is_embed(m)]
if llm_candidates:
print(f"✅ modello LLM trovato: {llm_candidates[0]}")
return True