PineconeGRPC

class pinecone.grpc.PineconeGRPC(api_key: str | None = None, host: str | None = None, proxy_url: str | None = None, proxy_headers: Dict[str, str] | None = None, ssl_ca_certs: str | None = None, ssl_verify: bool | None = None, additional_headers: Dict[str, str] | None = {}, pool_threads: int | None = None, **kwargs)[source]

An alternative version of the Pinecone client that uses gRPC instead of HTTP for data operations.

Installing the gRPC client

You must install extra dependencies in order to install the GRPC client.

Installing with pip

# Install the latest version
pip3 install "pinecone[grpc]"

# Install a specific version
pip3 install "pinecone[grpc]"==7.0.2

Installing with poetry

# Install the latest version
poetry add pinecone --extras grpc

# Install a specific version
poetry add pinecone==7.0.2 --extras grpc

Using the gRPC client

import os
from pinecone.grpc import PineconeGRPC

pc = PineconeGRPC(api_key=os.environ.get("PINECONE_API_KEY"))

# From this point on, usage is identical to the HTTP client.
index = pc.Index("my-index", host=os.environ("PINECONE_INDEX_HOST"))
index.query(...)

DB Control Plane

Indexes

PineconeGRPC.create_index(name: str, spec: Dict | ServerlessSpec | PodSpec | ByocSpec, dimension: int | None = None, metric: Metric | str | None = 'cosine', timeout: int | None = None, deletion_protection: DeletionProtection | str | None = 'disabled', vector_type: VectorType | str | None = 'dense', tags: Dict[str, str] | None = None) IndexModel

Creates a Pinecone index.

Parameters:
  • name (str) – The name of the index to create. Must be unique within your project and cannot be changed once created. Allowed characters are lowercase letters, numbers, and hyphens and the name may not begin or end with hyphens. Maximum length is 45 characters.

  • metric (str, optional) – Type of similarity metric used in the vector index when querying, one of {"cosine", "dotproduct", "euclidean"}.

  • spec (Dict) – A dictionary containing configurations describing how the index should be deployed. For serverless indexes, specify region and cloud. For pod indexes, specify replicas, shards, pods, pod_type, metadata_config, and source_collection. Alternatively, use the ServerlessSpec, PodSpec, or ByocSpec objects to specify these configurations.

  • dimension (int) – If you are creating an index with vector_type="dense" (which is the default), you need to specify dimension to indicate the size of your vectors. This should match the dimension of the embeddings you will be inserting. For example, if you are using OpenAI’s CLIP model, you should use dimension=1536. Dimension is a required field when creating an index with vector_type="dense" and should not be passed when vector_type="sparse".

  • timeout (int, optional) – Specify the number of seconds to wait until index gets ready. If None, wait indefinitely; if >=0, time out after this many seconds; if -1, return immediately and do not wait.

  • deletion_protection (Optional[Literal["enabled", "disabled"]]) – If enabled, the index cannot be deleted. If disabled, the index can be deleted.

  • vector_type (str, optional) – The type of vectors to be stored in the index. One of {"dense", "sparse"}.

  • tags (Optional[Dict[str, str]]) – Tags are key-value pairs you can attach to indexes to better understand, organize, and identify your resources. Some example use cases include tagging indexes with the name of the model that generated the embeddings, the date the index was created, or the purpose of the index.

Returns:

A IndexModel instance containing a description of the index that was created.

Examples:

Creating a serverless index
import os
from pinecone import (
    Pinecone,
    ServerlessSpec,
    CloudProvider,
    AwsRegion,
    Metric,
    DeletionProtection,
    VectorType
)

pc = Pinecone(api_key=os.environ.get("PINECONE_API_KEY"))

pc.create_index(
    name="my_index",
    dimension=1536,
    metric=Metric.COSINE,
    spec=ServerlessSpec(
        cloud=CloudProvider.AWS,
        region=AwsRegion.US_WEST_2
    ),
    deletion_protection=DeletionProtection.DISABLED,
    vector_type=VectorType.DENSE,
    tags={
        "model": "clip",
        "app": "image-search",
        "env": "testing"
    }
)
Creating a pod index
import os
from pinecone import (
    Pinecone,
    PodSpec,
    PodIndexEnvironment,
    PodType,
    Metric,
    DeletionProtection,
    VectorType
)

pc = Pinecone(api_key=os.environ.get("PINECONE_API_KEY"))

pc.create_index(
    name="my_index",
    dimension=1536,
    metric=Metric.COSINE,
    spec=PodSpec(
        environment=PodIndexEnvironment.US_EAST4_GCP,
        pod_type=PodType.P1_X1
    ),
    deletion_protection=DeletionProtection.DISABLED,
    tags={
        "model": "clip",
        "app": "image-search",
        "env": "testing"
    }
)
PineconeGRPC.create_index_for_model(name: str, cloud: CloudProvider | str, region: AwsRegion | GcpRegion | AzureRegion | str, embed: IndexEmbed | CreateIndexForModelEmbedTypedDict, tags: Dict[str, str] | None = None, deletion_protection: DeletionProtection | str | None = 'disabled', timeout: int | None = None) IndexModel
Parameters:
  • name (str) – The name of the index to create. Must be unique within your project and cannot be changed once created. Allowed characters are lowercase letters, numbers, and hyphens and the name may not begin or end with hyphens. Maximum length is 45 characters.

  • cloud (str) – The cloud provider to use for the index. One of {"aws", "gcp", "azure"}.

  • region (str) – The region to use for the index. Enum objects AwsRegion, GcpRegion, and AzureRegion are also available to help you quickly set these parameters, but may not be up to date as new regions become available.

  • embed (Union[Dict, IndexEmbed]) – The embedding configuration for the index. This param accepts a dictionary or an instance of the IndexEmbed object.

  • tags (Optional[Dict[str, str]]) – Tags are key-value pairs you can attach to indexes to better understand, organize, and identify your resources. Some example use cases include tagging indexes with the name of the model that generated the embeddings, the date the index was created, or the purpose of the index.

  • deletion_protection (Optional[Literal["enabled", "disabled"]]) – If enabled, the index cannot be deleted. If disabled, the index can be deleted. This setting can be changed with configure_index.

  • timeout (Optional[int]) – Specify the number of seconds to wait until index is ready to receive data. If None, wait indefinitely; if >=0, time out after this many seconds; if -1, return immediately and do not wait.

Returns:

A description of the index that was created.

Return type:

IndexModel

This method is used to create a Serverless index that is configured for use with Pinecone’s integrated inference models.

The resulting index can be described, listed, configured, and deleted like any other Pinecone index with the describe_index, list_indexes, configure_index, and delete_index methods.

After the model is created, you can upsert records into the index with the upsert_records method, and search your records with the search method.

from pinecone import (
    Pinecone,
    IndexEmbed,
    CloudProvider,
    AwsRegion,
    EmbedModel,
    Metric,
)

pc = Pinecone()

if not pc.has_index("book-search"):
    desc = await pc.create_index_for_model(
        name="book-search",
        cloud=CloudProvider.AWS,
        region=AwsRegion.US_EAST_1,
        embed=IndexEmbed(
            model=EmbedModel.Multilingual_E5_Large,
            metric=Metric.COSINE,
            field_map={
                "text": "description",
            },
        )
    )

See also

Official docs on available cloud regions

Model Gallery to learn about available models

PineconeGRPC.create_index_from_backup(*, name: str, backup_id: str, deletion_protection: DeletionProtection | str | None = 'disabled', tags: Dict[str, str] | None = None, timeout: int | None = None) IndexModel

Create an index from a backup.

Call list_backups to get a list of backups for your project.

Parameters:
  • name (str) – The name of the index to create.

  • backup_id (str) – The ID of the backup to restore.

  • deletion_protection (Optional[Literal["enabled", "disabled"]]) – If enabled, the index cannot be deleted. If disabled, the index can be deleted. This setting can be changed with configure_index.

  • tags (Optional[Dict[str, str]]) – Tags are key-value pairs you can attach to indexes to better understand, organize, and identify your resources. Some example use cases include tagging indexes with the name of the model that generated the embeddings, the date the index was created, or the purpose of the index.

  • timeout – Specify the number of seconds to wait until index is ready to receive data. If None, wait indefinitely; if >=0, time out after this many seconds; if -1, return immediately and do not wait.

Returns:

A description of the index that was created.

Return type:

IndexModel

PineconeGRPC.list_indexes() IndexList
Returns:

Returns an IndexList object, which is iterable and contains a list of IndexModel objects. The IndexList also has a convenience method names() which returns a list of index names for situations where you just want to iterate over all index names.

Lists all indexes in your project.

The results include a description of all indexes in your project, including the index name, dimension, metric, status, and spec.

If you simply want to check whether an index exists, see the has_index() convenience method.

You can use the list_indexes() method to iterate over descriptions of every index in your project.

from pinecone import Pinecone

pc = Pinecone()

for index in pc.list_indexes():
    print(index.name)
    print(index.dimension)
    print(index.metric)
    print(index.status)
    print(index.host)
    print(index.spec)
PineconeGRPC.describe_index(name: str) IndexModel
Parameters:

name – the name of the index to describe.

Returns:

Returns an IndexModel object which gives access to properties such as the index name, dimension, metric, host url, status, and spec.

Describes a Pinecone index.

Getting your index host url

In a real production situation, you probably want to store the host url in an environment variable so you don’t have to call describe_index and re-fetch it every time you want to use the index. But this example shows how to get the value from the API using describe_index.

from pinecone import Pinecone, Index

pc = Pinecone()

index_name="my_index"
description = pc.describe_index(name=index_name)
print(description)
# {
#     "name": "my_index",
#     "metric": "cosine",
#     "host": "my_index-dojoi3u.svc.aped-4627-b74a.pinecone.io",
#     "spec": {
#         "serverless": {
#             "cloud": "aws",
#             "region": "us-east-1"
#         }
#     },
#     "status": {
#         "ready": true,
#         "state": "Ready"
#     },
#     "vector_type": "dense",
#     "dimension": 1024,
#     "deletion_protection": "enabled",
#     "tags": {
#         "environment": "production"
#     }
# }

print(f"Your index is hosted at {description.host}")

index = pc.Index(host=description.host)
index.upsert(vectors=[...])
PineconeGRPC.configure_index(name: str, replicas: int | None = None, pod_type: PodType | str | None = None, deletion_protection: DeletionProtection | str | None = None, tags: Dict[str, str] | None = None)
Parameters:
  • name (str, required) – the name of the Index

  • replicas (int, optional) – the desired number of replicas, lowest value is 0.

  • pod_type (str or PodType, optional) – the new pod_type for the index. To learn more about the available pod types, please see Understanding Indexes. Note that pod type is only available for pod-based indexes.

  • deletion_protection (str or DeletionProtection, optional) – If set to 'enabled', the index cannot be deleted. If 'disabled', the index can be deleted.

  • tags (Dict[str, str], optional) – A dictionary of tags to apply to the index. Tags are key-value pairs that can be used to organize and manage indexes. To remove a tag, set the value to “”. Tags passed to configure_index will be merged with existing tags and any with the value empty string will be removed.

This method is used to modify an index’s configuration. It can be used to:

  • Scale a pod-based index horizontally using replicas

  • Scale a pod-based index vertically using pod_type

  • Enable or disable deletion protection using deletion_protection

  • Add, change, or remove tags using tags

Scaling pod-based indexes

To scale your pod-based index, you pass a replicas and/or pod_type param to the configure_index method. pod_type may be a string or a value from the PodType enum.

from pinecone import Pinecone, PodType

pc = Pinecone()
pc.configure_index(
    name="my_index",
    replicas=2,
        pod_type=PodType.P1_X2
    )

After providing these new configurations, you must call describe_index to see the status of the index as the changes are applied.

Enabling or disabling deletion protection

To enable or disable deletion protection, pass the deletion_protection parameter to the configure_index method. When deletion protection is enabled, the index cannot be deleted with the delete_index method.

from pinecone import Pinecone, DeletionProtection

pc = Pinecone()

# Enable deletion protection
pc.configure_index(
    name="my_index",
    deletion_protection=DeletionProtection.ENABLED
)

# Call describe_index to see the change was applied.
assert pc.describe_index("my_index").deletion_protection == "enabled"

# Disable deletion protection
pc.configure_index(
    name="my_index",
    deletion_protection=DeletionProtection.DISABLED
)

Adding, changing, or removing tags

To add, change, or remove tags, pass the tags parameter to the configure_index method. When tags are passed using configure_index, they are merged with any existing tags already on the index. To remove a tag, set the value of the key to an empty string.

from pinecone import Pinecone

pc = Pinecone()

# Add a tag
pc.configure_index(name="my_index", tags={"environment": "staging"})

# Change a tag
pc.configure_index(name="my_index", tags={"environment": "production"})

# Remove a tag
pc.configure_index(name="my_index", tags={"environment": ""})

# Call describe_index to view the tags are changed
print(pc.describe_index("my_index").tags)
PineconeGRPC.delete_index(name: str, timeout: int | None = None)
Parameters:
  • name (str) – the name of the index.

  • timeout (int, optional) – Number of seconds to poll status checking whether the index has been deleted. If None, wait indefinitely; if >=0, time out after this many seconds; if -1, return immediately and do not wait.

Deletes a Pinecone index.

Deleting an index is an irreversible operation. All data in the index will be lost. When you use this command, a request is sent to the Pinecone control plane to delete the index, but the termination is not synchronous because resources take a few moments to be released.

By default the delete_index method will block until polling of the describe_index method shows that the delete operation has completed. If you prefer to return immediately and not wait for the index to be deleted, you can pass timeout=-1 to the method.

After the delete request is submitted, polling describe_index will show that the index transitions into a Terminating state before eventually resulting in a 404 after it has been removed.

This operation can fail if the index is configured with deletion_protection="enabled". In this case, you will need to call configure_index to disable deletion protection before you can delete the index.

from pinecone import Pinecone

pc = Pinecone()

index_name = "my_index"
desc = pc.describe_index(name=index_name)

if desc.deletion_protection == "enabled":
    # If for some reason deletion protection is enabled, you will need to disable it first
    # before you can delete the index. But use caution as this operation is not reversible
    # and if somebody enabled deletion protection, they probably had a good reason.
    pc.configure_index(name=index_name, deletion_protection="disabled")

pc.delete_index(name=index_name)
PineconeGRPC.has_index(name: str) bool
Parameters:

name – The name of the index to check for existence.

Returns:

Returns True if the index exists, False otherwise.

Checks if a Pinecone index exists.

from pinecone import Pinecone, ServerlessSpec

pc = Pinecone()

index_name = "my_index"
if not pc.has_index(index_name):
    print("Index does not exist, creating...")
    pc.create_index(
        name=index_name,
        dimension=768,
        metric="cosine",
        spec=ServerlessSpec(cloud="aws", region="us-west-2")
    )

Backups

PineconeGRPC.create_backup(*, index_name: str, backup_name: str, description: str = '') BackupModel

Create a backup of an index.

Parameters:
  • index_name (str) – The name of the index to backup.

  • backup_name (str) – The name to give the backup.

  • description (str, optional) – Optional description of the backup.

PineconeGRPC.list_backups(*, index_name: str | None = None, limit: int | None = 10, pagination_token: str | None = None) BackupList

List backups.

If index_name is provided, the backups will be filtered by index. If no index_name is provided, all backups in the project will be returned.

Parameters:
  • index_name (str, optional) – The name of the index to list backups for.

  • limit (int, optional) – The maximum number of backups to return.

  • pagination_token (str, optional) – The pagination token to use for pagination.

PineconeGRPC.describe_backup(*, backup_id: str) BackupModel

Describe a backup.

Parameters:

backup_id (str) – The ID of the backup to describe.

PineconeGRPC.delete_backup(*, backup_id: str) None

Delete a backup.

Parameters:

backup_id (str) – The ID of the backup to delete.

Collections

PineconeGRPC.create_collection(name: str, source: str) None

Create a collection from a pod-based index

Parameters:
  • name (str, required) – Name of the collection

  • source (str, required) – Name of the source index

PineconeGRPC.list_collections() CollectionList

List all collections

from pinecone import Pinecone

pc = Pinecone()

for collection in pc.list_collections():
    print(collection.name)
    print(collection.source)

# You can also iterate specifically over the collection
# names with the .names() helper.
collection_name="my_collection"
for collection_name in pc.list_collections().names():
    print(collection_name)
PineconeGRPC.describe_collection(name: str)

Describes a collection.

Parameters:

name (str) – The name of the collection

Returns:

Description of the collection

from pinecone import Pinecone

pc = Pinecone()

description = pc.describe_collection("my_collection")
print(description.name)
print(description.source)
print(description.status)
print(description.size)
PineconeGRPC.delete_collection(name: str) None
Parameters:

name (str) – The name of the collection to delete.

Deletes a collection.

Deleting a collection is an irreversible operation. All data in the collection will be lost.

This method tells Pinecone you would like to delete a collection, but it takes a few moments to complete the operation. Use the describe_collection() method to confirm that the collection has been deleted.

from pinecone import Pinecone

pc = Pinecone()

pc.delete_collection(name="my_collection")

Restore Jobs

PineconeGRPC.list_restore_jobs(*, limit: int | None = 10, pagination_token: str | None = None) RestoreJobList

List restore jobs.

Parameters:
  • limit (int) – The maximum number of restore jobs to return.

  • pagination_token (str) – The pagination token to use for pagination.

PineconeGRPC.describe_restore_job(*, job_id: str) RestoreJobModel

Describe a restore job.

Parameters:

job_id (str) – The ID of the restore job to describe.

DB Data Plane

class pinecone.grpc.GRPCIndex(index_name: str, config: Config, channel: Channel | None = None, grpc_config: GRPCClientConfig | None = None, pool_threads: int | None = None, _endpoint_override: str | None = None)[source]

A client for interacting with a Pinecone index via GRPC API.

GRPCIndex.__init__(index_name: str, config: Config, channel: Channel | None = None, grpc_config: GRPCClientConfig | None = None, pool_threads: int | None = None, _endpoint_override: str | None = None)
GRPCIndex.describe_index_stats(filter: Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]] | Dict[Literal['$and'], List[Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]]]] | None = None, **kwargs) IndexDescription[source]

The DescribeIndexStats operation returns statistics about the index’s contents. For example: The vector count per namespace and the number of dimensions.

Examples:

>>> index.describe_index_stats()
>>> index.describe_index_stats(filter={'key': 'value'})
Parameters:
  • filter (Dict[str, Union[str, float, int, bool, List, dict]])

  • present (If this parameter is)

  • filter. (the operation only returns statistics for vectors that satisfy the)

  • <https (See `metadata filtering) –

    //www.pinecone.io/docs/metadata-filtering/>_` [optional]

Returns: DescribeIndexStatsResponse object which contains stats about the index.

Vectors

GRPCIndex.upsert(vectors: List[Vector] | List[Vector] | List[Tuple[str, List[float]]] | List[VectorTypedDict], async_req: bool = False, namespace: str | None = None, batch_size: int | None = None, show_progress: bool = True, **kwargs) UpsertResponse | PineconeGrpcFuture[source]

The upsert operation writes vectors into a namespace. If a new value is upserted for an existing vector id, it will overwrite the previous value.

Examples:

>>> index.upsert([('id1', [1.0, 2.0, 3.0], {'key': 'value'}),
                  ('id2', [1.0, 2.0, 3.0])
                  ],
                  namespace='ns1', async_req=True)
>>> index.upsert([{'id': 'id1', 'values': [1.0, 2.0, 3.0], 'metadata': {'key': 'value'}},
                  {'id': 'id2',
                            'values': [1.0, 2.0, 3.0],
                            'sparse_values': {'indices': [1, 8], 'values': [0.2, 0.4]},
                  ])
>>> index.upsert([GRPCVector(id='id1', values=[1.0, 2.0, 3.0], metadata={'key': 'value'}),
                  GRPCVector(id='id2', values=[1.0, 2.0, 3.0]),
                  GRPCVector(id='id3',
                             values=[1.0, 2.0, 3.0],
                             sparse_values=GRPCSparseValues(indices=[1, 2], values=[0.2, 0.4]))])
Parameters:
  • vectors (Union[List[Vector], List[Tuple]]) –

    A list of vectors to upsert.

    A vector can be represented by a 1) GRPCVector object, a 2) tuple or 3) a dictionary 1) if a tuple is used, it must be of the form (id, values, metadata) or (id, values).

    where id is a string, vector is a list of floats, and metadata is a dict. Examples: (‘id1’, [1.0, 2.0, 3.0], {‘key’: ‘value’}), (‘id2’, [1.0, 2.0, 3.0])

    1. if a GRPCVector object is used, a GRPCVector object must be of the form

      GRPCVector(id, values, metadata), where metadata is an optional argument of type Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]

      Examples: GRPCVector(id=’id1’, values=[1.0, 2.0, 3.0], metadata={‘key’: ‘value’}),

      GRPCVector(id=’id2’, values=[1.0, 2.0, 3.0]), GRPCVector(id=’id3’,

      values=[1.0, 2.0, 3.0], sparse_values=GRPCSparseValues(indices=[1, 2], values=[0.2, 0.4]))

    2. if a dictionary is used, it must be in the form {‘id’: str, ‘values’: List[float], ‘sparse_values’: {‘indices’: List[int], ‘values’: List[float]},

      ’metadata’: dict}

    Note: the dimension of each vector must match the dimension of the index.

  • async_req (bool) – If True, the upsert operation will be performed asynchronously. Cannot be used with batch_size. Defaults to False. See: https://docs.pinecone.io/docs/performance-tuning [optional]

  • namespace (str) – The namespace to write to. If not specified, the default namespace is used. [optional]

  • batch_size (int) –

    The number of vectors to upsert in each batch.

    Cannot be used with async_req=True.

    If not specified, all vectors will be upserted in a single batch. [optional]

  • show_progress (bool) – Whether to show a progress bar using tqdm. Applied only if batch_size is provided. Default is True.

Returns: UpsertResponse, contains the number of vectors upserted

GRPCIndex.query(vector: List[float] | None = None, id: str | None = None, namespace: str | None = None, top_k: int | None = None, filter: Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]] | Dict[Literal['$and'], List[Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]]]] | None = None, include_values: bool | None = None, include_metadata: bool | None = None, sparse_vector: SparseValues | SparseValues | SparseVectorTypedDict | None = None, async_req: bool | None = False, **kwargs) QueryResponse | PineconeGrpcFuture[source]

The Query operation searches a namespace, using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.

Examples:

>>> index.query(vector=[1, 2, 3], top_k=10, namespace='my_namespace')
>>> index.query(id='id1', top_k=10, namespace='my_namespace')
>>> index.query(vector=[1, 2, 3], top_k=10, namespace='my_namespace', filter={'key': 'value'})
>>> index.query(id='id1', top_k=10, namespace='my_namespace', include_metadata=True, include_values=True)
>>> index.query(vector=[1, 2, 3], sparse_vector={'indices': [1, 2], 'values': [0.2, 0.4]},
>>>             top_k=10, namespace='my_namespace')
>>> index.query(vector=[1, 2, 3], sparse_vector=GRPCSparseValues([1, 2], [0.2, 0.4]),
>>>             top_k=10, namespace='my_namespace')
Parameters:
  • vector (List[float]) – The query vector. This should be the same length as the dimension of the index being queried. Each query() request can contain only one of the parameters id or vector.. [optional]

  • id (str) – The unique ID of the vector to be used as a query vector. Each query() request can contain only one of the parameters vector or id.. [optional]

  • top_k (int) – The number of results to return for each query. Must be an integer greater than 1.

  • namespace (str) – The namespace to fetch vectors from. If not specified, the default namespace is used. [optional]

  • filter (Dict[str, Union[str, float, int, bool, List, dict]]) – The filter to apply. You can use vector metadata to limit your search. See metadata filtering <https://www.pinecone.io/docs/metadata-filtering/>_ [optional]

  • include_values (bool) – Indicates whether vector values are included in the response. If omitted the server will use the default value of False [optional]

  • include_metadata (bool) – Indicates whether metadata is included in the response as well as the ids. If omitted the server will use the default value of False [optional]

  • sparse_vector

    (Union[SparseValues, Dict[str, Union[List[float], List[int]]]]): sparse values of the query vector. Expected to be either a SparseValues object or a dict of the form:

    {‘indices’: List[int], ‘values’: List[float]}, where the lists each have the same length.

Returns: QueryResponse object which contains the list of the closest vectors as ScoredVector objects,

and namespace name.

GRPCIndex.query_namespaces(vector: List[float], namespaces: List[str], metric: Literal['cosine', 'euclidean', 'dotproduct'], top_k: int | None = None, filter: Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]] | Dict[Literal['$and'], List[Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]]]] | None = None, include_values: bool | None = None, include_metadata: bool | None = None, sparse_vector: SparseValues | SparseVectorTypedDict | None = None, **kwargs) QueryNamespacesResults[source]
GRPCIndex.delete(ids: List[str] | None = None, delete_all: bool | None = None, namespace: str | None = None, filter: Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]] | Dict[Literal['$and'], List[Dict[str, str | int | float | bool] | Dict[Literal['$eq'], str | int | float | bool] | Dict[Literal['$ne'], str | int | float | bool] | Dict[Literal['$gt'], int | float] | Dict[Literal['$gte'], int | float] | Dict[Literal['$lt'], int | float] | Dict[Literal['$lte'], int | float] | Dict[Literal['$in'], List[str | int | float | bool]] | Dict[Literal['$nin'], List[str | int | float | bool]]]] | None = None, async_req: bool = False, **kwargs) DeleteResponse | PineconeGrpcFuture[source]

The Delete operation deletes vectors from the index, from a single namespace. No error raised if the vector id does not exist.

Parameters:
  • ids (List[str]) – Vector ids to delete [optional]

  • delete_all (bool) – This indicates that all vectors in the index namespace should be deleted.. [optional] Default is False.

  • namespace (str) – The namespace to delete vectors from [optional] If not specified, the default namespace is used.

  • filter (FilterTypedDict) –

    If specified, the metadata filter here will be used to select the vectors to delete. This is mutually exclusive with specifying ids to delete in the ids param or using delete_all=True.

    See metadata filtering <https://www.pinecone.io/docs/metadata-filtering/>_ [optional]

  • async_req (bool) – If True, the delete operation will be performed asynchronously. Defaults to False. [optional]

Returns: DeleteResponse (contains no data) or a PineconeGrpcFuture object if async_req is True.

Note

For any delete call, if namespace is not specified, the default namespace is used.

Delete can occur in the following mutual exclusive ways:

  1. Delete by ids from a single namespace

  2. Delete all vectors from a single namespace by setting delete_all to True

  3. Delete all vectors from a single namespace by specifying a metadata filter (note that for this option delete all must be set to False)

Examples:

>>> index.delete(ids=['id1', 'id2'], namespace='my_namespace')
>>> index.delete(delete_all=True, namespace='my_namespace')
>>> index.delete(filter={'key': 'value'}, namespace='my_namespace', async_req=True)
GRPCIndex.fetch(ids: List[str] | None, namespace: str | None = None, async_req: bool | None = False, **kwargs) FetchResponse | PineconeGrpcFuture[source]

The fetch operation looks up and returns vectors, by ID, from a single namespace. The returned vectors include the vector data and/or metadata.

Examples:

>>> index.fetch(ids=['id1', 'id2'], namespace='my_namespace')
>>> index.fetch(ids=['id1', 'id2'])
Parameters:
  • ids (List[str]) – The vector IDs to fetch.

  • namespace (str) – The namespace to fetch vectors from. If not specified, the default namespace is used. [optional]

Returns: FetchResponse object which contains the list of Vector objects, and namespace name.

GRPCIndex.list(**kwargs)[source]

The list operation accepts all of the same arguments as list_paginated, and returns a generator that yields a list of the matching vector ids in each page of results. It automatically handles pagination tokens on your behalf.

Examples:

>>> for ids in index.list(prefix='99', limit=5, namespace='my_namespace'):
>>>     print(ids)
['99', '990', '991', '992', '993']
['994', '995', '996', '997', '998']
['999']
Parameters:
  • prefix (Optional[str]) – The id prefix to match. If unspecified, an empty string prefix will be used with the effect of listing all ids in a namespace [optional]

  • limit (Optional[int]) – The maximum number of ids to return. If unspecified, the server will use a default value. [optional]

  • pagination_token (Optional[str]) – A token needed to fetch the next page of results. This token is returned in the response if additional results are available. [optional]

  • namespace (Optional[str]) – The namespace to fetch vectors from. If not specified, the default namespace is used. [optional]

GRPCIndex.list_paginated(prefix: str | None = None, limit: int | None = None, pagination_token: str | None = None, namespace: str | None = None, **kwargs) ListResponse[source]

The list_paginated operation finds vectors based on an id prefix within a single namespace. It returns matching ids in a paginated form, with a pagination token to fetch the next page of results. This id list can then be passed to fetch or delete operations, depending on your use case.

Consider using the list method to avoid having to handle pagination tokens manually.

Examples:

>>> results = index.list_paginated(prefix='99', limit=5, namespace='my_namespace')
>>> [v.id for v in results.vectors]
['99', '990', '991', '992', '993']
>>> results.pagination.next
eyJza2lwX3Bhc3QiOiI5OTMiLCJwcmVmaXgiOiI5OSJ9
>>> next_results = index.list_paginated(prefix='99', limit=5, namespace='my_namespace', pagination_token=results.pagination.next)
Parameters:
  • prefix (Optional[str]) – The id prefix to match. If unspecified, an empty string prefix will be used with the effect of listing all ids in a namespace [optional]

  • limit (Optional[int]) – The maximum number of ids to return. If unspecified, the server will use a default value. [optional]

  • pagination_token (Optional[str]) – A token needed to fetch the next page of results. This token is returned in the response if additional results are available. [optional]

  • namespace (Optional[str]) – The namespace to fetch vectors from. If not specified, the default namespace is used. [optional]

Returns: SimpleListResponse object which contains the list of ids, the namespace name, pagination information, and usage showing the number of read_units consumed.