|
import faiss |
|
import pandas as pd |
|
import numpy as np |
|
from sentence_transformers import SentenceTransformer |
|
|
|
|
|
|
|
index_path = "embeddings/all-MiniLM-L6-v2_vector_db.index" |
|
try: |
|
index = faiss.read_index(index_path) |
|
print(f"FAISS index loaded successfully from {index_path}") |
|
except Exception as e: |
|
print(f"Error loading FAISS index: {e}") |
|
|
|
|
|
try: |
|
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2') |
|
print("Model loaded successfully.") |
|
except Exception as e: |
|
print(f"Error loading model: {e}") |
|
|
|
|
|
new_text = ["Cat am de plata"] |
|
print(f'The text is: {new_text}') |
|
|
|
|
|
try: |
|
new_embeddings = model.encode(new_text) |
|
print(f"Generated embeddings for new text: {new_embeddings[0]}") |
|
except Exception as e: |
|
print(f"Error generating embeddings: {e}") |
|
|
|
|
|
try: |
|
new_embeddings = np.array(new_embeddings).astype('float32') |
|
|
|
print(f"Converted new embeddings to float32: {new_embeddings[0]}") |
|
except Exception as e: |
|
print(f"Error converting embeddings to float32: {e}") |
|
|
|
|
|
try: |
|
k = 3 |
|
D, I = index.search(new_embeddings, k) |
|
print(f"Similarity search results: Indices - {I}, Distances - {D}") |
|
except Exception as e: |
|
print(f"Error performing similarity search: {e}") |
|
|
|
|
|
for i, query in enumerate(new_text): |
|
print(f"Query: {query}") |
|
print(f"Nearest neighbors indices: {I[i]}") |
|
print(f"Nearest neighbors distances: {D[i]}") |
|
print() |
|
|
|
|
|
|
|
|
|
csv_file_path = r'C:\Users\serban.tica\Documents\tobi_llm_intent_recognition\data\Pager_Intents_Cleaned.csv' |
|
try: |
|
df = pd.read_csv(csv_file_path) |
|
print(f"CSV file loaded successfully from {csv_file_path}") |
|
except Exception as e: |
|
print(f"Error loading CSV file: {e}") |
|
|
|
try: |
|
for i, query in enumerate(new_text): |
|
print(f"Query: {query}") |
|
for idx in I[i]: |
|
print(f"Index: {idx}, Row: {df.iloc[idx]}") |
|
except Exception as e: |
|
print(f"Error retrieving rows from DataFrame: {e}") |