File size: 445 Bytes
cf4f8aa
 
 
 
 
 
 
 
 
 
 
 
 
9eec855
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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:"""