Working with Serverless Indexes

Serverless indexes scale automatically: you pay for storage and queries without managing infrastructure. Pinecone handles capacity, replication, and availability.

Create a serverless index

An index’s fields are declared as a schema; deployment picks the cloud and region:

from pinecone import Pinecone

pc = Pinecone(api_key="your-api-key")

pc.indexes.create(
    name="product-search",
    schema={"fields": {"embedding": {"type": "dense_vector", "dimension": 1536, "metric": "cosine"}}},
    deployment={"deployment_type": "managed", "cloud": "aws", "region": "us-east-1"},
)

create polls until the index is ready by default. Pass timeout=-1 to return immediately without waiting.

Supported clouds and regions

Use the CloudProvider, AwsRegion, GcpRegion, and AzureRegion enums for tab-completion and typo safety:

from pinecone import Pinecone
from pinecone.models.enums import AwsRegion, CloudProvider

pc = Pinecone(api_key="your-api-key")

pc.indexes.create(
    name="product-search",
    schema={"fields": {"embedding": {"type": "dense_vector", "dimension": 1536, "metric": "cosine"}}},
    deployment={
        "deployment_type": "managed",
        "cloud": CloudProvider.AWS,
        "region": AwsRegion.US_EAST_1,
    },
)

AWS: us-east-1, us-west-2, eu-west-1, eu-central-1, ap-southeast-1

GCP: us-central1, europe-west4

Azure: eastus2, germanywestcentral

Enable deletion protection

Add deletion_protection="enabled" to prevent accidental deletes:

from pinecone import Pinecone
from pinecone.models.enums import DeletionProtection

pc = Pinecone(api_key="your-api-key")

pc.indexes.create(
    name="product-search",
    schema={"fields": {"embedding": {"type": "dense_vector", "dimension": 1536, "metric": "cosine"}}},
    deployment={"deployment_type": "managed", "cloud": "aws", "region": "us-east-1"},
    deletion_protection=DeletionProtection.ENABLED,
)

Check index status

describe returns an IndexModel with the current state:

desc = pc.indexes.describe("product-search")
print(desc.status.state)   # e.g. "Ready"
print(desc.status.ready)   # True when ready to accept requests

Poll manually when you passed timeout=-1 to create:

import time

while not pc.indexes.describe("product-search").status.ready:
    time.sleep(5)

List indexes

list returns a Paginator you can iterate:

for idx in pc.indexes.list():
    print(idx.name, idx.status.state)

# Just the names
names = [idx.name for idx in pc.indexes.list()]

Describe an index

idx = pc.indexes.describe("product-search")
print(idx.name)
print(idx.schema.fields["embedding"].dimension)
print(idx.schema.fields["embedding"].metric)
print(idx.deployment.cloud)
print(idx.deployment.region)

Delete an index

pc.indexes.delete("product-search")

delete polls until the index is gone. Pass timeout=-1 to return immediately.

If deletion protection is enabled, disable it first:

pc.indexes.configure("product-search", deletion_protection="disabled")
pc.indexes.delete("product-search")

See also