Spaces:
Runtime error
Runtime error
File size: 890 Bytes
a88785b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import os
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from langchain_community.vectorstores import FAISS
from langchain_core.documents import Document
def create_or_load_vectorstore(text_chunks):
embeddings = GoogleGenerativeAIEmbeddings(
model="models/embedding-001", google_api_key=os.getenv("GOOGLE_API_KEY")
)
documents = [
Document(page_content=chunk, metadata={"source": "resume"})
for chunk in text_chunks
]
vectorstore = FAISS.from_documents(
documents=documents,
embedding=embeddings
)
return vectorstore
def similarity_search(vectorstore, query, k=5):
try:
documents = vectorstore.similarity_search(query, k=k)
return documents
except Exception as e:
print(f"Error in similarity search: {str(e)}")
return []
|