Skip to content

Release v5.4.0

Compare
Choose a tag to compare
@jhamon jhamon released this 13 Nov 20:37
· 60 commits to main since this release

Query namespaces

In this release we have added a utility method to run a query across multiple namespaces, then merge the result sets into a single ranked result set with the top_k most relevant results. The query_namespaces method accepts most of the same arguments as query with the addition of a required namespaces param.

Since query_namespaces executes multiple queries in parallel, in order to get good performance it is important to set values for the pool_threads and connection_pool_maxsize properties on the index client. The pool_threads setting is the number of threads available to execute requests while connection_pool_maxsize is the number of cached http connections that will be held. Since these tasks are not computationally heavy and are mainly i/o bound, it should be okay to have a high ratio of threads to cpus.

The combined results include the sum of all read unit usage used to perform the underlying queries for each namespace.

from pinecone import Pinecone

pc = Pinecone(api_key="key")
index = pc.Index(
  name="index-name",
  pool_threads=50,             # <-- make sure to set these
  connection_pool_maxsize=50,  # <-- make sure to set these
)

query_vec = [ 0.1, ...] # an embedding vector with same dimension as the index
combined_results = index.query_namespaces(
    vector=query_vec,
    namespaces=['ns1', 'ns2', 'ns3', 'ns4'],
    top_k=10,
    include_values=False,
    include_metadata=True,
    filter={"genre": { "$eq": "comedy" }},
    show_progress=False,
)

for scored_vec in combined_results.matches:
    print(scored_vec)
print(combined_results.usage)

A version of query_namespaces is also available over grpc. For grpc, there is no need to set the connection_pool_maxsize because grpc makes efficient use of open connections by default.

from pinecone.grpc import PineconeGRPC

pc = PineconeGRPC(api_key="key")
index = pc.Index(
  name="index-name",
  pool_threads=50, # <-- make sure to set this
)

query_vec = [ 0.1, ...] # an embedding vector with same dimension as the index
combined_results = index.query_namespaces(
    vector=query_vec,
    namespaces=['ns1', 'ns2', 'ns3', 'ns4'],
    top_k=10,
    include_values=False,
    include_metadata=True,
    filter={"genre": { "$eq": "comedy" }},
    show_progress=False,
)

for scored_vec in combined_results.matches:
    print(scored_vec)
print(combined_results.usage)

Changelog

Additions

  • [feat] PineconeGrpcFuture implements concurrent.futures.Future by @jhamon in #410
  • Update to pinecone-plugin-inference=2.0.0 by @ssmith-pc in #397
  • Detect plugins for Index and IndexGRPC classes by @jhamon in #402
  • Add query_namespaces by @jhamon in #409
  • Expose connection_pool_maxsize on Index and add docstrings by @jhamon in #415
  • Implement query_namespaces over grpc by @jhamon in #416
  • query_namespaces performance improvements by @jhamon in #417

Chores / Fixes

  • [Refactor] Extract GrpcChannelFactory from GRPCIndexBase by @jhamon in #394
  • [Refactor] Extract GrpcRunner from GRPCIndexBase class by @jhamon in #395
  • [Chore] Replace black with ruff linter / formatter by @jhamon in #392
  • [Fix] Update build-oas script for building exceptions template changes by @ssmith-pc in #396
  • [Chore] Put date into test index and collection names by @jhamon in #399
  • [Chore] Automatically cleanup old resources each night by @jhamon in #400
  • [Chore] Improve test flakes by @jhamon in #404

Full Changelog: v5.3.1...v5.4.0.dev5