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¶
Pass a ServerlessSpec with a cloud provider and region:
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(api_key="your-api-key")
pc.indexes.create(
name="product-search",
dimension=1536,
metric="cosine",
spec=ServerlessSpec(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, ServerlessSpec
from pinecone.models.enums import AwsRegion, CloudProvider
pc = Pinecone(api_key="your-api-key")
pc.indexes.create(
name="product-search",
dimension=1536,
metric="cosine",
spec=ServerlessSpec(
cloud=CloudProvider.AWS,
region=AwsRegion.US_EAST_1,
),
)
AWS: us-east-1, us-west-2, eu-west-1
GCP: us-central1, europe-west4
Azure: eastus2
Enable deletion protection¶
Add deletion_protection="enabled" to prevent accidental deletes:
from pinecone import Pinecone, ServerlessSpec
from pinecone.models.enums import DeletionProtection
pc = Pinecone(api_key="your-api-key")
pc.indexes.create(
name="product-search",
dimension=1536,
metric="cosine",
spec=ServerlessSpec(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 an IndexList you can iterate, slice, or call
.names() on:
for idx in pc.indexes.list():
print(idx.name, idx.status.state)
# Just the names
print(pc.indexes.list().names())
Describe an index¶
idx = pc.indexes.describe("product-search")
print(idx.name)
print(idx.dimension)
print(idx.metric)
print(idx.spec.serverless.cloud)
print(idx.spec.serverless.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¶
IndexModel— full index response modelIndexList— list response modelWorking with Pod-Based Indexes — pod-based index management
Backups and Restore — create and restore backups