Download climateqa/engine/vectorstore.py from Ekimetrics/climate-question-answering: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/f2baf8741a4c6b9712f2cd9cec2f86ddb4ca4274/climateqa/engine/vectorstore.py
- Command line
-
hf download hf://spaces/Ekimetrics/climate-question-answering@f2baf8741a4c6b9712f2cd9cec2f86ddb4ca4274/climateqa/engine/vectorstore.py
-
curl -L -o vectorstore.py https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/f2baf8741a4c6b9712f2cd9cec2f86ddb4ca4274/climateqa/engine/vectorstore.py
1.51 kB
| # Pinecone | |
| # More info at https://docs.pinecone.io/docs/langchain | |
| # And https://python.langchain.com/docs/integrations/vectorstores/pinecone | |
| import os | |
| from pinecone import Pinecone | |
| from langchain_community.vectorstores import Pinecone as PineconeVectorstore | |
| # LOAD ENVIRONMENT VARIABLES | |
| try: | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| except: | |
| pass | |
| def get_pinecone_vectorstore(embeddings,text_key = "content", index_name = os.getenv("PINECONE_API_INDEX")): | |
| # # initialize pinecone | |
| # pinecone.init( | |
| # api_key=os.getenv("PINECONE_API_KEY"), # find at app.pinecone.io | |
| # environment=os.getenv("PINECONE_API_ENVIRONMENT"), # next to api key in console | |
| # ) | |
| # index_name = os.getenv("PINECONE_API_INDEX") | |
| # vectorstore = Pinecone.from_existing_index(index_name, embeddings,text_key = text_key) | |
| # return vectorstore | |
| pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY")) | |
| index = pc.Index(index_name) | |
| vectorstore = PineconeVectorstore( | |
| index, embeddings, text_key, | |
| ) | |
| return vectorstore | |
| # def get_pinecone_retriever(vectorstore,k = 10,namespace = "vectors",sources = ["IPBES","IPCC"]): | |
| # assert isinstance(sources,list) | |
| # # Check if all elements in the list are either IPCC or IPBES | |
| # filter = { | |
| # "source": { "$in":sources}, | |
| # } | |
| # retriever = vectorstore.as_retriever(search_kwargs={ | |
| # "k": k, | |
| # "namespace":"vectors", | |
| # "filter":filter | |
| # }) | |
| # return retriever |