Skip to main content

Pinecone client and SDK

Project description

pinecone-client

The Pinecone python client

For more information, see the docs at https://www.pinecone.io/docs/

Installation

Install a released version from pip:

pip3 install pinecone-client

Or the gRPC version of the client for tuning performance

pip3 install "pinecone-client[grpc]"

Or the latest development version:

pip3 install git+https://git@github.com/pinecone-io/pinecone-python-client.git

Or a specific development version:

pip3 install git+https://git@github.com/pinecone-io/pinecone-python-client.git
pip3 install git+https://git@github.com/pinecone-io/pinecone-python-client.git@example-branch-name
pip3 install git+https://git@github.com/pinecone-io/pinecone-python-client.git@259deff

Creating an index

The following example creates an index without a metadata configuration. By default, Pinecone indexes all metadata.

import pinecone


pinecone.init(api_key="YOUR_API_KEY",
              environment="us-west1-gcp")

pinecone.create_index("example-index", dimension=1024)

The following example creates an index that only indexes the "color" metadata field. Queries against this index cannot filter based on any other metadata field.

metadata_config = {
    "indexed": ["color"]
}

pinecone.create_index("example-index-2", dimension=1024,
                      metadata_config=metadata_config)

List indexes

The following example returns all indexes in your project.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

active_indexes = pinecone.list_indexes()

Describe index

The following example returns information about the index example-index.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

index_description = pinecone.describe_index("example-index")

Delete an index

The following example deletes example-index.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

pinecone.delete_index("example-index")

Scale replicas

The following example changes the number of replicas for example-index.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

new_number_of_replicas = 4
pinecone.configure_index("example-index", replicas=new_number_of_replicas)

Describe index statistics

The following example returns statistics about the index example-index.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
index = pinecone.Index("example-index")

index_stats_response = index.describe_index_stats()

Upsert vectors

The following example upserts vectors to example-index.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
index = pinecone.Index("example-index")

upsert_response = index.upsert(
    vectors=[
        ("vec1", [0.1, 0.2, 0.3, 0.4], {"genre": "drama"}),
        ("vec2", [0.2, 0.3, 0.4, 0.5], {"genre": "action"}),
    ],
    namespace="example-namespace"
)

Query an index

The following example queries the index example-index with metadata filtering.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
index = pinecone.Index("example-index")

query_response = index.query(
    namespace="example-namespace",
    top_k=10,
    include_values=True,
    include_metadata=True,
    vector=[0.1, 0.2, 0.3, 0.4],
    filter={
        "genre": {"$in": ["comedy", "documentary", "drama"]}
    }
)

Delete vectors

The following example deletes vectors by ID.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
index = pinecone.Index("example-index")

delete_response = index.delete(ids=["vec1", "vec2"], namespace="example-namespace")

Fetch vectors

The following example fetches vectors by ID.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
index = pinecone.Index("example-index")

fetch_response = index.fetch(ids=["vec1", "vec2"], namespace="example-namespace")

Update vectors

The following example updates vectors by ID.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
index = pinecone.Index("example-index")

update_response = index.update(
    id="vec1",
    values=[0.1, 0.2, 0.3, 0.4],
    set_metadata={"genre": "drama"},
    namespace="example-namespace"
)

Create collection

The following example creates the collection example-collection from example-index.

import pinecone

pinecone.init(api_key="YOUR_API_KEY",
              environment="us-west1-gcp")

pinecone.create_collection("example-collection", "example-index")

List collections

The following example returns a list of the collections in the current project.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

active_collections = pinecone.list_collections()

Describe a collection

The following example returns a description of the collection example-collection.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

collection_description = pinecone.describe_collection("example-collection")

Delete a collection

The following example deletes the collection example-collection.

import pinecone

pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")

pinecone.delete_collection("example-collection")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pinecone-2.2.4.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

pinecone-2.2.4-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file pinecone-2.2.4.tar.gz.

File metadata

  • Download URL: pinecone-2.2.4.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.16 Darwin/22.6.0

File hashes

Hashes for pinecone-2.2.4.tar.gz
Algorithm Hash digest
SHA256 b4eeee626737ba0a8b16b622df17b1b85ece1cc8a052a4f9a1efdc6c645f2bb8
MD5 756aed43317b53fb5c8576f6abbbf618
BLAKE2b-256 6c794de6907f6c7ebc6d39b5fb63eb4d08393634d9f5583c461f1de9c389691b

See more details on using hashes here.

File details

Details for the file pinecone-2.2.4-py3-none-any.whl.

File metadata

  • Download URL: pinecone-2.2.4-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.16 Darwin/22.6.0

File hashes

Hashes for pinecone-2.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c63d6deab1016a754c00ac2d387db2ab98c2c5f6fad429e1ec407bb75dcd134a
MD5 9082d83154c8f9fdae39abcd3a0c0e81
BLAKE2b-256 026ea6ade9573587c0df4c283eab27e1550bbc30ec3f6d58479a3097e9497fc2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page