Spaces:
Runtime error
Runtime error
Download core/vector_store.py from utkarsh134/FastAPI-Experience-Extractor: direct link, hf CLI and curl.
- Browser
- Download file 855 Bytes
-
https://huggingface.co/spaces/utkarsh134/FastAPI-Experience-Extractor/resolve/1fe46a05dbb5bdbb6066ed6c75c668e562f4e59a/core/vector_store.py
- Command line
-
hf download hf://spaces/utkarsh134/FastAPI-Experience-Extractor@1fe46a05dbb5bdbb6066ed6c75c668e562f4e59a/core/vector_store.py
-
curl -L -o vector_store.py https://huggingface.co/spaces/utkarsh134/FastAPI-Experience-Extractor/resolve/1fe46a05dbb5bdbb6066ed6c75c668e562f4e59a/core/vector_store.py
855 Bytes
| 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 [] |