Please help me fix this:
import os
from pinecone import Pinecone, ServerlessSpec
from langchain.vectorstores import Pinecone as PineconeLangchain
os.environ["PINECONE_API_KEY"] = PINECONE_API_KEY
pc = Pinecone(api_key=PINECONE_API_KEY)
index_name = "medchat"
if index_name not in pc.list_indexes().names():
pc.create_index(
name=index_name,
dimension=384,
metric="cosine",
spec=ServerlessSpec(
cloud="aws",
region=PINECONE_API_ENV
)
)
index = pc.Index(index_name)
docsearch = PineconeLangchain.from_existing_index(index_name, embeddings)
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=docsearch.as_retriever(search_kwargs={'k': 2}),
return_source_documents=True,
chain_type_kwargs=chain_type_kwargs
)
Error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-33-f1e2e49d4e0a> in <cell line: 0>()
28
29
---> 30 docsearch = PineconeLangchain.from_existing_index(index_name, embeddings)
31
32
2 frames
/usr/local/lib/python3.11/dist-packages/langchain_community/vectorstores/pinecone.py in __init__(self, index, embedding, text_key, namespace, distance_strategy)
71 )
72 if not isinstance(index, pinecone.Index):
---> 73 raise ValueError(
74 f"client should be an instance of pinecone.Index, " f"got {type(index)}"
75 )
ValueError: client should be an instance of pinecone.Index, got <class 'pinecone.data.index.Index'>
The code was working correctly 2~3 weeks ago, but I checked today and this error was persistently coming up. I can see the problem is in these bits:
index = pc.Index(index_name)
docsearch = PineconeLangchain.from_existing_index(index_name, embeddings)
What's the problem?