-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define enum classes with control plane configuration options (#437)
## Problem Many configuration fields take string inputs even though there is a limited range of accepted values. It's poor UX having to go into documentation or examples in order to know which string values are available. This also means support via type hints from code editors are not available to keep people moving quickly. ## Solution - Create Enum classes for control plane configuration fields under `pinecone.enum`: - General index configs: `Metric`, `VectorType`, `DeletionProtection` - Serverless spec: `CloudProvider`, `AwsRegion`, `GcpRegion`, `AzureRegion` - Pod spec: `PodIndexEnvironment`, `PodType` kwargs that accept these values are loosely typed as the union of the enum type and string. This should prevent unnecessary breaking changes and maintain flexibility to accept new values that may not be avaialble or known at the time this SDK release is published. For example, if in the future pinecone can deploy to more Azure regions, this loose typing would allow a person to pass that configuration as region without necessarily having to update their SDK to satisfy to a type check. ## Usage: Serverless ```python # Old way, which still works but requires you to know what values are available from pinecone import Pinecone, ServerlessSpec pc = Pinecone(api_key='key') pc.create_index( name="my-index", dimension=1024, metric="cosine", spec=ServerlessSpec( cloud="aws", region="us-west-2" ), vector_type="sparse" ) ``` ```python # New way, using enum types from pinecone import ( Pinecone, ServerlessSpec, Metric, VectorType, CloudProvider, AwsRegion ) pc = Pinecone(api_key='key') pc.create_index( name="my-index", dimension=1024, metric=Metric.COSINE, spec=ServerlessSpec( cloud=CloudProvider.AWS, region=AwsRegion.US_WEST_2 ), vector_type=VectorType.SPARSE ) ``` ## Usage: Pods ```python # old way, you have to know all the magic strings from pinecone import Pinecone, PodSpec pc = Pinecone(api_key='key') pc.create_index( name="my-index", dimension=1024, spec=PodSpec( pod_type='s1.x4' environment="us-east1-gcp" ), ) # Later, when scaling pc.configure_index( name="my-index", pod_type="s1.x8" ) ``` ```python # New way, using enum types from pinecone import ( Pinecone, PodSpec, PodIndexEnvironment, PodType ) pc = Pinecone(api_key='key') pc.create_index( name="my-index", dimension=1024, spec=PodSpec( environment=PodIndexEnvironment.US_EAST1_GCP, pod_type=PodType.S1_X4 ) ) # Later, when scaling pc.configure_index( name="my-index", pod_type=PodType.S1_X8 ) ``` ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here)
- Loading branch information
Showing
18 changed files
with
297 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from .clouds import CloudProvider, AwsRegion, GcpRegion, AzureRegion | ||
from .deletion_protection import DeletionProtection | ||
from .metric import Metric | ||
from .pod_index_environment import PodIndexEnvironment | ||
from .pod_type import PodType | ||
from .vector_type import VectorType | ||
|
||
__all__ = [ | ||
"CloudProvider", | ||
"AwsRegion", | ||
"GcpRegion", | ||
"AzureRegion", | ||
"DeletionProtection", | ||
"Metric", | ||
"PodIndexEnvironment", | ||
"PodType", | ||
"VectorType", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from enum import Enum | ||
|
||
|
||
class CloudProvider(Enum): | ||
"""Cloud providers available for use with Pinecone serverless indexes""" | ||
|
||
AWS = "aws" | ||
GCP = "gcp" | ||
AZURE = "azure" | ||
|
||
|
||
class AwsRegion(Enum): | ||
"""AWS (Amazon Web Services) regions available for use with Pinecone serverless indexes""" | ||
|
||
US_EAST_1 = "us-east-1" | ||
US_WEST_2 = "us-west-2" | ||
EU_WEST_1 = "eu-west-1" | ||
|
||
|
||
class GcpRegion(Enum): | ||
"""GCP (Google Cloud Platform) regions available for use with Pinecone serverless indexes""" | ||
|
||
US_CENTRAL1 = "us-central1" | ||
EUROPE_WEST4 = "europe-west4" | ||
|
||
|
||
class AzureRegion(Enum): | ||
"""Azure regions available for use with Pinecone serverless indexes""" | ||
|
||
EAST_US = "eastus2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from enum import Enum | ||
|
||
|
||
class DeletionProtection(Enum): | ||
"""The DeletionProtection setting of an index indicates whether the index | ||
can be the index cannot be deleted using the delete_index() method. | ||
If disabled, the index can be deleted. If enabled, calling delete_index() | ||
will raise an error. | ||
This setting can be changed using the configure_index() method. | ||
""" | ||
|
||
ENABLED = "enabled" | ||
DISABLED = "disabled" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from enum import Enum | ||
|
||
|
||
class Metric(Enum): | ||
""" | ||
The metric specifies how Pinecone should calculate the distance between vectors when querying an index. | ||
""" | ||
|
||
COSINE = "cosine" | ||
EUCLIDEAN = "euclidean" | ||
DOTPRODUCT = "dotproduct" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from enum import Enum | ||
|
||
|
||
class PodIndexEnvironment(Enum): | ||
""" | ||
These environment strings are used to specify where a pod index should be deployed. | ||
""" | ||
|
||
US_WEST1_GCP = "us-west1-gcp" | ||
US_CENTRAL1_GCP = "us-central1-gcp" | ||
US_WEST4_GCP = "us-west4-gcp" | ||
US_EAST4_GCP = "us-east4-gcp" | ||
NORTHAMERICA_NORTHEAST1_GCP = "northamerica-northeast1-gcp" | ||
ASIA_NORTHEAST1_GCP = "asia-northeast1-gcp" | ||
ASIA_SOUTHEAST1_GCP = "asia-southeast1-gcp" | ||
US_EAST1_GCP = "us-east1-gcp" | ||
EU_WEST1_GCP = "eu-west1-gcp" | ||
EU_WEST4_GCP = "eu-west4-gcp" | ||
US_EAST1_AWS = "us-east-1-aws" | ||
EASTUS_AZURE = "eastus-azure" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from enum import Enum | ||
|
||
|
||
class PodType(Enum): | ||
""" | ||
PodType represents the available pod types for a pod index. | ||
""" | ||
|
||
P1_X1 = "p1.x1" | ||
P1_X2 = "p1.x2" | ||
P1_X4 = "p1.x4" | ||
P1_X8 = "p1.x8" | ||
S1_X1 = "s1.x1" | ||
S1_X2 = "s1.x2" | ||
S1_X4 = "s1.x4" | ||
S1_X8 = "s1.x8" | ||
P2_X1 = "p2.x1" | ||
P2_X2 = "p2.x2" | ||
P2_X4 = "p2.x4" | ||
P2_X8 = "p2.x8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from enum import Enum | ||
|
||
|
||
class VectorType(Enum): | ||
""" | ||
VectorType is used to specifiy the type of vector you will store in the index. | ||
Dense vectors are used to store dense embeddings, which are vectors with non-zero values in most of the dimensions. | ||
Sparse vectors are used to store sparse embeddings, which allow vectors with zero values in most of the dimensions to be represented concisely. | ||
""" | ||
|
||
DENSE = "dense" | ||
SPARSE = "sparse" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.