pinecone-io / pinecone-python-client

The Pinecone Python client
https://www.pinecone.io/docs
Apache License 2.0
304 stars 79 forks source link

List vector ids by prefix #307

Closed jhamon closed 8 months ago

jhamon commented 9 months ago

Problem

Need to implement the new data plane list endpoint.

Solution

Open questions

Usage

Install the dev client version install "pinecone-client[grpc]"==3.1.0.dev1

REST

from pinecone import Pinecone

pc = Pinecone(api_key='xxx')
index = pc.Index(host='hosturl')

# To iterate over all result pages using a generator function
for ids in index.list(prefix='pref', limit=3, namespace='foo'):
    print(ids) // ['pref1', 'pref2', 'pref3']

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

GRPC

from pinecone.grpc import PineconeGRPC

pc = PineconeGRPC(api_key='xxx')
index = pc.Index(host='hosturl')

# To iterate over all result pages using a generator function
for ids in index.list(prefix='pref', limit=3, namespace='foo'):
    print(ids) // ['pref1', 'pref2', 'pref3']

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

Type of Change

Testing

Try out the dev version.

pip install "pinecone-client[grpc]"==3.1.0.dev1
opbenesh commented 8 months ago

@jhamon, awesome work. Excited to get that out!

As for your open question: we do not plan to add anything else in the near future, but it theoretically might happen at some point. However if we end up adding just some auxiliary data it might be possible to modify the iterator function to deal with it/strip it away.

@gdj0nes WDYT?

jhamon commented 8 months ago

I removed the full_page check and added in docstrings.