For introductory information on indexes, please see Understanding indexes
When you are working with dense embedding vectors, you must specify the dimension
of the vectors you expect to store at the time your index is created. For sparse vectors, used to represent vectors where most values are zero, you omit dimension
and must specify vector_type="sparse"
.
from pinecone import (
Pinecone,
ServerlessSpec,
CloudProvider,
AwsRegion,
Metric,
VectorType
)
pc = Pinecone(api_key='<<PINECONE_API_KEY>>')
pc.create_index(
name='index-for-dense-vectors',
dimension=1536,
metric=Metric.COSINE,
# vector_type="dense" is the default value, so it can be omitted if you prefer
vector_type=VectorType.DENSE,
spec=ServerlessSpec(
cloud=CloudProvider.AWS,
region=AwsRegion.US_WEST_2
),
)
pc.create_index(
name='index-for-sparse-vectors',
metric=Metric.DOTPRODUCT,
vector_type=VectorType.SPARSE,
spec=ServerlessSpec(
cloud=CloudProvider.AWS,
region=AwsRegion.US_WEST_2
),
)
See the available cloud regions page for the most up-to-date information one which cloud regions are available.
The following example creates a serverless index in the us-west-2
region of AWS. For more information on serverless and regional availability, see Understanding indexes.
from pinecone import (
Pinecone,
ServerlessSpec,
CloudProvider,
AwsRegion,
Metric,
VectorType
)
pc = Pinecone(api_key='<<PINECONE_API_KEY>>')
pc.create_index(
name='my-index',
dimension=1536,
metric=Metric.COSINE,
spec=ServerlessSpec(
cloud=CloudProvider.AWS,
region=AwsRegion.US_WEST_2
),
vector_type=VectorType.DENSE
)
The following example creates a serverless index in the us-central1
region of GCP. For more information on serverless and regional availability, see Understanding indexes.
from pinecone import (
Pinecone,
ServerlessSpec,
CloudProvider,
GcpRegion,
Metric
)
pc = Pinecone(api_key='<<PINECONE_API_KEY>>')
pc.create_index(
name='my-index',
dimension=1536,
metric=Metric.COSINE,
spec=ServerlessSpec(
cloud=CloudProvider.GCP,
region=GcpRegion.US_CENTRAL1
)
)
The following example creates a serverless index on Azure. For more information on serverless and regional availability, see Understanding indexes.
from pinecone import (
Pinecone,
ServerlessSpec,
CloudProvider,
AzureRegion,
Metric
)
pc = Pinecone(api_key='<<PINECONE_API_KEY>>')
pc.create_index(
name='my-index',
dimension=1536,
metric=Metric.COSINE,
spec=ServerlessSpec(
cloud=CloudProvider.AZURE,
region=AzureRegion.EASTUS2
)
)
See shared index actions to learn about how to manage the lifecycle of your index after it is created.