Find answers from the community

s
F
Y
a
P
Updated last month

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
1 comment
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
Add a reply
Sign up and join the conversation on Discord