pinecone.models
1from .index_description import ServerlessSpecDefinition, PodSpecDefinition 2from .collection_description import CollectionDescription 3from .serverless_spec import ServerlessSpec 4from .pod_spec import PodSpec 5from .index_list import IndexList 6from .collection_list import CollectionList 7from .index_model import IndexModel 8from .index_embed import IndexEmbed 9 10__all__ = [ 11 "CollectionDescription", 12 "PodSpec", 13 "PodSpecDefinition", 14 "ServerlessSpec", 15 "ServerlessSpecDefinition", 16 "IndexList", 17 "CollectionList", 18 "IndexModel", 19 "IndexEmbed", 20]
5class CollectionDescription(NamedTuple): 6 """ 7 The description of a collection. 8 """ 9 10 name: str 11 """ 12 The name of the collection. 13 """ 14 15 source: str 16 """ 17 The name of the index used to create the collection. 18 """
The description of a collection.
Create new instance of CollectionDescription(name, source)
Inherited Members
- builtins.tuple
- index
- count
8@dataclass(frozen=True) 9class PodSpec: 10 """ 11 PodSpec represents the configuration used to deploy a pod-based index. 12 13 To learn more about the options for each configuration, please see [Understanding Indexes](https://docs.pinecone.io/docs/indexes) 14 """ 15 16 environment: str 17 """ 18 The environment where the pod index will be deployed. Example: 'us-east1-gcp' 19 """ 20 21 replicas: Optional[int] = None 22 """ 23 The number of replicas to deploy for the pod index. Default: 1 24 """ 25 26 shards: Optional[int] = None 27 """ 28 The number of shards to use. Shards are used to expand the amount of vectors you can store beyond the capacity of a single pod. Default: 1 29 """ 30 31 pods: Optional[int] = None 32 """ 33 Number of pods to deploy. Default: 1 34 """ 35 36 pod_type: Optional[str] = "p1.x1" 37 """ 38 This value combines pod type and pod size into a single string. This configuration is your main lever for vertical scaling. 39 """ 40 41 metadata_config: Optional[Dict] = field(default_factory=dict) 42 """ 43 If you are storing a lot of metadata, you can use this configuration to limit the fields which are indexed for search. 44 45 This configuration should be a dictionary with the key 'indexed' and the value as a list of fields to index. 46 47 Example: 48 ``` 49 {'indexed': ['field1', 'field2']} 50 ``` 51 """ 52 53 source_collection: Optional[str] = None 54 """ 55 The name of the collection to use as the source for the pod index. This configuration is only used when creating a pod index from an existing collection. 56 """ 57 58 def __init__( 59 self, 60 environment: Union[PodIndexEnvironment, str], 61 pod_type: Union[PodType, str] = "p1.x1", 62 replicas: Optional[int] = None, 63 shards: Optional[int] = None, 64 pods: Optional[int] = None, 65 metadata_config: Optional[Dict] = None, 66 source_collection: Optional[str] = None, 67 ): 68 object.__setattr__( 69 self, 70 "environment", 71 environment.value if isinstance(environment, PodIndexEnvironment) else str(environment), 72 ) 73 object.__setattr__( 74 self, "pod_type", pod_type.value if isinstance(pod_type, PodType) else str(pod_type) 75 ) 76 object.__setattr__(self, "replicas", replicas) 77 object.__setattr__(self, "shards", shards) 78 object.__setattr__(self, "pods", pods) 79 object.__setattr__( 80 self, "metadata_config", metadata_config if metadata_config is not None else {} 81 ) 82 object.__setattr__(self, "source_collection", source_collection) 83 84 def asdict(self) -> Dict: 85 """ 86 Returns the PodSpec as a dictionary. 87 """ 88 return {"pod": self.__dict__}
PodSpec represents the configuration used to deploy a pod-based index.
To learn more about the options for each configuration, please see Understanding Indexes
58 def __init__( 59 self, 60 environment: Union[PodIndexEnvironment, str], 61 pod_type: Union[PodType, str] = "p1.x1", 62 replicas: Optional[int] = None, 63 shards: Optional[int] = None, 64 pods: Optional[int] = None, 65 metadata_config: Optional[Dict] = None, 66 source_collection: Optional[str] = None, 67 ): 68 object.__setattr__( 69 self, 70 "environment", 71 environment.value if isinstance(environment, PodIndexEnvironment) else str(environment), 72 ) 73 object.__setattr__( 74 self, "pod_type", pod_type.value if isinstance(pod_type, PodType) else str(pod_type) 75 ) 76 object.__setattr__(self, "replicas", replicas) 77 object.__setattr__(self, "shards", shards) 78 object.__setattr__(self, "pods", pods) 79 object.__setattr__( 80 self, "metadata_config", metadata_config if metadata_config is not None else {} 81 ) 82 object.__setattr__(self, "source_collection", source_collection)
The number of shards to use. Shards are used to expand the amount of vectors you can store beyond the capacity of a single pod. Default: 1
This value combines pod type and pod size into a single string. This configuration is your main lever for vertical scaling.
If you are storing a lot of metadata, you can use this configuration to limit the fields which are indexed for search.
This configuration should be a dictionary with the key 'indexed' and the value as a list of fields to index.
Example:
{'indexed': ['field1', 'field2']}
5class PodSpecDefinition(NamedTuple): 6 replicas: int 7 shards: int 8 pods: int 9 pod_type: str 10 environment: str 11 metadata_config: Optional[Dict]
PodSpecDefinition(replicas, shards, pods, pod_type, environment, metadata_config)
Create new instance of PodSpecDefinition(replicas, shards, pods, pod_type, environment, metadata_config)
Inherited Members
- builtins.tuple
- index
- count
9@dataclass(frozen=True) 10class ServerlessSpec: 11 cloud: str 12 region: str 13 14 def __init__( 15 self, 16 cloud: Union[CloudProvider, str], 17 region: Union[AwsRegion, GcpRegion, AzureRegion, str], 18 ): 19 # Convert Enums to their string values if necessary 20 object.__setattr__(self, "cloud", cloud.value if isinstance(cloud, Enum) else str(cloud)) 21 object.__setattr__( 22 self, "region", region.value if isinstance(region, Enum) else str(region) 23 ) 24 25 def asdict(self): 26 return {"serverless": {"cloud": self.cloud, "region": self.region}}
14 def __init__( 15 self, 16 cloud: Union[CloudProvider, str], 17 region: Union[AwsRegion, GcpRegion, AzureRegion, str], 18 ): 19 # Convert Enums to their string values if necessary 20 object.__setattr__(self, "cloud", cloud.value if isinstance(cloud, Enum) else str(cloud)) 21 object.__setattr__( 22 self, "region", region.value if isinstance(region, Enum) else str(region) 23 )
ServerlessSpecDefinition(cloud, region)
Create new instance of ServerlessSpecDefinition(cloud, region)
Inherited Members
- builtins.tuple
- index
- count
8class IndexList: 9 def __init__(self, index_list: OpenAPIIndexList): 10 self.index_list = index_list 11 self.indexes = [IndexModel(i) for i in self.index_list.indexes] 12 self.current = 0 13 14 def names(self) -> List[str]: 15 return [i.name for i in self.indexes] 16 17 def __getitem__(self, key): 18 return self.indexes[key] 19 20 def __len__(self): 21 return len(self.indexes) 22 23 def __iter__(self): 24 return iter(self.indexes) 25 26 def __str__(self): 27 return str(self.indexes) 28 29 def __repr__(self): 30 return json.dumps([i.to_dict() for i in self.indexes], indent=4) 31 32 def __getattr__(self, attr): 33 return getattr(self.index_list, attr)
6class CollectionList: 7 """ 8 A list of collections. 9 """ 10 11 def __init__(self, collection_list: OpenAPICollectionList): 12 self.collection_list = collection_list 13 self.current = 0 14 15 def names(self): 16 return [i["name"] for i in self.collection_list.collections] 17 18 def __getitem__(self, key): 19 return self.collection_list.collections[key] 20 21 def __len__(self): 22 return len(self.collection_list.collections) 23 24 def __iter__(self): 25 return iter(self.collection_list.collections) 26 27 def __str__(self): 28 return str(self.collection_list) 29 30 def __repr__(self): 31 return json.dumps([c.to_dict() for c in self.collection_list.collections], indent=4) 32 33 def __getattr__(self, attr): 34 return getattr(self.collection_list, attr)
A list of collections.
5class IndexModel: 6 def __init__(self, index: OpenAPIIndexModel): 7 self.index = index 8 self.deletion_protection = index.deletion_protection.value 9 10 def __str__(self): 11 return str(self.index) 12 13 def __getattr__(self, attr): 14 return getattr(self.index, attr) 15 16 def __getitem__(self, key): 17 return self.__getattr__(key) 18 19 def to_dict(self): 20 return self.index.to_dict()
9@dataclass(frozen=True) 10class IndexEmbed: 11 """ 12 IndexEmbed represents the index embedding configuration when creating an index from a model. 13 """ 14 15 model: str 16 """ 17 The name of the embedding model to use for the index. 18 Required. 19 """ 20 21 field_map: Dict[str, Any] 22 """ 23 A mapping of field names to their types. 24 Required. 25 """ 26 27 metric: Optional[str] = None 28 """ 29 The metric to use for the index. If not provided, the default metric for the model is used. 30 Optional. 31 """ 32 33 read_parameters: Optional[Dict[str, Any]] = None 34 """ 35 The parameters to use when reading from the index. 36 Optional. 37 """ 38 39 write_parameters: Optional[Dict[str, Any]] = None 40 """ 41 The parameters to use when writing to the index. 42 Optional. 43 """ 44 45 def as_dict(self) -> Dict[str, Any]: 46 """ 47 Returns the IndexEmbed as a dictionary. 48 """ 49 return self.__dict__ 50 51 def __init__( 52 self, 53 model: Union[EmbedModel, str], 54 field_map: Dict[str, Any], 55 metric: Optional[Union[Metric, str]] = None, 56 read_parameters: Optional[Dict[str, Any]] = None, 57 write_parameters: Optional[Dict[str, Any]] = None, 58 ): 59 object.__setattr__( 60 self, "model", model.value if isinstance(model, EmbedModel) else str(model) 61 ) 62 object.__setattr__(self, "field_map", field_map) 63 object.__setattr__(self, "metric", metric.value if isinstance(metric, Metric) else metric) 64 object.__setattr__( 65 self, "read_parameters", read_parameters if read_parameters is not None else {} 66 ) 67 object.__setattr__( 68 self, "write_parameters", write_parameters if write_parameters is not None else {} 69 )
IndexEmbed represents the index embedding configuration when creating an index from a model.
51 def __init__( 52 self, 53 model: Union[EmbedModel, str], 54 field_map: Dict[str, Any], 55 metric: Optional[Union[Metric, str]] = None, 56 read_parameters: Optional[Dict[str, Any]] = None, 57 write_parameters: Optional[Dict[str, Any]] = None, 58 ): 59 object.__setattr__( 60 self, "model", model.value if isinstance(model, EmbedModel) else str(model) 61 ) 62 object.__setattr__(self, "field_map", field_map) 63 object.__setattr__(self, "metric", metric.value if isinstance(metric, Metric) else metric) 64 object.__setattr__( 65 self, "read_parameters", read_parameters if read_parameters is not None else {} 66 ) 67 object.__setattr__( 68 self, "write_parameters", write_parameters if write_parameters is not None else {} 69 )
The metric to use for the index. If not provided, the default metric for the model is used. Optional.
The parameters to use when reading from the index. Optional.