File size: 1,794 Bytes
139fefe 4b4bf28 bcc8503 139fefe bcc8503 139fefe 4b4bf28 139fefe 4b4bf28 bcc8503 38ed905 4b4bf28 139fefe 4b4bf28 139fefe |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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
from langchain_chroma import Chroma
# LOAD ENVIRONMENT VARIABLES
try:
from dotenv import load_dotenv
load_dotenv()
except:
pass
def get_chroma_vectorstore(embedding_function, persist_directory="/home/dora/climate-question-answering/data/vectorstore"):
vectorstore = Chroma(persist_directory=persist_directory, embedding_function=embedding_function)
return vectorstore
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 |