
    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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.    )absolute_import)division)unicode_literals)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   r2   IndexesClient.Get7   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	   -AiplatformProjectsLocationsIndexesListRequestr1   )r   r=   
region_refs      r   ListIndexesClient.List<   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)r8   !googleCloudAiplatformV1beta1Index)r   ParseCreateArgsr	   !GoogleCloudAiplatformV1beta1IndexLabelsValueindex_update_method IndexUpdateMethodValueValuesEnumSTREAM_UPDATEBATCH_UPDATEr"   r#   formatencryption_kms_key_name*GoogleCloudAiplatformV1beta1EncryptionSpec/AiplatformProjectsLocationsIndexesCreateRequestr1   display_namerL   r+   r(   r   Creater   location_refargsrN   rU   encryption_specreqs          r   
CreateBetaIndexesClient.CreateBetaE   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.NrD   rE   rF   rG   rH   rJ   )r8   googleCloudAiplatformV1Index)r   rR   r	   GoogleCloudAiplatformV1IndexrT   rU   rV   rW   rX   r"   r#   rY   rZ   %GoogleCloudAiplatformV1EncryptionSpecr\   r1   r]   rL   r+   r(   r   r^   r_   s          r   r^   IndexesClient.Createm   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.rM   r]   rL   c                  :   > TR                  T 5      R                  $ r   r2   rN   r4   r   s   r   	GetLabels*IndexesClient.PatchBeta.<locals>.GetLabels       xx	")))r    rN   No updates requested.,)r/   rQ   
updateMask)r	   rS   r(   r+   rM   appendr]   rK   rL   r   ProcessUpdateArgsLazyrT   needs_updaterN   r   NoFieldsSpecifiedError.AiplatformProjectsLocationsIndexesPatchRequestr1   joinr   Patchr   r4   ra   indexupdate_maskro   labels_updater5   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.rM   r]   rL   c                  :   > TR                  T 5      R                  $ r   rm   rn   s   r   ro   &IndexesClient.Patch.<locals>.GetLabels   rq   r    rN   rr   rs   )r/   rg   rt   )r	   rh   r(   r+   rM   ru   r]   rK   rL   r   rv   rT   rw   rN   r   rx   ry   r1   rz   r   r{   r|   s   ``      r   r{   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	   /AiplatformProjectsLocationsIndexesDeleteRequestr1   r   Deleter3   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)r}   3googleCloudAiplatformV1beta1RemoveDatapointsRequest)datapoint_idsdatapoints_from_filer   ArgumentErrorr	   9AiplatformProjectsLocationsIndexesRemoveDatapointsRequestr1   3GoogleCloudAiplatformV1beta1RemoveDatapointsRequestr   r$   r   RemoveDatapointsr   r4   ra   rc   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   )r}   .googleCloudAiplatformV1RemoveDatapointsRequest)r   r   r   r   r	   r   r1   .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.Nrs   
datapointsrt   )r}   3googleCloudAiplatformV1beta1UpsertDatapointsRequest)r   r   r$   r%   r&   r	   *GoogleCloudAiplatformV1beta1IndexDatapointru   r~   rz   9AiplatformProjectsLocationsIndexesUpsertDatapointsRequestr1   3GoogleCloudAiplatformV1beta1UpsertDatapointsRequestr   UpsertDatapoints	r   r4   ra   r   r*   datapoint_json	datapointr~   rc   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.Nrs   r   )r}   .googleCloudAiplatformV1UpsertDatapointsRequest)r   r   r$   r%   r&   r	   %GoogleCloudAiplatformV1IndexDatapointru   r~   rz   r   r1   .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+   r2   rA   rd   r^   r   r{   r   r   r   r   r   __static_attributes__ r    r   r   r       sJ    >;&
&%P%%N"(H"(H)
/././,/r    r   N)r   
__future__r   r   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      s<    : &  ' ( ' , A C 3 0 < $Y/F Y/r    