Update src/ingestion/semantic_splitter.py
Browse files
src/ingestion/semantic_splitter.py
CHANGED
|
@@ -9,7 +9,7 @@ from langchain_huggingface import HuggingFaceEmbeddings
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
class ActivaSemanticSplitter:
|
| 12 |
-
def __init__(self, model_name="sentence-transformers/
|
| 13 |
self.batch_size = batch_size
|
| 14 |
provider = os.getenv("EMBEDDING_PROVIDER", "huggingface").lower()
|
| 15 |
|
|
@@ -138,32 +138,4 @@ class ActivaSemanticSplitter:
|
|
| 138 |
print(f"📊 Grafico salvato: {filename}")
|
| 139 |
plt.close()
|
| 140 |
except Exception:
|
| 141 |
-
pass
|
| 142 |
-
|
| 143 |
-
# --- TEST ---
|
| 144 |
-
if __name__ == "__main__":
|
| 145 |
-
sample_text = """
|
| 146 |
-
La Basilica di S. Marco a Venezia è un'opera d'arte unica.
|
| 147 |
-
Risale al sec. XI e rappresenta lo stile bizantino.
|
| 148 |
-
L'interno è ricco di mosaici.
|
| 149 |
-
|
| 150 |
-
Tuttavia, cambiando argomento, la cucina veneziana offre piatti come le sarde in saor.
|
| 151 |
-
È un piatto a base di cipolle e aceto.
|
| 152 |
-
"""
|
| 153 |
-
|
| 154 |
-
splitter = ActivaSemanticSplitter()
|
| 155 |
-
# Soglia molto bassa (10) per FORZARE lo split solo sul cambio drastico di argomento
|
| 156 |
-
chunks, dists, thresh = splitter.create_chunks(sample_text, percentile_threshold=50)
|
| 157 |
-
|
| 158 |
-
print(f"\n--- TEST FIX ABBREVIAZIONI ---")
|
| 159 |
-
print(f"Input: {len(sample_text)} chars")
|
| 160 |
-
|
| 161 |
-
# Debug delle frasi grezze riconosciute
|
| 162 |
-
sentences = splitter._split_sentences(sample_text)
|
| 163 |
-
print(f"Frasi riconosciute ({len(sentences)}):")
|
| 164 |
-
for s in sentences:
|
| 165 |
-
print(f" - {s}")
|
| 166 |
-
|
| 167 |
-
print(f"\n--- CHUNK GENERATI ---")
|
| 168 |
-
for i, c in enumerate(chunks):
|
| 169 |
-
print(f"🔹 Chunk {i+1}: {c}")
|
|
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
class ActivaSemanticSplitter:
|
| 12 |
+
def __init__(self, model_name="sentence-transformers/all-MiniLM-L6-v2", batch_size=32):
|
| 13 |
self.batch_size = batch_size
|
| 14 |
provider = os.getenv("EMBEDDING_PROVIDER", "huggingface").lower()
|
| 15 |
|
|
|
|
| 138 |
print(f"📊 Grafico salvato: {filename}")
|
| 139 |
plt.close()
|
| 140 |
except Exception:
|
| 141 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|