It looks like there is a naming conflict between the original Pinecone client and the LangChain integration for Pinecone. In modern versions of LangChain the recommended approach is to use the Pinecone integration from the langchain_pinecone module, typically via the PineconeVectorStore class. The error
AttributeError: type object 'Pinecone' has no attribute 'from_existing_index'
suggests that you’re importing the wrong Pinecone class.
What’s Happening
You have both:
from langchain.vectorstores import Pinecone
and
from pinecone import Pinecone, ServerlessSpec
in your code. The first one (from langchain.vectorstores) may be getting overridden or confused with the Pinecone client from the pinecone package. Additionally, the older Pinecone wrapper does not include the from_existing_index method, which is available on PineconeVectorStore.
How to Fix It
-
Remove the conflicting import from the original Pinecone client:
Do not import Pinecone from the pinecone package if you are using it via LangChain.
-
Use the correct class:
Instead of using Pinecone (from langchain.vectorstores), switch to using the PineconeVectorStore class from langchain_pinecone.
For example, update your code to:
from langchain_pinecone import PineconeVectorStore
from langchain.embeddings import HuggingFaceEmbeddings
# Make sure your index_name and embeddings are defined correctly:
index_name = "your-index-name"
embeddings = HuggingFaceEmbeddings()
docsearch = PineconeVectorStore.from_existing_index(index_name, embeddings)
query = "What are Allergies"
docs = docsearch.similarity_search(query, k=3)
print("Result", docs)
- Ensure version compatibility:
Confirm that you have the latest versions of LangChain and langchain_pinecone installed. You can update using pip:
pip install --upgrade langchain langchain-pinecone
Summary
By removing the conflicting original Pinecone client import and switching to the PineconeVectorStore class from langchain_pinecone, you should have access to the from_existing_index method and the error should be resolved.