Skip to main content
Pinecone Docs

Search documentation

Type to search this documentation.

On this pageOverview

Create an index

For guidance and examples, see Create an index.

Python
# pip install "pinecone[grpc]"
# Serverless index
from pinecone.grpc import PineconeGRPC as Pinecone
from pinecone import ServerlessSpec

pc = Pinecone(api_key="YOUR_API_KEY")

pc.create_index(
  name="docs-example1",
  dimension=1536,
  metric="cosine",
  spec=ServerlessSpec(
    cloud="aws",
    region="us-east-1",
  ),
  deletion_protection="disabled"
)

# Pod-based index
from pinecone.grpc import PineconeGRPC as Pinecone, PodSpec

pc = Pinecone(api_key="YOUR_API_KEY")

pc.create_index(
  name="docs-example2",
  dimension=1536,
  metric="cosine",
  spec=PodSpec(
    environment="us-west1-gcp",
    pod_type="p1.x1",
    pods=1,
  ),
  deletion_protection="disabled"
)
JavaScript
// npm install @pinecone-database/pinecone
// Serverles index
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({
  apiKey: 'YOUR_API_KEY'
});

await pc.createIndex({
  name: 'serverless-index',
  dimension: 1536,
  metric: 'cosine',
  spec: {
    serverless: {
      cloud: 'aws',
      region: 'us-east-1'
    }
  },
  deletionProtection: 'disabled',
});

// Pod-based index
await pc.createIndex({
  name: 'docs-example2',
  dimension: 1536,
  metric: 'cosine',
  spec: {
    pod: {
      environment: 'us-west1-gcp',
      podType: 'p1.x1',
      pods: 1
    }
  },
  deletionProtection: 'disabled',
});
Java
import io.pinecone.clients.Pinecone;
import org.openapitools.db_control.client.model.IndexModel;
import org.openapitools.db_control.client.model.DeletionProtection;

// Serverless index
public class CreateServerlessIndexExample {
    public static void main(String[] args) {
        Pinecone pc = new Pinecone.Builder("YOUR_API_KEY").build();
        pc.createServerlessIndex("docs-example1", "cosine", 1536, "aws", "us-east-1", DeletionProtection.disabled);
    }
}

// Pod-based index
public class CreatePodIndexExample {
    public static void main(String[] args) {
        Pinecone pc = new Pinecone.Builder("YOUR_API_KEY").build();
        pc.createPodsIndex("docs-example2", 1536, "us-west1-gcp",
                "p1.x1", "cosine", DeletionProtection.disabled);
    }
}
Go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/pinecone-io/go-pinecone/v2/pinecone"
)

func main() {
    ctx := context.Background()

    pc, err := pinecone.NewClient(pinecone.NewClientParams{
        ApiKey: "YOUR_API_KEY",
    })
    if err != nil {
        log.Fatalf("Failed to create Client: %v", err)
    }

    deletionProtection := pinecone.DeletionProtectionDisabled

    // Serverless index
    idx1, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{
        Name:      "docs-example1",
        Dimension: 1536,
        Metric:    pinecone.Cosine,
        Cloud:     pinecone.Aws,
        Region:    "us-east-1",
        DeletionProtection: &deletionProtection,
    })
  	if err != nil {
        log.Fatalf("Failed to create serverless index: %v", idx1.Name)
    } else {
        fmt.Printf("Successfully created serverless index: %v", idx1.Name)
    }

    // Pod-based index
    idx2, err := pc.CreatePodIndex(ctx, &pinecone.CreatePodIndexRequest{
        Name:        "docs-example2",
        Dimension:   1536,
        Metric:      pinecone.Cosine,
        Environment: "us-east1-gcp",
        PodType:     "p1.x1",
        DeletionProtection: &deletionProtection,
    })
  	if err != nil {
        log.Fatalf("Failed to create pod-based index: %v", idx2.Name)
    } else {
        fmt.Printf("Successfully created pod-based index: %v", idx2.Name)
    }
}
C#
using Pinecone;

var pinecone = new PineconeClient("YOUR_API_KEY");

// Serverless index
var createIndexRequest = await pinecone.CreateIndexAsync(new CreateIndexRequest
{
    Name = "docs-example1",
    Dimension = 1536,
    Metric = CreateIndexRequestMetric.Cosine,
    Spec = new ServerlessIndexSpec
    {
        Serverless = new ServerlessSpec
        {
            Cloud = ServerlessSpecCloud.Aws,
            Region = "us-east-1",
        }
    },
    DeletionProtection = DeletionProtection.Disabled
});

// Pod-based index
var createIndexRequest = await pinecone.CreateIndexAsync(new CreateIndexRequest
{
    Name = "pod index",
    Dimension = 1536,
    Metric = CreateIndexRequestMetric.Cosine,
    Spec = new PodIndexSpec
    {
        Pod = new PodSpec
        {
            Environment = "us-east1-gcp",
            PodType = "p1.x1",
            Pods = 1,
        }
    },
    DeletionProtection = DeletionProtection.Disabled
});
curl
PINECONE_API_KEY="YOUR_API_KEY"

# Serverless index
curl -s https://api.pinecone.io/indexes \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H "X-Pinecone-Api-Version: 2024-07" \
  -d '{
         "name": "serverless-index",
         "dimension": 1536,
         "metric": "cosine",
         "spec": {
            "serverless": {
               "cloud": "aws",
               "region": "us-east-1"
            }
         },
         "deletion_protection": "disabled"
      }'

# Pod-based index
curl -s https://api.pinecone.io/indexes \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H "X-Pinecone-Api-Version: 2024-07" \
  -d '{
         "name": "pod-index",
         "dimension": 1536,
         "metric": "cosine",
         "spec": {
            "pod": {
               "environment": "us-west1-gcp",
               "pod_type": "p1.x1",
               "pods": 1
            }
         },
         "deletion_protection": "disabled"
      }'
curl
# Serverless index
{
    "name": "docs-example1",
    "metric": "cosine",
    "dimension": 1536,
    "status": {
        "ready": true,
        "state": "Ready"
    },
    "host": "docs-example1-4zo0ijk.svc.dev-us-west2-aws.pinecone.io",
    "spec": {
        "serverless": {
            "region": "us-east-1",
            "cloud": "aws"
        }
    }
}

# Pod-based index
{
    "name": "docs-example2",
    "metric": "cosine",
    "dimension": 1536,
    "status": {
        "ready": true,
        "state": "Ready"
    },
    "host": "docs-example2-4zo0ijk.svc.us-west1-gcp.pinecone.io",
    "spec": {
        "pod": {
            "replicas": 1,
            "shards": 1,
            "pods": 1,
            "pod_type": "p1.x1",
            "environment": "us-west1-gcp"
        }
    }
}

POST /indexes

  • name (body, string, required) — The name of the index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'.
  • dimension (body, integer, required) — The dimensions of the vectors to be inserted in the index.
  • metric (body, string) — The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'.
  • deletion_protection (body, string) — Whether deletion protection is enabled/disabled for the index.
  • spec (body, object, required) — The spec object defines how the index should be deployed. For serverless indexes, you define only the cloud and region where the index should be hosted. For pod-based indexes, you define the environment where the index should be
  • 201 — The index has been successfully created.
  • 400 — Bad request. The request body included invalid request parameters.
  • 401 — Unauthorized. Possible causes: Invalid API key.
  • 403 — You've exceed your pod quota.
  • 404 — Unknown cloud or region when creating a serverless index.
  • 409 — Index of given name already exists.
  • 422 — Unprocessable entity. The request body could not be deserialized.
  • 500 — Internal server error.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu