Spaces:
Runtime error
Runtime error
Download src/chains/retrieval.py from hello-yaaash25/zenith: direct link, hf CLI and curl.
- Browser
- Download file 592 Bytes
-
https://huggingface.co/spaces/hello-yaaash25/zenith/resolve/main/src/chains/retrieval.py
- Command line
-
hf download hf://spaces/hello-yaaash25/zenith/src/chains/retrieval.py
-
curl -L -o retrieval.py https://huggingface.co/spaces/hello-yaaash25/zenith/resolve/main/src/chains/retrieval.py
592 Bytes
| from langchain_community.vectorstores import FAISS | |
| from langchain_community.embeddings import HuggingFaceEmbeddings | |
| DB_FAISS_PATH = 'vectorstore.faiss' | |
| def retrieve_documents(query: str, k: int = 5): | |
| embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", | |
| model_kwargs={'device': 'cpu'}) | |
| db = FAISS.load_local(DB_FAISS_PATH, embeddings) | |
| results = db.similarity_search(query, k=k) | |
| return results | |
| def get_relevant_documents(query: str): | |
| documents = retrieve_documents(query) | |
| return documents |