stock_analysis_rag_project / vector_store.py
genaibeauty's picture
Update vector_store.py
1e3e963 verified
raw
history blame contribute delete
678 Bytes
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