Problem

If you are using Pinecone serverless and getting the error "AttributeError: module 'pinecone' has no attribute 'init', first check that you are using the latest version of the Python client.

You can check the version of the client by running:

pip list pinecone-client

Solution

Serverless requires a minimum version of 3.0. To upgrade to the latest version, run:

pip install --upgrade pinecone-client

If you’re on the right version and getting this error, you just have to make some slight changes to your code to make use of serverless. Instead of calling:

import pinecone

pinecone.init(api_key=api_key,environment=environment)

You’ll use:

from pinecone import Pinecone

pc = Pinecone(api_key=api_key)

You no longer need to specify the cloud environment your index is hosted in; the API key is all you need.