AttributeError: module 'pinecone' has no attribute 'init'

1.1k views Asked by At

I am following the Pinecone API and I received this error message:

Traceback (most recent call last):
  File "/Users/leonardjin/Dev/lodge/openAI/collegeAssistant/academicAssisstants/apush/embeddings/embeddings_test.py", line 57, in <module>
    pinecone.init(
    ^^^^^^^^^^^^^
AttributeError: module 'pinecone' has no attribute 'init'

Here is an excerpt of my code:

import pinecone

index_name = 'langchain-retrieval-augmentation'

pinecone.init(
        api_key="----------------------------,  # find api key in console at app.pinecone.io
        environment='us-west1-gcp'  # find next to api key in console
)

if index_name not in pinecone.list_indexes():

    # we create a new index
    pinecone.create_index(
        name=index_name,
        metric='dotproduct',
        dimension=len(res[0]) # 1536 dim of text-embedding-ada-002
    )

#Connect to index (current 'total_vector_count' is 0)

index = pinecone.GRPCIndex(index_name)

index.describe_index_stats()

I installed: pip3 install "pinecone-client[grpc]" but it did not solve this error

My code ran successfully before, but it started to give me this error:

AttributeError: module 'pinecone' has no attribute 'init'

I did multiple Google searches and tried everything, but I am still not sure why I got this error. I would really appreciate some help, thanks

3

There are 3 answers

1
Yusuf On

I got the same error and I solved it by using the pinecone.Pinecone() method.

Use this instead of using pinecone.init():

pinecone.Pinecone(
   api_key=os.getenv("PINECONE_API_KEY"),  
   environment=os.getenv("PINECONE_ENV"),  
)
0
Manna Yang On

Please update your pinecone-client version >=3.0.2

In my project :

ChatGPT-Flutter-Web

from pinecone import Pinecone, PodSpec


pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"), host=os.getenv("PINECONE_CONTROLLER_HOST"))
if index_name not in pc.list_indexes().names():
    loguru.logger.info(f"Creating index: {index_name}")
    loguru.logger.info(f"Store index: {pc.list_indexes()}")
    pc.create_index(name=index_name, metric="cosine", dimension=1536,
                    spec=PodSpec(os.getenv("PINECONE_ENV")))
    data_files = ["dart_v3.2.txt", "flutter_v3.16.txt", "langchain_v0.1.0.txt"]
    for file in data_files:
        file_content = TextLoader(f"./data/{file}").load()
        file_texts = text_splitter.split_documents(file_content)
        VectorPinecone.from_documents(file_texts, embeddings, index_name=index_name)
pinecone_index = pc.Index(index_name)
response = pinecone_index.describe_index_stats()
loguru.logger.info(f"Pinecone index created successfully.{response}")
vectorstore = VectorPinecone.from_existing_index(index_name, embeddings)

0
Rishu.here On

The method pinecone.init for initialization is now considered outdated and has been eliminated from the process.

Try following

pc = Pinecone(
        api_key=os.environ.get("PINECONE_API_KEY")
    )