Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement query_namespaces over grpc #416

Merged
merged 2 commits into from
Nov 13, 2024
Merged

Conversation

jhamon
Copy link
Collaborator

@jhamon jhamon commented Nov 13, 2024

Problem

I want to maintain parity across REST / GRPC implementations. This PR adds a query_namespaces implementation for the GRPC index client.

Solution

Use a ThreadPoolExecutor to execute queries in parallel, then aggregate the results QueryResultsAggregator.

Usage

import random
from pinecone.grpc import PineconeGRPC

pc = PineconeGRPC(api_key="key")
index = pc.Index(host="jen1024-dojoi3u.svc.apw5-4e34-81fa.pinecone.io", pool_threads=25)

query_vec = [random.random() for i in range(1024)]
combined_results = index.query_namespaces(
    vector=query_vec,
    namespaces=["ns1", "ns2", "ns3", "ns4"],
    include_values=False,
    include_metadata=True,
    filter={"genre": {"$eq": "drama"}},
    top_k=50
)

for vec in combined_results.matches:
    print(vec.get('id'), vec.get('score'))
print(combined_results.usage)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

Describe specific steps for validating this change.

@jhamon jhamon marked this pull request as ready for review November 13, 2024 15:22
@jhamon jhamon force-pushed the jhamon/query_namespaces_grpc branch from 0587ae5 to d01168b Compare November 13, 2024 15:25
Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@rohanshah18 rohanshah18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jhamon jhamon merged commit ab28227 into main Nov 13, 2024
84 of 85 checks passed
@jhamon jhamon deleted the jhamon/query_namespaces_grpc branch November 13, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants