
    _0                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  SS	KJr  SS
KJr   " S S\5      rg)z3Utilities for dealing with AI Platform indexes API.    )extra_types)
list_pager)apis)messages)
exceptions)	constants)errors)labels_util)yamlc                   n    \ rS rSrSrSS jrS rS rSS jrS r	S	 r
S
 rS rS rS rS rS rS rSrg)IndexesClient   z6High-level client for the AI Platform indexes surface.Nc                 
   U=(       d6    [         R                  " [        R                  [        R                  U   5      U l        U=(       d    U R
                  R                  U l        U R
                  R                  U l	        g N)
r   GetClientInstancer   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONclientMESSAGES_MODULEr   projects_locations_indexes_service)selfr   r   versions       /lib/googlecloudsdk/api_lib/ai/indexes/client.py__init__IndexesClient.__init__    s[     4D22&&))'24DK ; ; ;DMKK::DM    c                     U(       d  [         R                  " SS5      eSn[        R                  " U5      nU(       a%  [        R
                  " U[        R                  5      nU$ )zParse json metadata file.z--metadata-filez&Index metadata file must be specified.N)gcloud_exceptionsBadArgumentExceptionr   	load_pathmessages_utilDictToMessageWithErrorCheckr   	JsonValue)r   metadata_fileindex_metadatadatas       r   _ReadIndexMetadata IndexesClient._ReadIndexMetadata'   sW    22
EG GN>>-(D$@@
%%'nr   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ N)name)r   ,AiplatformProjectsLocationsIndexesGetRequestRelativeNamer   Getr   	index_refrequests      r   r/   IndexesClient.Get4   s=    mmHH##% I 'G==W%%r   c                     [         R                  " U R                  U R                  R	                  UR                  5       S9SSUS9$ )N)parentindexespageSize)fieldbatch_size_attributelimit)r   YieldFromListr   r   -AiplatformProjectsLocationsIndexesListRequestr.   )r   r:   
region_refs      r   ListIndexesClient.List9   sI    ##CC**, 	D 	.' r   c                 X   [         R                  " X R                  R                  R                  5      nSnUR
                  (       a  UR
                  S:X  a+  U R                  R                  R                  R                  nOkUR
                  S:X  a+  U R                  R                  R                  R                  nO0[        R                  " SSR                  UR
                  5      5      eSnUR                  b#  U R                  R                  UR                  S9nU R                  R                  UR                  5       U R                  R                  UR                   UR"                  U R%                  UR&                  5      UUUS9S9nU R(                  R+                  U5      $ )	zCreate a new index.Nstream-updatebatch-update--index-update-methodInvalid index update method: {}
kmsKeyNamedisplayNamedescriptionmetadatalabelsindexUpdateMethodencryptionSpec)r5   !googleCloudAiplatformV1beta1Index)r
   ParseCreateArgsr   !GoogleCloudAiplatformV1beta1IndexLabelsValueindex_update_method IndexUpdateMethodValueValuesEnumSTREAM_UPDATEBATCH_UPDATEr   r    formatencryption_kms_key_name*GoogleCloudAiplatformV1beta1EncryptionSpec/AiplatformProjectsLocationsIndexesCreateRequestr.   display_namerI   r(   r%   r   Creater   location_refargsrK   rR   encryption_specreqs          r   
CreateBetaIndexesClient.CreateBetaB   sw   ((mm==IIKF 		!	!_	4MM;;,,]] 	 ##~5MM;;,,\\ 	  44#-44T5M5MN
 	

 O##/
--
B
B55 C 7  --
G
G((**.--	*	*))((,,T-?-?@1* 
+ 
 H 
C ==$$r   c                 X   [         R                  " X R                  R                  R                  5      nSnUR
                  (       a  UR
                  S:X  a+  U R                  R                  R                  R                  nOkUR
                  S:X  a+  U R                  R                  R                  R                  nO0[        R                  " SSR                  UR
                  5      5      eSnUR                  b#  U R                  R                  UR                  S9nU R                  R                  UR                  5       U R                  R                  UR                   UR"                  U R%                  UR&                  5      UUUS9S9nU R(                  R+                  U5      $ )	zCreate a new v1 index.NrA   rB   rC   rD   rE   rG   )r5   googleCloudAiplatformV1Index)r
   rO   r   GoogleCloudAiplatformV1IndexrQ   rR   rS   rT   rU   r   r    rV   rW   %GoogleCloudAiplatformV1EncryptionSpecrY   r.   rZ   rI   r(   r%   r   r[   r\   s          r   r[   IndexesClient.Createj   sy   ((mm88DDFF 		!	!_	4MM66--mm 	 ##~5MM66WWdd 	  44#-44T5M5MN
 	

 O##/
--
=
=55 > 7  --
G
G((*%)]]%O%O))((,,T-?-?@1* &P & H 	C ==$$r   c                 8  ^ ^ T R                   R                  5       n/ nUR                  b2  T R                  UR                  5      Ul        UR                  S5        OUR                  b"  UR                  Ul        UR                  S5        UR                  b"  UR                  Ul        UR                  S5        UU 4S jn[        R                  " UT R                   R                  R                  U5      nUR                  (       a"  UR                  Ul        UR                  S5        U(       d  [        R                  " S5      eT R                   R!                  TR#                  5       USR%                  U5      S9nT R&                  R)                  U5      $ )	zUpdate an index.rJ   rZ   rI   c                  :   > TR                  T 5      R                  $ r   r/   rK   r1   r   s   r   	GetLabels*IndexesClient.PatchBeta.<locals>.GetLabels       xx	")))r   rK   No updates requested.,)r,   rN   
updateMask)r   rP   r%   r(   rJ   appendrZ   rH   rI   r
   ProcessUpdateArgsLazyrQ   needs_updaterK   r	   NoFieldsSpecifiedError.AiplatformProjectsLocationsIndexesPatchRequestr.   joinr   Patchr   r1   r^   indexupdate_maskrl   labels_updater2   s   ``      r   	PatchBetaIndexesClient.PatchBeta   sR   MM;;=EK%..t/A/ABen$				& -->*				% ,,=)* "77
??KK
m 
	#	#$++8$))*ABBmmJJ##%*/88K( K *G ==w''r   c                 8  ^ ^ T R                   R                  5       n/ nUR                  b2  T R                  UR                  5      Ul        UR                  S5        OUR                  b"  UR                  Ul        UR                  S5        UR                  b"  UR                  Ul        UR                  S5        UU 4S jn[        R                  " UT R                   R                  R                  U5      nUR                  (       a"  UR                  Ul        UR                  S5        U(       d  [        R                  " S5      eT R                   R!                  TR#                  5       USR%                  U5      S9nT R&                  R)                  U5      $ )	zUpdate an v1 index.rJ   rZ   rI   c                  :   > TR                  T 5      R                  $ r   rj   rk   s   r   rl   &IndexesClient.Patch.<locals>.GetLabels   rn   r   rK   ro   rp   )r,   rd   rq   )r   re   r%   r(   rJ   rr   rZ   rH   rI   r
   rs   rQ   rt   rK   r	   ru   rv   r.   rw   r   rx   ry   s   ``      r   rx   IndexesClient.Patch   sR   MM668EK%..t/A/ABen$				& -->*				% ,,=)* "77
::FF
m 
	#	#$++8$))*ABBmmJJ##%%*88K( K *G ==w''r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ r+   )r   /AiplatformProjectsLocationsIndexesDeleteRequestr.   r   Deleter0   s      r   r   IndexesClient.Delete   s=    mmKK##% L 'G==((r   c                 <   UR                   (       a'  UR                  (       a  [        R                  " S5      eUR                   (       aI  U R                  R                  UR                  5       U R                  R                  UR                   S9S9nUR                  (       a_  [        R                  " UR                  5      nU R                  R                  UR                  5       U R                  R                  US9S9nU R                  R                  W5      $ )z(Remove data points from a v1beta1 index.zGdatapoint_ids and datapoints_from_file can not be set at the same time.datapointIds)rz   3googleCloudAiplatformV1beta1RemoveDatapointsRequest)datapoint_idsdatapoints_from_filer	   ArgumentErrorr   9AiplatformProjectsLocationsIndexesRemoveDatapointsRequestr.   3GoogleCloudAiplatformV1beta1RemoveDatapointsRequestr   r!   r   RemoveDatapointsr   r1   r^   r`   r'   s        r   RemoveDatapointsBeta"IndexesClient.RemoveDatapointsBeta   s    d77   
 MMSS&&(>Bmm>>-- ? / T 0c
   ^^D556dMMSS&&(>Bmm>> ? ! T "c
 ==))#..r   c                 <   UR                   (       a'  UR                  (       a  [        R                  " S5      eUR                   (       aI  U R                  R                  UR                  5       U R                  R                  UR                   S9S9nUR                  (       a_  [        R                  " UR                  5      nU R                  R                  UR                  5       U R                  R                  US9S9nU R                  R                  W5      $ )z#Remove data points from a v1 index.zO`--datapoint_ids` and `--datapoints_from_file` can not be set at the same time.r   )rz   .googleCloudAiplatformV1RemoveDatapointsRequest)r   r   r	   r   r   r   r.   .GoogleCloudAiplatformV1RemoveDatapointsRequestr   r!   r   r   r   s        r   r   IndexesClient.RemoveDatapoints   s    d77   
 MMSS&&(9=99-- : / T 0c
   ^^D556dMMSS&&(9=99 : ! T "c
 ==))#..r   c                    / nUR                   (       ae  [        R                  " UR                   5      nU H?  n[        R                  " UU R
                  R                  5      nUR                  U5        MA     SnUR                  (       a  SR                  UR                  5      nU R
                  R                  UR                  5       U R
                  R                  UUS9S9nU R                  R                  U5      $ )z(Upsert data points from a v1beta1 index.Nrp   
datapointsrq   )rz   3googleCloudAiplatformV1beta1UpsertDatapointsRequest)r   r   r!   r"   r#   r   *GoogleCloudAiplatformV1beta1IndexDatapointrr   r{   rw   9AiplatformProjectsLocationsIndexesUpsertDatapointsRequestr.   3GoogleCloudAiplatformV1beta1UpsertDatapointsRequestr   UpsertDatapoints	r   r1   r^   r   r'   datapoint_json	datapointr{   r`   s	            r   UpsertDatapointsBeta"IndexesClient.UpsertDatapointsBeta  s    J  ^^D556d .!==MMDDF	 	)$	 !
 KHHT--.k
--
Q
Q$$&<@MM	<	<!" 
= 
$ R %C ==))#..r   c                    / nUR                   (       ae  [        R                  " UR                   5      nU H?  n[        R                  " UU R
                  R                  5      nUR                  U5        MA     SnUR                  (       a  SR                  UR                  5      nU R
                  R                  UR                  5       U R
                  R                  UUS9S9nU R                  R                  U5      $ )z#Upsert data points from a v1 index.Nrp   r   )rz   .googleCloudAiplatformV1UpsertDatapointsRequest)r   r   r!   r"   r#   r   %GoogleCloudAiplatformV1IndexDatapointrr   r{   rw   r   r.   .GoogleCloudAiplatformV1UpsertDatapointsRequestr   r   r   s	            r   r   IndexesClient.UpsertDatapoints"  s    J  ^^D556d .!==MM??A	 	)$	 !
 KHHT--.k
--
Q
Q$$&7;}}	7	7!" 
8 
$ R %C ==))#..r   )r   r   r   )NNN)NN)__name__
__module____qualname____firstlineno____doc__r   r(   r/   r>   ra   r[   r}   rx   r   r   r   r   r   __static_attributes__ r   r   r   r      sJ    >;&
&%P%%N"(H"(H)
/././,/r   r   N)r   apitools.base.pyr   r   googlecloudsdk.api_lib.utilr   r   r"   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.air   r	   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.corer   objectr   r   r   r   <module>r      s5    : ) ' , A C 3 0 < $Y/F Y/r   