Ways to check in an entry in DB is present, with ID

Received this question from a community member, and asnwering it here to help anyone else wondering the same thing

Question:

Is there a way to check if an entry in db is present with id ? E.g i upserted an entry with id = 1 with its vectors and some metadata. Now next time when I run my code I want to check if the id is present or not. If present I want to skip the upsert . I do not want to do a vector similarities check . .

Answer

Yes!

For serverless indexes, just use the list operation to check if specific IDs exist in your index1.

python SDK :backhand_index_pointing_down:

from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key='YOUR_API_KEY')index = pc.Index(host="INDEX_HOST")
# List IDs with a specific prefixfor ids in index.list(prefix="1", namespace="example-namespace"):    print(ids)

The list operation returns up to 100 IDs at a time by default in sorted order.
Then, you can compare your ID against the returned list to check if it exists before performing an upsert.

Note: The list operation is supported only for serverless indexes. If you need this functionality for pod-based indexes, you would need to explore alternative approaches. This is only an issue for a small subset of users, but good to be aware of

Hope that helps!

You could also use fetch to retrieve one or more vectors by their specific ID: Fetch records - Pinecone Docs