PineconeException
pinecone.exceptions.PineconeException
Stack trace
pinecone.exceptions.PineconeException: Index 'my-index' not found. Please create the index before upserting vectors.
Why it happens
The Pinecone client throws this error when you try to upsert vectors into an index name that hasn't been created or is deleted. It can also happen if the index name is misspelled or if your API key lacks permissions to access the index.
Detection
Check for PineconeException with message containing 'Index not found' immediately after upsert calls. Logging the index name and Pinecone client status helps catch this early.
Causes & fixes
The Pinecone index was never created before upsert.
Create the index using client.create_index() with the correct name and dimension before performing upsert operations.
The index name used in the upsert call is misspelled or incorrect.
Verify and correct the index name string passed to Pinecone client methods to exactly match the created index.
The Pinecone API key or environment is misconfigured, causing inability to access the index.
Ensure your API key and environment variables are correctly set in os.environ and that the key has permissions for the target index.
Code: broken vs fixed
import os
from pinecone import Pinecone
client = Pinecone(api_key=os.environ['PINECONE_API_KEY'], environment=os.environ['PINECONE_ENV'])
# This will raise PineconeException if index does not exist
client.upsert(index_name='my-index', vectors=[('id1', [0.1, 0.2, 0.3])]) # Error here import os
from pinecone import Pinecone
client = Pinecone(api_key=os.environ['PINECONE_API_KEY'])
# Create index if it doesn't exist
if 'my-index' not in client.list_indexes():
client.create_index(name='my-index', dimension=3)
index = client.Index('my-index')
index.upsert(vectors=[('id1', [0.1, 0.2, 0.3])]) # Fixed: index ensured
print('Upsert succeeded') Workaround
Catch PineconeException on upsert, then create the index dynamically before retrying the upsert operation.
Prevention
Implement index existence checks and automated creation in your initialization code to guarantee the index is always available before upsert calls.