Spaces:
Runtime error
Runtime error
import faiss | |
from langchain.vectorstores import FAISS | |
from langchain.schema import Document | |
from embeddings import get_embedding # Import the updated embedding function | |
# FAISS parameters | |
dim = 384 # Size of the embedding (MiniLM has 384-dimensional vectors) | |
index = faiss.IndexFlatL2(dim) | |
vector_db = FAISS(embedding_function=get_embedding, index=index) | |
def add_document(text, doc_id): | |
"""Add document embeddings to FAISS.""" | |
doc = Document(page_content=text, metadata={"id": doc_id}) | |
vector_db.add_documents([doc]) | |
def search(query): | |
"""Search FAISS index for similar documents.""" | |
results = vector_db.similarity_search(query, k=3) | |
return results | |