Spaces:
Runtime error
Runtime error
File size: 677 Bytes
3b0bc72 e14cc04 3b0bc72 e14cc04 3b0bc72 e14cc04 3b0bc72 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import faiss
from langchain.vectorstores import FAISS
from langchain.schema import Document
from embeddings import embedding_model # Correct the import to directly reference the embeddings.py file
# Initialize FAISS index
dim = 384 # MiniLM embedding size
index = faiss.IndexFlatL2(dim)
vector_db = FAISS(embedding_function=embedding_model, 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
|