Find answers from the community

s
F
Y
a
P
Updated 2 years ago

Anyone has examples for using Pinecone

Anyone has examples for using Pinecone to store data in one time then answering queries later on without having a reference on the created index?

I've seen this example: https://github.com/jerryjliu/gpt_index/blob/main/examples/vector_indices/PineconeIndexDemo.ipynb, but it uses an index created at a previous step.
How do you query using Pinecone's index directly without loading the documents again?
w
J
9 comments
This is what I'm aiming for,
index should be called once at the start, to initially index the data into pinecone

query should use pinecone directly without attempting to load the data or re-indexing.

What am I doing wrong?

Plain Text
from llama_index import SimpleDirectoryReader, GPTPineconeIndex
import pinecone

def index():
  existing_indexes = pinecone.list_indexes()
  if "paul-graham-essay" not in existing_indexes:
    pinecone.create_index(
        "paul-graham-essay", 
        dimension=1536, 
        metric="euclidean", 
        pod_type="p1"
    )

  pinecone_index = pinecone.Index("paul-graham-essay")
  documents = SimpleDirectoryReader('./hcaa/static').load_data()
  GPTPineconeIndex(documents, pinecone_index=pinecone_index)

def query(q):
  pinecone_index = pinecone.Index("paul-graham-essay")
  documents = SimpleDirectoryReader('./hcaa/static').load_data()
  index = GPTPineconeIndex(documents=documents, pinecone_index=pinecone_index)

  response = index.query(q)
  return response
@walid This was driving me up a wall too. I read thru this GitHub issue (https://github.com/jerryjliu/llama_index/issues/375) and was still sort of confused, so I ended up asking the Kapa bot how to query a preexisting index and it gave me this code (which worked for me):

Plain Text
gpt_index = GPTPineconeIndex([], pinecone_index=index)
Yeah, thanks a lot for getting back on this!

I figured it out ages ago πŸ˜‚ guess kapa bot didn't have the context back then
Out of curiosity, did you end up using that same syntax? Or did you find a better way to do it?
Yeah I ended up using the same syntax

I ditched Pinecone and went for Elasticsearch
Interesting, is it easier to use? I'm just getting started with experimenting on Pinecone
Well I don't know about 'easier' but it is definitely more reliable
I'm going to use it in production capacity so Pinecone felt a little unreliable for my usecase
Got it, thanks!
Add a reply
Sign up and join the conversation on Discord