This page shows you how to create a serverless index, pod-based index, and an index from a collection.

To learn about the concepts related to indexes, see Indexes.

Create a serverless index

Serverless indexes are in public preview and are available only on AWS in the us-west-2, us-east-1, and eu-west-1 regions. Check current limits and restrictions and test thoroughly before using them in production.

To create a serverless index, import the ServerlessSpec class and use the spec parameter to define the cloud and region where the index should be deployed:

from pinecone import Pinecone, ServerlessSpec

pc = Pinecone(api_key="YOUR_API_KEY")

pc.create_index(
  name="serverless-index",
  dimension=1536,
  metric="cosine",
  spec=ServerlessSpec(
    cloud="aws",
    region="us-east-1"
  )
)

Create a pod-based index

To create a pod-based index, import the PodSpec class and use the spec parameter to define the environment where the index should be deployed, the pod type and size to use, and other index characteristics:

from pinecone import Pinecone, PodSpec

pc = Pinecone(api_key="YOUR_API_KEY")

pc.create_index(
  name="pod-index",
  dimension=1536,
  metric="cosine",
  spec=PodSpec(
    environment="us-west1-gcp",
    pod_type="p1.x1",
    pods=1
  )
)

For the full list of parameters available to customize an index, see the create_index API reference.

Create an index from a collection

Serverless indexes do not support collections.

To create a pod-based index from a collection, use the create_index operation and provide a source_collection parameter containing the name of the collection from which you wish to create an index. The new index is queryable and writable.

Creating an index from a collection generally takes about 10 minutes. Creating a p2 index from a collection can take several hours when the number of vectors is on the order of 1M.

Example

The following example creates an index named example-index with 128 dimensions from a collection named example-collection.

from pinecone import Pinecone, PodSpec

pc = Pinecone(api_key="YOUR_API_KEY")

pc.create_index(
  name="example-index",
  dimension=128,
  metric="cosine",
  spec=PodSpec(
    environment="us-west-1-gcp",
    pod_type="p1.x1",
    pods=1,
    source_collection="example-collection"
  )
)