This commit is contained in:
l.gabrysiak 2025-02-26 16:10:38 +01:00
parent 4719f1022c
commit 1fada52aa3
1 changed files with 5 additions and 3 deletions

View File

@ -31,10 +31,12 @@ def create_faiss_index(sections):
return index, sections return index, sections
# === KROK 3: WYSZUKIWANIE NAJBLIŻSZEGO FRAGMENTU === # === KROK 3: WYSZUKIWANIE NAJBLIŻSZEGO FRAGMENTU ===
def search_faiss(query, index, sections): def search_faiss(query, index, sections, top_k=3):
query_vector = embedding_model.encode([query], convert_to_numpy=True) query_vector = embedding_model.encode([query], convert_to_numpy=True)
_, idx = index.search(query_vector, 1) _, idx = index.search(query_vector, top_k) # Szukamy więcej wyników
return sections[idx[0][0]] if idx[0][0] < len(sections) else "Nie znaleziono pasującego artykułu."
results = [sections[i] for i in idx[0] if i < len(sections)]
return "\n\n".join(results) # Połącz kilka najlepszych fragmentów
# === KROK 4: GENEROWANIE ODPOWIEDZI Z OLLAMA === # === KROK 4: GENEROWANIE ODPOWIEDZI Z OLLAMA ===
def generate_response(user_query): def generate_response(user_query):