mod
This commit is contained in:
parent
4719f1022c
commit
1fada52aa3
|
|
@ -31,10 +31,12 @@ def create_faiss_index(sections):
|
|||
return index, sections
|
||||
|
||||
# === 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)
|
||||
_, idx = index.search(query_vector, 1)
|
||||
return sections[idx[0][0]] if idx[0][0] < len(sections) else "Nie znaleziono pasującego artykułu."
|
||||
_, idx = index.search(query_vector, top_k) # Szukamy więcej wyników
|
||||
|
||||
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 ===
|
||||
def generate_response(user_query):
|
||||
|
|
|
|||
Loading…
Reference in New Issue