Module 'pinecone' has no attribute 'GRPCIndex'

Hello Im trying to create a GRPCIndex and I have the following error:

AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_7876\1517300752.py in
23
24 # connect to index
—> 25 index = pinecone.GRPCIndex(index_name)
26 # view index stats
27 index.describe_index_stats()

AttributeError: module ‘pinecone’ has no attribute ‘GRPCIndex’

This is my code:
import pinecone
import time

initialize connection to pinecone (get API key at app.pinecone.io)

api_key = “xxx”

find your environment next to the api key in pinecone console

env = “xxxx”

pinecone.init(api_key=api_key, environment=env)
pinecone.whoami()
index_name = ‘gpt-4-rfp-docs’

check if index already exists (it shouldn’t if this is first time)

if index_name not in pinecone.list_indexes():
# if does not exist, create index
pinecone.create_index(
index_name,
dimension=len(res[‘data’][0][‘embedding’]),
metric=‘cosine’
)
# wait for index to be initialized
time.sleep(1)

connect to index

index = pinecone.GRPCIndex(index_name)

view index stats

index.describe_index_stats()

from tqdm.auto import tqdm
from time import sleep

batch_size = 100 # how many embeddings we create and insert at once

for i in tqdm(range(0, len(documents), batch_size)):
# find end of batch
i_end = min(len(documents), i+batch_size)
meta_batch = documents[i:i_end]
# get ids
ids_batch = [x[‘id’] for x in meta_batch]
# get texts to encode
texts = [x[‘text’] for x in meta_batch]
# create embeddings (try-except added to avoid RateLimitError)
try:
res = openai.Embedding.create(input=texts, engine=embed_model)
except:
done = False
while not done:
sleep(5)
try:
res = openai.Embedding.create(input=texts, engine=embed_model)
done = True
except:
pass
embeds = [record[‘embedding’] for record in res[‘data’]]
# cleanup metadata
meta_batch = [{
‘text’: x[‘text’],
‘metadata’: x[‘metadata’]
} for x in meta_batch]
to_upsert = list(zip(ids_batch, embeds, meta_batch))
# upsert to Pinecone
index.upsert(vectors=to_upsert)

pip install --upgrade pinecone

were you able to find a solution to this? I am having the same issue and can’t find any information on the resolution.

pip install --upgrade pinecone did not work for me.

1 Like

I figured it out.

I had to uninstall pinecone using:
pip3 uninstall pinecone-client

Then reinstall pinecone with:
pip3 install pinecone-client[grpc]

5 Likes