Skip to content

Commit

Permalink
manage.py edits for configure_index
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat08 committed Aug 13, 2022
1 parent 78f54a8 commit e683d30
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pinecone/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

import time
from typing import NamedTuple
from typing import NamedTuple, Optional

import pinecone
from pinecone.config import Config
Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(self, keys, values):
self.__dict__[k] = v

def __str__(self):
return str(self.__dict__)
return str(self.__dict__)


def _get_api_instance():
Expand Down Expand Up @@ -202,7 +202,8 @@ def describe_index(name: str):
replicas=db['replicas'], dimension=db['dimension'], shards=db['shards'],
pods=db.get('pods', db['shards'] * db['replicas']), pod_type=db.get('pod_type', 'p1'),
index_config=db['index_config'], status={'ready': ready, 'state': state},
metadata_config=db.get('metadata_config'), source_collection=db.get('source_collection',''))
metadata_config=db.get('metadata_config'),
source_collection=db.get('source_collection', ''))


def scale_index(name: str, replicas: int):
Expand Down Expand Up @@ -255,15 +256,17 @@ def describe_collection(name: str):
return response_object


def configure_index(name: str, replicas: int = None, pod_type: str = ""):
def configure_index(name: str, replicas: Optional[int] = None, pod_type: Optional[str] = ""):
"""Changes current configuration of the index.
:param: name: the name of the Index
:param: replicas: the desired number of replicas, lowest value is 0.
:param: pod_type: the new pod_type for the index.
"""
api_instance = _get_api_instance()
config_args = {}
if pod_type != "":
config_args.update(pod_type=pod_type)
if replicas:
patch_request = PatchRequest(replicas=replicas, pod_type=pod_type)
else:
patch_request = PatchRequest(pod_type=pod_type)
config_args.update(replicas=replicas)
patch_request = PatchRequest(**config_args)
api_instance.configure_index(name, patch_request=patch_request)

0 comments on commit e683d30

Please sign in to comment.