Spaces:
Sleeping
Sleeping
import numpy as np | |
def query_faiss(query, index, embedder, chunks, top_k=3): | |
query_vector = embedder.encode([query]) | |
D, I = index.search(np.array(query_vector), top_k) | |
retrieved_chunks = [chunks[i] for i in I[0]] | |
return "\n\n".join(retrieved_chunks) | |
def build_prompt(context, question): | |
return f"""You are an AI assistant. Use the following context to answer the question. | |
Context: | |
{context} | |
Question: {question} | |
Answer:""" |