Spaces:
Sleeping
Sleeping
File size: 700 Bytes
40ab55e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # vector_store.py
from langchain.vectorstores import FAISS
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.docstore.document import Document
import faiss
# You can replace this with any sentence transformer you prefer
def build_index(chunks):
# Convert string chunks to Document objects
documents = [Document(page_content=chunk) for chunk in chunks]
# Load a small sentence transformer model for embeddings
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
# Create FAISS index wrapped with LangChain
vector_index = FAISS.from_documents(documents, embedding_model)
return vector_index, embedding_model
|