Find answers from the community

Updated 3 months ago

Pinecone

Hey guys, I'm trying to index documents loaded in pinecone as below. However I get this error. Anyone with an idea on how I can solve this?

AttributeError: 'str' object has no attribute 'upsert'
----> 6 index = GPTVectorStoreIndex.from_documents(documents, storage_context=storage_context)

Code chunk:
coppervstore = PineconeVectorStore(
pinecone_index=index_name,
add_sparse_vector=True,
)
storage_context = StorageContext.from_defaults(vector_store=coppervstore)
index = GPTVectorStoreIndex.from_documents(documents, storage_context=storage_context)
L
n
14 comments
I think that pinecone_index is more than a string
See this example
Plain Text
api_key = "api_key"
pinecone.init(api_key=api_key, environment="us-west1-gcp")
pinecone.create_index(
    "quickstart",
    dimension=1536,
    metric="euclidean",
    pod_type="p1"
)
pinecone_index = pinecone.Index("quickstart")
Then that pinecone index could go into the vector store.

Once the index is created, you can of course skip that line that creates it
@Logan M Oooh makes sense, will try this. Thank you.
But actually the main problem is in this part
index = GPTVectorStoreIndex.from_documents(documents, storage_context=storage_context)
So using GPTVectorStoreIndex results to that error. I already created the pinecone_index
What error does that give you? That shouuuuld work
Also side note when you get there, If you've already inserted the documents with llama index, you can just do this to reconnect to it GPTVectorStoreIndex([], storage_context=storage_context)
Let me try this.. The error is

AttributeError Traceback (most recent call last)
<ipython-input-27-bddaeb9f6a4b> in <cell line: 1>()
----> 1 index = GPTVectorStoreIndex.from_documents(documents, storage_context=storage_context)

7 frames
/usr/local/lib/python3.10/dist-packages/llama_index/vector_stores/pinecone.py in add(self, embedding_results)
207 )[0]
208 entry.update({"sparse_values": sparse_vector})
--> 209 self._pinecone_index.upsert(
210 [entry], namespace=self._namespace, **self._insert_kwargs
211 )

AttributeError: 'str' object has no attribute 'upsert'
The pinecone index is still a string πŸ‘€
You set it up like the code example I gave?
Its now working, yes I followed the instructions. Thank you for your help.
Add a reply
Sign up and join the conversation on Discord