ID prefixes count

Hi @yzhou and welcome to the Pinecone forums!

Thanks for your question.

If I’m understanding your question correctly, you may want to use manual pagination, which allows you to provide the prefix of records to list:

from pinecone import Pinecone

pc = Pinecone(api_key='YOUR_API_KEY')
index = pc.Index("pinecone-index")

namespace = 'ns1'

# For manual control over pagination
results = index.list_paginated(
    prefix='pref',
    limit=3,
    namespace='ns1'
)
print(results.namespace)
print([v.id for v in results.vectors])
print(results.pagination.next)
print(results.usage)

You would want to maintain a local variable in your code to track each prefix’s count.

So, one variable to track the count for prefix1 and one for prefix2.

Then, paginate through the list of vectors retrieved with each prefix until there are no more, and that’s your count for that prefix.

You can also see examples in our Pinecone Python client docs.

Hope this helps!

Best,
Zack

2 Likes