
    dhF                      S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKrS SKJr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.J/r/  S SK0J1r1  \Rd                  " 5       r3\(       a.  S SK4J5r5  S SK6J7r7  S SK8J9r9J:r:  S SK;J<r<  S SK;J9r=  S SK>J?r?J@r@JArAJBrBJCrC  \*" SSSS9rD\*" SSSS9rE\*" SSSS9rF\*" SSSS9rGSrH\               S+                                   S,S jj5       rI\               S-                                   S.S jj5       rI               S+                                   S/S  jjrI " S! S"\,5      rJ " S# S$\(5      rK    S0S% jrL    S1S& jrM  S2         S3S' jjrN  S2         S4S( jjrOS5S) jrPS6S7S* jjrQg)8    )annotationsN)TracebackType)TYPE_CHECKINGAnyCallableClassVar
CollectionDictIterableListLiteralOptionalTupleTypeUnioncastoverload)#AsyncCallbackManagerForRetrieverRunCallbackManagerForRetrieverRun)Document)
Embeddings)LangChainException)BaseRetriever)get_from_env)VectorStore)
ConfigDictmodel_validator)maximal_marginal_relevance)TokenCredentialAsyncTokenCredential)SearchClientSearchItemPaged)AsyncSearchItemPagedr"   )CorsOptionsScoringProfileSearchFieldSemanticConfigurationVectorSearchAZURESEARCH_FIELDS_IDid)keyenv_keydefaultAZURESEARCH_FIELDS_CONTENTcontent!AZURESEARCH_FIELDS_CONTENT_VECTORcontent_vectorAZURESEARCH_FIELDS_TAGmetadatai  c                    g N endpoint
index_namer-   azure_ad_access_tokensemantic_configuration_namefieldsvector_searchsemantic_configurationsscoring_profilesdefault_scoring_profiledefault_fields
user_agentcors_optionsasync_ additional_search_client_optionsazure_credentialazure_async_credentials                    d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/vectorstores/azuresearch.py_get_search_clientrK   V   s    *     c                    g r7   r8   r9   s                    rJ   rK   rK   n   s    *  #rL   c                8  ^7^8^9 SSK Jm7JnJn  SSKJn  SSKJn  SSKJ	nJ
n  SSKJ	n  SSKJn  SSKJn  SSKJn  SS	KJnJnJnJnJnJn Jn!Jn"Jn#Jn$Jn%Jn&Jn'   " U74S
 jSU5      n( " S SU5      n)U=(       d    0 nU
=(       d    / n
UbJ  UR?                  5       S:X  a+  [A        SU" 5       5      n*U*RC                  S5        U)" U*5      n+O?U" U5      n*U*n+O4Ub  U(" U5      n*U)" U*5      n+O U=(       d    U" 5       n*U=(       d    U" 5       n+U" S*U U*US.UD6n, U,RE                  US9  U(       d  U" S*U UU*US).UD6$ U" S*U UU+US).UD6$ ! U Ga    UGb  U V-s0 sH  n-U-RF                  U-RH                  _M     Os  sn-f sn-m8U
 V.s0 sH  n.U.RF                  U.RH                  _M     Os  sn.f sn.m9[K        T9RM                  5       5      [K        T8RM                  5       5      -
   VV/s0 sH  u  nn/UT9U   _M     Os  sn/nf n0nn/[O        U05      S:  aG  S+U8U94S jjn1SRQ                  U0 V2s/ sH  n2U1" U25      PM     Os  sn2f sn25      n3[S        SU0 SU3 35      eOU
nUcT  U$" U" SU%RT                  U" SSSU&RV                  S9S9U" SU%RX                  U" U&RV                  S9S9/U'" SSS 9U'" S!SS 9/S"9nU(       a   [[        U[\        5      (       d  U/nU#" UUS#9n4O%U(       a  U " UU"" U!" [^        S$9/S%9S&9n5U#" U5/S'9n4OS n4U" UUUU4UU	US(9n6U,Ra                  U65         GNf = f),Nr   )AccessTokenAzureKeyCredentialr   r    )ResourceNotFoundError)DefaultAzureCredentialInteractiveBrowserCredential)rR   r%   )SearchIndexClient)#ExhaustiveKnnAlgorithmConfigurationExhaustiveKnnParametersHnswAlgorithmConfigurationHnswParametersSearchIndexr)   SemanticFieldSemanticPrioritizedFieldsSemanticSearchr*   VectorSearchAlgorithmKindVectorSearchAlgorithmMetricVectorSearchProfilec                  R   > \ rS rSrSU 4S jjrSSSS.           S	S jjrSrg)
6_get_search_client.<locals>.AzureBearerTokenCredential   c                `   > T" U[        [        R                  " 5       5      S-   5      U l        g )Ni  )inttime_token)selftokenrO   s     rJ   __init__?_get_search_client.<locals>.AzureBearerTokenCredential.__init__   s!    %eS-=-DEDKrL   NFclaims	tenant_id
enable_caec                   U R                   $ r7   rf   rg   rl   rm   rn   scopeskwargss         rJ   	get_token@_get_search_client.<locals>.AzureBearerTokenCredential.get_token   s     ;;rL   rp   )rh   strrr   rv   rl   Optional[str]rm   rx   rn   boolrs   r   returnrO   )__name__
__module____qualname____firstlineno__ri   rt   __static_attributes__)rO   s   rJ   AzureBearerTokenCredentialra      sX    	F %)'+$		 "	 %		
 	 	 	 	rL   r   c                  v    \ rS rSrS
S jrSSSS.           SS jjrSS jr   S       SS jjrS	rg)7_get_search_client.<locals>.AsyncTokenCredentialWrapper   c                    Xl         g r7   _credential)rg   
credentials     rJ   ri   @_get_search_client.<locals>.AsyncTokenCredentialWrapper.__init__   s    )rL   NFrk   c               J   #    U R                   R                  " UUUUS.UD6$ 7f)Nrk   )r   rt   rq   s         rJ   rt   A_get_search_client.<locals>.AsyncTokenCredentialWrapper.get_token   s6      ##--#%	
  s   !#c                   #    g 7fr7   r8   rg   s    rJ   close=_get_search_client.<locals>.AsyncTokenCredentialWrapper.close   s        c                   #    g 7fr7   r8   )rg   exc_type	exc_value	tracebacks       rJ   	__aexit__A_get_search_client.<locals>.AsyncTokenCredentialWrapper.__aexit__   s
      r   r   )r   r   rw   rz   None)NNN)r   zOptional[Type[BaseException]]r   zOptional[BaseException]r   zOptional[TracebackType]rz   r   )	r{   r|   r}   r~   ri   rt   r   r   r   r8   rL   rJ   AsyncTokenCredentialWrapperr      s    	* %)'+$		 "	 %		
 	 	 	 	
 7;1515		3	 /	 /		
 	 	rL   r   INTERACTIVEr   z!https://search.azure.com/.default)r:   r   rD   )namec           
        > U  STR                  U S5       STR                  U 5       STR                  U 5       SU R                  5        S3
$ )Nz current type: 'MISSINGz'. It has to be 'z#' or you can point to a different 'z;' field name by using the env variable 'AZURESEARCH_FIELDS_')getupper)xfields_typesmandatory_fieldss    rJ   fmt_err#_get_search_client.<locals>.fmt_err  sk    #-l.>.>q).L-M N))9)=)=a)@(A B++;+?+?+B*C DFFGggi[PQSrL   
z2You need to specify at least the following fields z; or provide alternative field names in the env variables.

r/      i  i  )mef_construction	ef_searchmetric)r   kind
parametersdefault_exhaustive_knn)r   myHnswProfile)r   algorithm_configuration_namemyExhaustiveKnnProfile)
algorithmsprofiles)configurationsdefault_configuration_name)
field_name)content_fields)r   prioritized_fields)r   )r   r>   r?   semantic_searchrA   rB   rE   )r:   r;   r   rD   r8   )r   rv   rz   rv   )1azure.core.credentialsrO   rP   r   azure.core.credentials_asyncr!   azure.core.exceptionsrQ   azure.identityrR   rS   azure.identity.aioazure.search.documentsr"   azure.search.documents.aioazure.search.documents.indexesrT   %azure.search.documents.indexes.modelsrU   rV   rW   rX   rY   r)   rZ   r[   r\   r*   r]   r^   r_   r   r   rt   	get_indexr   typesetitemslenjoin
ValueErrorHNSWCOSINEEXHAUSTIVE_KNN
isinstancelistFIELDS_CONTENTcreate_index):r:   r;   r-   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rP   r   r!   rQ   rR   rS   AsyncDefaultAzureCredentialr"   AsyncSearchClientrT   rU   rV   rW   rX   rY   r)   rZ   r[   r\   r*   r]   r^   r_   r   r   r   async_credentialindex_clientfdfvaluemissing_fieldsr   r   errorr   semantic_configurationindexrO   r   r   s:                                                          @@@rJ   rK   rK      s   * XWA;SX3L@    _ &: > (H'M2$#)rN
 99;-'/1M1OPJ  !DE::F+C0J)		*/0EF
6zB%A)?)A
1R5P5R&7 '' +	'La)J/F  
!!!	

 /
 	
 ! 
!'!	

 /
 	
W ! _)4:;FqAFFAFFNF;L;IJ>R 0>J #&&6&<&<&>"?l((*+#,#,JC %c**#,N 
 >"Q&  		~"F~!71:~"FG H%& '%%*G-  '" $F (.&6;;#1,/&)#>#E#E	$	 856EE#:#>#E#E$( (,5> (55M	)MB #5t<<+B*C',6+FO )%:0#<$1^$L#M$&" -=S<TUO #O '+-$;%
 	!!%(_)sC   E L E54L F"!?L G321L#H5
4C!LLc                     \ rS rSrSr        S:SSSSSS.                                   S;S jjjrS<S jr\S=S j5       rS>S jr	 S?SS	.         S@S
 jjjr
 S?SS	.         S@S jjjr S?SS	.       SAS jjjr S?SS	.       SAS jjjrS?SBS jjrS?SBS jjr SCSS.         SDS jjjrSS.       SES jjr SCSS.         SDS jjjrSS.       SES jjr SCSS.         SFS jjjr SCSS.         SFS jjjr SCSS.         SGS jjjr SCSS.         SGS jjjr  SH         SIS jjr  SH         SIS jjr   SJSS.             SKS jjjr   SJSS.             SKS  jjjrSCSLS! jjr SC       SLS" jjr  SH         SIS# jjr  SH         SIS$ jjr SCSS.         SFS% jjjr  SCSS.         SFS& jjjr!   SJSS.             SKS' jjjr"   SJSS.             SKS( jjjr#SS.           SMS) jjr$SS.           SNS* jjr% SC       SLS+ jjr& SC       SLS, jjr'  SOSS.           SPS- jjjr(  SOSS.           SPS. jjjr) SCSS.         SQS/ jjjr* SCSS.         SQS0 jjjr+\,      SR                     SSS3 jj5       r-\,      SR                     SSS4 jj5       r.\, S?S1S1S2SS5.                   STS6 jjj5       r/\, S?S1S1S2SS5.                   STS7 jjj5       r0SUS8 jr1S9r2g)VAzureSearchir  z&`Azure Cognitive Search` vector store.N)vector_search_dimensionsrG   r<   rH   rI   c                   SSK JnJnJnJn   X@l        [        U R                  [        5      (       a  U R                  R                  U l	        OU R                  U l	        U" [        UR                  SSS9U" [        UR                  S9U" [        UR                  UR                  5      SU=(       d    [!        U R                  S5      5      SS	9U" ["        UR                  S9/nS
nSU;   a  US   (       a  USUS   -   -  n[%        UUUUUUUU	U
UUUU[&        R(                  " U5      US9U l        [%        UUUUUUUU	U
UUUUSUUUS9U l        XPl        X`l        U(       a  UOUU l        Xl        X l        X0l        X`l        Xpl        Xl        Xl         Xl!        Xl"        UU l#        UU l$        Xl%        g ! [
         a  n[        S5      UeS nAff = f)Nr   )SearchableFieldr(   SearchFieldDataTypeSimpleFieldzeUnable to import azure.search.documents. Please install with `pip install -U azure-search-documents`.T)r   r   r-   
filterable)r   r   Textr   )r   r   
searchabler   vector_search_profile_name	langchainrD    )r=   r>   r?   r@   rA   rB   rC   rD   rE   rG   rH   )r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   )&r   r   r(   r   r   ImportErrorembedding_functionr   r   embed_query	FIELDS_IDStringr   FIELDS_CONTENT_VECTORr	   Singler   FIELDS_METADATArK   copydeepcopyclientasync_clientsearch_typer=   r>   _azure_search_endpoint_azure_search_key_index_name_semantic_configuration_name_fields_vector_search_semantic_configurations_scoring_profiles_default_scoring_profile_default_fields_user_agent_cors_options)rg   azure_search_endpointazure_search_keyr;   r   r   r=   r>   r?   r@   rA   rB   rE   r   rG   r<   rH   rI   rs   r   r(   r   r   erC   rD   s                             rJ   ri   AzureSearch.__init__u  s&   0	  	4"4d--z::#66BBD#66D (//	 #(// *(334G4N4NO)A *1t''/0+: $(//'
0 !
6!f\&:#| 444J )!!(C'$;-$;)!%-1]]0. .#
* /!!(C'$;-$;)!%-M-#9#
& '+F( &fN&;#!1%,G)+(?%!1(?%-%)G  	; 	s   F: :
GGGc                   [        U S5      (       a+  U R                  (       a  U R                  R                  5         [        U S5      (       a  U R                  (       a   [        R
                  " 5       nUR                  5       (       a*  UR                  U R                  R                  5       5        g UR                  U R                  R                  5       5        g g g ! [         a}    [        R                  " 5       n[        R                  " U5         UR                  U R                  R                  5       5        UR                  5          g ! UR                  5         f = ff = f)Nr   r   )hasattrr   r   r   asyncioget_event_loop
is_runningcreate_taskrun_until_completeRuntimeErrornew_event_loopset_event_loop)rg   loops     rJ   __del__AzureSearch.__del__  s   4""t{{KK 4((T->->!--/??$$$$T%6%6%<%<%>? ++D,=,=,C,C,EF .?(   !--/&&t,!++D,=,=,C,C,EFJJLDJJL!s+    AC  4)C   5E')E?E'E##E'c                \    [        U R                  [        5      (       a  U R                  $ S $ r7   )r   r   r   r   s    rJ   
embeddingsAzureSearch.embeddings  s1    
 $11:>> ##	
 	
rL   c                   #    U R                   (       a#  U R                   R                  U5      I S h  vN $ [        [        U R                  5      " U5      $  N$7fr7   )r  aembed_queryr   r   r   )rg   texts     rJ   _aembed_queryAzureSearch._aembed_query  sA     ??55d;;;$"9"9:4@@ <s   0AA%Akeysc               *   [        U R                  [        5      (       a&   U R                  R                  [	        U5      5      nOU Vs/ sH  o`R                  U5      PM     nn[        U5      S:X  a  [        R                  S5        / $ U(       d&  SU;   a   [        US   5      [        U5      :X  a  US   nU R                  [        X5      X#S9$ ! [
         a2    U Vs/ sH  o`R                  R                  U5      PM     Os  snf nn Nf = fs  snf )z$Add texts data to an existing index.r   Nothing to insert, skipping.idsr  )r   r   r   embed_documentsr   NotImplementedErrorr   r   loggerdebugadd_embeddingsziprg   texts	metadatasr  rs   r  r   s          rJ   	add_textsAzureSearch.add_texts!  s     d--z::U!44DDT%[Q
 ?DDe11!4eJDz?aLL78I
 5F?VE]1Cs:1V%=D""3u#99"PP ' UNSTe55AA!DeT
T
U Es#   $C 
DD#DDDc               l  #    [        U R                  [        5      (       a.   U R                  R                  [	        U5      5      I S h  vN nOU Vs/ sH  o`R                  U5      PM     nn[        U5      S:X  a  [        R                  S5        / $ U(       d&  SU;   a   [        US   5      [        U5      :X  a  US   nU R                  [        X5      X#S9I S h  vN $  N! [
         a;    U Vs/ sH&  o`R                  R                  U5      I S h  vN  PM(     Os  snf nn Nf = fs  snf  NS7f)Nr   r  r  r  )r   r   r   aembed_documentsr   r   r  r   r!  r"  aadd_embeddingsr$  r%  s          rJ   
aadd_textsAzureSearch.aadd_texts?  s     d--z::#'#:#:#K#KDQVK#XX
 ?DDe11!4eJDz?aLL78I
 5F?VE]1Cs:1V%=D))#e*@))WWW% Y& KPKPa11>>qAAA5
 

 E Xsk    D4'C% 
C#C% D4D--A1D4D2D4#C% %D*3"D D	D D*'D4)D**	D4c               2   / n/ n[        U5       GH  u  nu  pxU(       a  X6   n	OM[        [        R                  " 5       5      n	[        R
                  " [        U	S5      5      R                  S5      n	U(       a  X&   O0 n
SS[        U	[        U[        [        R                  " U[        R                  S9R                  5       [        [         R"                  " U
5      0nU
(       a`  U
R%                  5        VVVs0 sH1  u  pXR&                   Vs/ sH  oR(                  PM     sn;   d  M/  X_M3     nnnnUR+                  U5        UR-                  U5        UR-                  U	5        [/        U5      [0        :X  d  GMm  U R2                  R5                  US9n[7        S U 5       5      (       d  [9        U5      e/ nGM     [/        U5      S:X  a  U$ U R2                  R5                  US9n[7        S	 U 5       5      (       a  U$ [9        U5      es  snf s  snnnf )
$Add embeddings to an existing index.utf-8ascii@search.actionuploaddtype	documentsc              3  6   #    U H  oR                   v   M     g 7fr7   	succeeded.0rs     rJ   	<genexpr>-AzureSearch.add_embeddings.<locals>.<genexpr>       91;;   r   c              3  6   #    U H  oR                   v   M     g 7fr7   r:  r<  s     rJ   r?  r@         -Hq{{HrB  )	enumeraterv   uuiduuid4base64urlsafe_b64encodebytesdecoder   r   r   nparrayfloat32tolistr   jsondumpsr   r>   r   updateappendr   MAX_UPLOAD_BATCH_SIZEr   upload_documentsallr   rg   text_embeddingsr'  r  r  datair  	embeddingr-   r5   dockvr   additional_fieldsresponses                    rJ   r#  AzureSearch.add_embeddings]  s     $-o$> A g$**,'..uS'/BCJJ7S'0y|bH !(3%rxx	'L'S'S'UH!5C  !) 0% 0[[9[VV[99 AD 0 " %
 

,-KKJJsO4y11;;77$7G9999,X66G %?L t9>J ;;//$/?-H---J$X..1 :%s   9H
H"H
*H
H
c               `  #    / n/ n[        U5       GH  u  nu  pxU(       a  X6   O[        [        R                  " 5       5      n	[        R
                  " [        U	S5      5      R                  S5      n	U(       a  X&   O0 n
SS[        U	[        U[        [        R                  " U[        R                  S9R                  5       [        [         R"                  " U
5      0nU
(       a`  U
R%                  5        VVVs0 sH1  u  pXR&                   Vs/ sH  oR(                  PM     sn;   d  M/  X_M3     nnnnUR+                  U5        UR-                  U5        UR-                  U	5        [/        U5      [0        :X  d  GMl  U R2                  R5                  US9I Sh  vN n[7        S U 5       5      (       d  [9        U5      e/ nGM     [/        U5      S	:X  a  U$ U R2                  R5                  US9I Sh  vN n[7        S
 U 5       5      (       a  U$ [9        U5      es  snf s  snnnf  N N67f)r0  r1  r2  r3  r4  r5  r7  Nc              3  6   #    U H  oR                   v   M     g 7fr7   r:  r<  s     rJ   r?  .AzureSearch.aadd_embeddings.<locals>.<genexpr>  rA  rB  r   c              3  6   #    U H  oR                   v   M     g 7fr7   r:  r<  s     rJ   r?  rd    rD  rB  )rE  rv   rF  rG  rH  rI  rJ  rK  r   r   r   rL  rM  rN  rO  r   rP  rQ  r   r>   r   rR  rS  r   rT  r   rU  rV  r   rW  s                    rJ   r,  AzureSearch.aadd_embeddings  s      $-o$> A !$'s4::<'8C**5g+>?FFwOC'0y|bH !(3%rxx	'L'S'S'UH!5C  !) 0% 0[[9[VV[99 AD 0 " %
 

,-KKJJsO4y11!%!2!2!C!Cd!C!SS9999,X66? %?D t9>J **;;d;KK-H---J$X..1 :% T LsV   C8H.:H#
H#H#
+H#
1AH.>H.H*AH.5H,6(H.H#
#H.,H.c                    U(       a?  U R                   R                  U Vs/ sH  n[        U0PM     sn5      n[        U5      S:  $ gs  snf )Delete by vector ID.

Args:
    ids: List of ids to delete.

Returns:
    bool: True if deletion is successful,
    False otherwise.
r   F)r   delete_documentsr   r   rg   r  rs   rZ  ress        rJ   deleteAzureSearch.delete  sE     ++../L1A/LMCs8a< 0Ms   Ac                   #    U(       aC  U R                   R                  U Vs/ sH  nSU0PM	     sn5      I Sh  vN n[        U5      S:  $ gs  snf  N7f)rh  r,   Nr   F)r   ri  r   rj  s        rJ   adeleteAzureSearch.adelete  sP      ))::s;Ss!T1Is;STTCs8a< <TTs   !AA
AAAr   )r   c                   U=(       d    U R                   nUS:X  a  U R                  " U4SU0UD6nU$ US:X  a  U R                  " U4SU0UD6nU$ US:X  a  U R                  " U4SU0UD6nU$ [	        SU S35      eN
similarityr]  hybridsemantic_hybridsearch_type of  not allowed.)r   r?   hybrid_searchsemantic_hybrid_searchr   rg   queryr]  r   rs   docss         rJ   similarity_searchAzureSearch.similarity_search  s     "5T%5%5,&%%e;q;F;D  H$%%e;q;F;D
 	 --..uDDVDD  {m=IJJrL   )r]  c                   UR                  SU R                  5      nUS:X  a  U R                  " U4SU0UD6$ US:X  a  U R                  " U4SU0UD6$ US:X  a  U R                  " U4SU0UD6$ [        SU S35      e)$Run similarity search with distance.r   rs  r]  rt  ru  rv  rw  )popr   vector_search_with_scorehybrid_search_with_score!semantic_hybrid_search_with_scorer   rg   r{  r]  rs   r   s        rJ   similarity_search_with_score(AzureSearch.similarity_search_with_score  s    
 jj0@0@A,&00F!FvFFH$00F!FvFF--99%O1OOO{m=IJJrL   c               <  #    U=(       d    U R                   nUS:X  a  U R                  " U4SU0UD6I S h  vN nU$ US:X  a  U R                  " U4SU0UD6I S h  vN nU$ US:X  a  U R                  " U4SU0UD6I S h  vN nU$ [	        SU S35      e N_ N< N7frr  )r   avector_searchahybrid_searchasemantic_hybrid_searchr   rz  s         rJ   asimilarity_searchAzureSearch.asimilarity_search  s      "5T%5%5,&,,UBaB6BBD  H$,,UBaB6BBD
 	 --55eKqKFKKD  {m=IJJ CBKs3   4BB$BB$B BBBBc               >  #    UR                  SU R                  5      nUS:X  a  U R                  " U4SU0UD6I Sh  vN $ US:X  a  U R                  " U4SU0UD6I Sh  vN $ US:X  a  U R                  " U4SU0UD6I Sh  vN $ [        SU S35      e NY N8 N7f)	r  r   rs  r]  Nrt  ru  rv  rw  )r   r   avector_search_with_scoreahybrid_search_with_score"asemantic_hybrid_search_with_scorer   r  s        rJ   asimilarity_search_with_score)AzureSearch.asimilarity_search_with_score(  s      jj0@0@A,&77MMfMMMH$77MMfMMM--@@V!VvVVV{m=IJJ NMVs3   ;BB"B B!"BBBBB)score_thresholdc               x    U R                   " U4SU0UD6nUc  U$ U Vs/ sH  ofS   U:  d  M  UPM     sn$ s  snf Nr]     r  rg   r{  r]  r  rs   resultr>  s          rJ   'similarity_search_with_relevance_scores3AzureSearch.similarity_search_with_relevance_scores6  X     ..uDDVD & 	
 $?Vt'>!V?	
 @   77c                  #    U R                   " U4SU0UD6I S h  vN nUc  U$ U Vs/ sH  ofS   U:  d  M  UPM     sn$  N%s  snf 7fr  r  r  s          rJ   (asimilarity_search_with_relevance_scores4AzureSearch.asimilarity_search_with_relevance_scoresE  d      55eKqKFKK & 	
 $?Vt'>!V?	
 L @$   AAAAAAA)filtersc               Z    U R                  XUS9nU VVs/ sH  u  pgUPM	     snn$ s  snnf )$  
Returns the most similar indexed documents to the query text.

Args:
    query (str): The query text for which to find similar documents.
    k (int): The number of documents to return. Default is 4.

Returns:
    List[Document]: A list of documents that are most similar to the query text.
r]  r  r  rg   r{  r]  r  rs   docs_and_scoresr\  _s           rJ   r?   AzureSearch.vector_searchT  s3     77G7T"12//222s   'c               v   #    U R                  XUS9I Sh  vN nU VVs/ sH  u  pgUPM	     snn$  Ns  snnf 7f)r  r  Nr  r  s           rJ   r  AzureSearch.avector_searchd  sI      !% > > !? !
 
 #22//22
 3s   91	9399c                h    U R                  U5      nU R                  " USU4SU0UD6n[        U5      $ )^  Return docs most similar to query.

Args:
    query (str): Text to look up documents similar to.
    k (int, optional): Number of Documents to return. Defaults to 4.
    filters (str, optional): Filtering expression. Defaults to None.

Returns:
    List[Tuple[Document, float]]: List of Documents most similar
        to the query and score for each
 r  r   _simple_search_results_to_documentsrg   r{  r]  r  rs   r[  resultss          rJ   r  $AzureSearch.vector_search_with_scorev  s=    $ $$U+	%%iQRR6R$W--rL   c                   #    U R                  U5      I Sh  vN nU R                  " USU4SU0UD6I Sh  vN n[        U5      I Sh  vN $  N6 N N7f)r  Nr  r  r  _asimple_search_aresults_to_documentsr  s          rJ   r  %AzureSearch.avector_search_with_score  se     $ ,,U33	,,r1
&-
17
 
 ,G444 4
 5s1   AAAAA	A
AAAc                   U R                  U5      nU R                  " USU4SU0UD6n[        U[        R                  " U5      XBS9$ )  Perform a search and return results that are reordered by MMR.

Args:
    query (str): Text to look up documents similar to.
    k (int, optional): How many results to give. Defaults to 4.
    fetch_k (int, optional): Total results to select k from.
        Defaults to 20.
    lambda_mult: Number between 0 and 1 that determines the degree
                of diversity among the results with 0 corresponding
                to maximum diversity and 1 to minimum diversity.
                Defaults to 0.5
    filters (str, optional): Filtering expression. Defaults to None.

Returns:
    List[Tuple[Document, float]]: List of Documents most similar
        to the query and score for each
r  r  query_embeddinglambda_multr]  r   r  0_reorder_results_with_maximal_marginal_relevancerL  rM  	rg   r{  r]  fetch_kr  r  rs   r[  r  s	            rJ   (max_marginal_relevance_search_with_score4AzureSearch.max_marginal_relevance_search_with_score  sP    6 $$U+	%%iWXgXQWX?RXXi%8k
 	
rL   c                  #    U R                  U5      I Sh  vN nU R                  " USU4SU0UD6I Sh  vN n[        U[        R                  " U5      UUS9I Sh  vN $  NK N. N7f)r  Nr  r  r  r  r  1_areorder_results_with_maximal_marginal_relevancerL  rM  r  s	            rJ   )amax_marginal_relevance_search_with_score5AzureSearch.amax_marginal_relevance_search_with_score  s     6 ,,U33	,,r7
,3
7=
 
 GHHY/#	
 
 	
 4

s1   A)A#A)A%'A)A'A)%A)'A)c                d    U R                   " U4SU0UD6nU VVs/ sH  u  pVUPM	     snn$ s  snnf )r  r]  r  rg   r{  r]  rs   r  r\  r  s          rJ   rx  AzureSearch.hybrid_search  s8     77MMfM"12//222s   ,c                   #    U R                   " U4SU0UD6I Sh  vN nU VVs/ sH  u  pVUPM	     snn$  Ns  snnf 7f)r  r]  Nr  r  s          rJ   r  AzureSearch.ahybrid_search  sD      !% > >u T TV TT"12//22 U2s   >6	>8>>c                f    U R                  U5      nU R                  " XQU4SU0UD6n[        U5      $ )Return docs most similar to query with a hybrid query.

Args:
    query: Text to look up documents similar to.
    k: Number of Documents to return. Defaults to 4.

Returns:
    List of Documents most similar to the query and score for each
r  r  r  s          rJ   r  $AzureSearch.hybrid_search_with_score  s;    " $$U+	%%iU7UfU$W--rL   c                   #    U R                  U5      I Sh  vN nU R                  " XQU4SU0UD6I Sh  vN n[        U5      I Sh  vN $  N5 N N7f)r  Nr  r  r  s          rJ   r  %AzureSearch.ahybrid_search_with_score#  sc     " ,,U33	,,a
)0
4:
 
 ,G444 4
 5s1   AAAAAA	AAAc               x    U R                   " U4SU0UD6nUc  U$ U Vs/ sH  ofS   U:  d  M  UPM     sn$ s  snf r  r  r  s          rJ   #hybrid_search_with_relevance_scores/AzureSearch.hybrid_search_with_relevance_scores;  r  r  c                  #    U R                   " U4SU0UD6I S h  vN nUc  U$ U Vs/ sH  ofS   U:  d  M  UPM     sn$  N%s  snf 7fr  r  r  s          rJ   $ahybrid_search_with_relevance_scores0AzureSearch.ahybrid_search_with_relevance_scoresJ  r  r  c                   U R                  U5      nU R                  " XqU4SU0UD6n[        U[        R                  " U5      XBS9$ )  Return docs most similar to query with a hybrid query
    and reorder results by MMR.

Args:
    query (str): Text to look up documents similar to.
    k (int, optional): Number of Documents to return. Defaults to 4.
    fetch_k (int, optional): Total results to select k from.
        Defaults to 20.
    lambda_mult: Number between 0 and 1 that determines the degree
                of diversity among the results with 0 corresponding
                to maximum diversity and 1 to minimum diversity.
                Defaults to 0.5
    filters (str, optional): Filtering expression. Defaults to None.

Returns:
    List of Documents most similar to the query and score for each
r  r  r  r  s	            rJ   /hybrid_max_marginal_relevance_search_with_score;AzureSearch.hybrid_max_marginal_relevance_search_with_scoreY  sY    8 $$U+	%%g
/6
:@
 @RXXi%8k
 	
rL   c                  #    U R                  U5      I Sh  vN nU R                  " XqU4SU0UD6I Sh  vN n[        U[        R                  " U5      UUS9I Sh  vN $  NJ N. N7f)r  Nr  r  r  r  s	            rJ   0ahybrid_max_marginal_relevance_search_with_score<AzureSearch.ahybrid_max_marginal_relevance_search_with_score~  s}     8 ,,U33	,,g
/6
:@
 
 GHHY/#	
 
 	
 4

s1   A(A"A(A$'A(A&A($A(&A(c          
     f    SSK Jn  U R                  R                  " SUU" UU[        S9/UUS.UD6$ )a  Perform vector or hybrid search in the Azure search index.

Args:
    embedding: A vector embedding to search in the vector space.
    text_query: A full-text search query expression;
        Use "*" or omit this parameter to perform only vector search.
    k: Number of documents to return.
    filters: Filtering expression.
Returns:
    Search items
r   VectorizedQueryvectork_nearest_neighborsr>   search_textvector_queriesfiltertopr8   )azure.search.documents.modelsr  r   searchr   rg   r[  
text_queryr]  r  rs   r  s          rJ   r  AzureSearch._simple_search  sO    ( 	B{{!! 
"$()0 
 
 	
rL   c          
        #    SSK Jn  U R                  R                  " SUU" UU[        S9/UUS.UD6I Sh  vN $  N7f)r  r   r  r  r  Nr8   )r  r  r   r  r   r  s          rJ   r  AzureSearch._asimple_search  s^     ( 	B&&-- 
"$()0 
 
 
 	
 
s   6?=?c                f    U R                   " U4SU0UD6nU VVs/ sH  u  n  oePM
     snn$ s  snnf )G  
Returns the most similar indexed documents to the query text.

Args:
    query (str): The query text for which to find similar documents.
    k (int): The number of documents to return. Default is 4.
    filters: Filtering expression.

Returns:
    List[Document]: A list of documents that are most similar to the query text.
r]  ,semantic_hybrid_search_with_score_and_rerankr  s          rJ   ry  "AzureSearch.semantic_hybrid_search  sG     KK

 
 &55_	Q_555s   -c                   #    U R                   " U4SU0UD6I Sh  vN nU VVs/ sH  u  n  oePM
     snn$  Ns  snnf 7f)r  r]  N-asemantic_hybrid_search_with_score_and_rerankr  s          rJ   r  #AzureSearch.asemantic_hybrid_search  sV      !% R R!
!
 !
 
 &55_	Q_55
 6s   ?7	?9??c                   U R                   " U4SU0UD6nUS:X  a$  U VVV	s/ sH  u  pxn	Ub  X:  d  M  Xx4PM     sn	nn$ US:X  a$  U VV	V
s/ sH  u  pyn
Ub  X:  d  M  Xz4PM     sn
n	n$ gs  sn	nnf s  sn
n	nf )  
Returns the most similar indexed documents to the query text.

Args:
    query (str): The query text for which to find similar documents.
    k (int): The number of documents to return. Default is 4.
    score_type: Must either be "score" or "reranker_score".
        Defaulted to "score".
    filters: Filtering expression.

Returns:
    List[Tuple[Document, float]]: A list of documents and their
        corresponding scores.
r]  scoreNreranker_scorer  rg   r{  r]  
score_typer  rs   r  r\  r  r  r  s              rJ   r  -AzureSearch.semantic_hybrid_search_with_score  s    . KK

 
   &5%4MC"*e.F %4 
 ++ />.=*CN"*n.O &%.=  ,s   A+A+A2A2c                 #    U R                   " U4SU0UD6I Sh  vN nUS:X  a$  U VVV	s/ sH  u  pxn	Ub  X:  d  M  Xx4PM     sn	nn$ US:X  a$  U VV	V
s/ sH  u  pyn
Ub  X:  d  M  Xz4PM     sn
n	n$ g NYs  sn	nnf s  sn
n	nf 7f)r  r]  Nr  r  r  r  s              rJ   r  .AzureSearch.asemantic_hybrid_search_with_score;  s     . !% R R!
!
 !
 
   &5%4MC"*e.F %4 
 ++ />.=*CN"*n.O &%.=  ,
s7   BA5BA7A7BA>(A>/B7Bc                  SSK Jn  U R                  R                  " SUU" U R	                  U5      U[
        S9/USU R                  SSUS.UD6nUR                  5       =(       d    / n0 nU H(  n	U	R                  U	R                  S.XR                  '   M*     U V
VVs/ sGH:  n
[        U
R                  [        5      0 [        U
;   a  [        U
R                  [        5      0O0 E[        U
;   a  [         R"                  " U
[           5      O/U
R%                  5        VVs0 sH  u  p+U[
        :w  d  M  X+_M     snnEU
R'                  S5      (       aA  U
R'                  S0 /5      S   R                  U
R'                  S0 /5      S   R                  S.O0 UR'                  U
R'                  [        S	5      S	5      S
.ES9[)        U
S   5      [)        U
S   5      4PGM=     nnn
nU$ s  snnf s  snnn
f )  Return docs most similar to query with a hybrid query.

Args:
    query: Text to look up documents similar to.
    k: Number of Documents to return. Defaults to 4.
    filters: Filtering expression.

Returns:
    List of Documents most similar to the query and score for each
r   r  r  semantic
extractiver  r  r  
query_typer=   query_captionquery_answerr  r  
highlights@search.captionsr  captionsanswerspage_contentr5   @search.score@search.reranker_scorer8   )r  r  r   r  r   r   r=   get_answersr  r  r-   r   r  r   r   r   rP  loadsr   r   float)rg   r{  r]  r  rs   r  r  semantic_answerssemantic_answers_dictsemantic_answerr  r^  r|  s                rJ   r  8AzureSearch.semantic_hybrid_search_with_score_and_rerankb  s(    	B++$$ 
++E2()0 !(,(H(H&%
 
$ #..06B&(/O',,-88:!"5"56  0` "U+
T "Q !'N!;!  )F2 '

9(=>!#	!  /&8 !JJvo'>? -3LLN",:DA#$(=#= !%,:"!2 $*::.@#A#A -3JJ7IB4,P()-&&*d28**=ORTQU2V()3&&0j!" &('<'@'@ &

9b 9 "(!$J f_-.f567O(R "U 	 +
X ?"+
s    BG, G&3G&9B'G,&G,c               D  #    SSK Jn  U R                  U5      I Sh  vN nU R                  R                  " SUU" UU[
        S9/USU R                  SSUS.UD6I Sh  vN nUR                  5       I Sh  vN =(       d    / n0 n	U H(  n
U
R                  U
R                  S.XR                  '   M*     U VVVs/ s Sh  vN n[        UR                  [        5      0 [        U;   a  [        UR                  [        5      0O0 E[        U;   a  [         R"                  " U[           5      O/UR%                  5        VVs0 sH  u  p,U[
        :w  d  M  X,_M     snnEUR'                  S	5      (       aA  UR'                  S	0 /5      S   R                  UR'                  S	0 /5      S   R                  S.O0 U	R'                  UR'                  [        S
5      S
5      S.ES9[)        US   5      [)        US   5      4PGMB   GN GN GN GNGs  snnf 
 Os  snnnf nnnnU$ 7f)r  r   r  Nr  r  r  r  r  r  r  r  r  r  r  r8   )r  r  r  r   r  r   r=   r  r  r  r-   r   r  r   r   r   rP  r  r   r   r  )rg   r{  r]  r  rs   r  r  r  r   r!  r"  r  r^  r|  s                 rJ   r   9AzureSearch.asemantic_hybrid_search_with_score_and_rerank  sO     	B))%00))00 
!()0 !(,(H(H&%
 
 
$ #*"5"5"77>B&(/O',,-88:!"5"56  0` !(U+
 +
T Q !'N!;!  )F2 '

9(=>!#	!  /&8 !JJvo'>? -3LLN",:DA#$(=#= !%,:"!2 $*::.@#A#A -3JJ7IB4,P()-&&*d28**=ORTQU2V()3&&0j!" &('<'@'@ &

9b 9 "(!$J f_-.f567O(9 1
$ 8+
"+
 +
 +
X s   H G?AH H H 7H8AH ;H=H
HH
A<HHHB%H?H H H H
HH r  langchain-indexc	                J    U " UUUU4UUS.U	D6n
U
R                   " X40 U	D6  U
$ N)r>   r<   )r(  clsr&  r[  r'  r  r  r<   r;   r>   rs   azure_searchs              rJ   
from_textsAzureSearch.from_texts  sL     !	

 "7
 
 	u:6:rL   c	                f   #    U " UUUU4UUS.U	D6n
U
R                   " X40 U	D6I S h  vN   U
$  N7fr(  )r-  r)  s              rJ   afrom_textsAzureSearch.afrom_texts+  s[      !	

 "7
 
 %%eA&AAA 	Bs   &1/1)r  r  r;   r>   c          
        #    [        U5      u  pU	c  [        S5      e[        U	S   5      n
U " SUUUUUU
S.UD6nUR                  " X40 UD6I S h  vN   U$  N7fNz0Cannot create AzureSearch from empty embeddings.r  )r  r  r;   r   r>   r   r8   )_peekr   r   r,  r*  rX  r[  r'  r  r  r;   r>   rs   first_text_embeddingr   r+  s               rJ   afrom_embeddingsAzureSearch.afrom_embeddingsE  s      16o0F-'OPP#&';A'>#?  
"7-!(%=
 
 **?PPPP 	Qs   AAAAc          
         [        U5      u  pU	c  [        S5      e[        U	S   5      n
U " SUUUUUU
S.UD6nUR                  " X40 UD6  U$ r2  )r3  r   r   r#  r4  s               rJ   from_embeddingsAzureSearch.from_embeddingsc  sz     16o0F-'OPP#&';A'>#?  
"7-!(%=
 
 	##OI&IrL   c                    UR                  SU R                  5      nX!S'   UR                  SS5      =(       d    / nUR                  U R	                  5       5        [        SSU 0UDSU0D6$ )aO  Return AzureSearchVectorStoreRetriever initialized from this VectorStore.

Args:
    search_type (Optional[str]): Overrides the type of search that
        the Retriever should perform. Defaults to `self.search_type`.
        Can be "similarity", "hybrid", or "semantic_hybrid".
    search_kwargs (Optional[Dict]): Keyword arguments to pass to the
        search function. Can include things like:
            score_threshold: Minimum relevance threshold
                for similarity_score_threshold
            fetch_k: Amount of documents to pass to MMR algorithm (Default: 20)
            lambda_mult: Diversity of results returned by MMR;
                1 for minimum diversity and 0 for maximum. (Default: 0.5)
            filter: Filter by document metadata

Returns:
    AzureSearchVectorStoreRetriever: Retriever class for VectorStore.
r   tagsNvectorstorer8   )r   r   r  extend_get_retriever_tagsAzureSearchVectorStoreRetriever)rg   rs   r   r<  s       rJ   as_retrieverAzureSearch.as_retriever  se    & jj0@0@A +}zz&$'-2D,,./.U4U6UPTUUrL   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   r   r=   )rt  NNNNNNN)$r  rv   r  rx   r;   rv   r   zUnion[Callable, Embeddings]r   rv   r=   rx   r>   Optional[List[SearchField]]r?   Optional[VectorSearch]r@   COptional[Union[SemanticConfiguration, List[SemanticConfiguration]]]rA   Optional[List[ScoringProfile]]rB   rx   rE   Optional[CorsOptions]r   zOptional[int]rG   Optional[Dict[str, Any]]r<   rx   rH   Optional[TokenCredential]rI   Optional[AsyncTokenCredential]rs   r   r   )rz   zOptional[Embeddings])r  rv   rz   List[float]r7   )
r&  zIterable[str]r'  Optional[List[dict]]r  Optional[List[str]]rs   r   rz   	List[str])rX  !Iterable[Tuple[str, List[float]]]r'  rL  r  rM  rz   rN  )r  rM  rs   r   rz   ry   )r   )
r{  rv   r]  rd   r   rx   rs   r   rz   List[Document])r{  rv   r]  rd   rs   r   rz   List[Tuple[Document, float]])
r{  rv   r]  rd   r  Optional[float]rs   r   rz   rQ  )
r{  rv   r]  rd   r  rx   rs   r   rz   rP  )r   N)
r{  rv   r]  rd   r  rx   rs   r   rz   rQ  )r            ?)r{  rv   r]  rd   r  rd   r  r  r  rx   rs   r   rz   rQ  )r{  rv   r]  rd   rs   r   rz   rP  )r[  rK  r  rv   r]  rd   r  rx   rs   r   rz   zSearchItemPaged[dict])r[  rK  r  rv   r]  rd   r  rx   rs   r   rz   zAsyncSearchItemPaged[dict])r   r  )r{  rv   r]  rd   r  z"Literal['score', 'reranker_score']r  rR  rs   r   rz   rQ  )
r{  rv   r]  rd   r  rx   rs   r   rz   z#List[Tuple[Document, float, float]])Nr  r  Nr&  N)r*  Type[AzureSearch]r&  rN  r[  r   r'  rL  r  rv   r  rv   r<   rx   r;   rv   r>   rC  rs   r   rz   r   )r*  rU  rX  rO  r[  r   r'  rL  r  rv   r  rv   r;   rv   r>   rC  rs   r   rz   r   )rs   r   rz   r@  )3r{   r|   r}   r~   __doc__ri   r  propertyr  r  r(  r-  r#  r,  rl  ro  r}  r  r  r  r  r  r?   r  r  r  r  r  rx  r  r  r  r  r  r  r  r  r  ry  r  r  r  r  r   classmethodr,  r/  r6  r9  rA  r   r8   rL   rJ   r   r   r  s   0 $59.204 ;?15.2B*" 37EI/36:AE+B*"B* (B* 	B*
 8B* B* &3B* ,B* .B*"
B* 9B* "/B* ,B*" #0#B*$ +C%B*&  -'B*( 4)B** !?+B*, -B*H!2 
 
A +/Q
 %)QQ (Q
 "Q Q 
QB +/X
 %)XX (X
 "X X 
XB +/;/
 %);/:;/ (;/
 ";/ 
;/@ +/7/
 %)7/:7/ (7/
 "7/ 
7/r & 
 &* 
 #  
( '(KK #K36K	%K$ 
 &* 
 #  
( '(KK #K36K	%K" 

 ,0

 

 )
 
 
&
$ 

 ,0

 

 )
 
 
&
  $%3BF33 32?3RU3	3" $%3BF33 32?3RU3	3* !%	.. . 	.
 . 
&.4 !%	55 5 	5
 5 
&58   
 "& 
 
  
 	 

  
  
  
 
& 
J  %
 "&%
%
 %
 	%

 %
 %
 %
 
&%
N3 $%33 3033	3& !%	.. . 	.
 . 
&.2 !%	55 5 	5
 5 
&56 

 ,0

 

 )
 
 
&
$ 

 ,0

 

 )
 
 
&
$  #
 "&#
#
 #
 	#

 #
 #
 #
 
&#
P  &
 "&&
&
 &
 	&

 &
 &
 &
 
&&
\ "&"
"
 "
 	"
 "
 "
 
"
T "&"
"
 "
 	"
 "
 "
 
$"
J $%66 6036	6( $%66 6036	6, 9@	% ,0%% % 7	% )% % 
&%T 9@	% ,0%% % 7	% )% % 
&%P $%UBFUU U2?URUU	,Up $%VBFVV V2?VRUV	,Vp 
 +/%' "/3+.2  (	
  #   -  ,  
 2 
 +/%' "/3+.2  (	
  #   -  ,  
 2 
 +/	 &( "+.2:  (	  #   ,  
 : 
 +/	 &( "+.2:  (	  #   ,  
 <VrL   r   c                      \ rS rSr% SrS\S'    SrS\S'    SrS	\S
'    0 rS\S'    Sr	S\S'   \
" SS9r\" SS9\SS j5       5       r        SS jr        SS jrSrg)r@  i  z-Retriever that uses `Azure Cognitive Search`.r   r=  rt  rv   r   r   rd   r]  dictsearch_kwargs)rs  similarity_score_thresholdrt  hybrid_score_thresholdru  semantic_hybrid_score_thresholdzClassVar[Collection[str]]allowed_search_typesT)arbitrary_types_allowedbefore)modec                p    SU;   a/  US   nX R                   ;  a  [        SU SU R                    35      eU$ )zValidate search type.r   rv  z  not allowed. Valid values are: )r_  r   )r*  valuesr   s      rJ   validate_search_type4AzureSearchVectorStoreRetriever.validate_search_type  sQ     F" /K":":: %k]2R//02  rL   c                   0 U R                   EUEnU R                  S:X  a+  U R                  R                  " U4SU R                  0UD6nU$ U R                  S:X  a>  U R                  R
                  " U4SU R                  0UD6 VVs/ sH  u  pgUPM	     nnnU$ U R                  S:X  a+  U R                  R                  " U4SU R                  0UD6nU$ U R                  S:X  a>  U R                  R                  " U4SU R                  0UD6 VVs/ sH  u  pgUPM	     nnnU$ U R                  S:X  a+  U R                  R                  " U4SU R                  0UD6nU$ U R                  S:X  a>  U R                  R                  " U4SU R                  0UD6 VVs/ sH  u  pgUPM	     nnnU$ [        SU R                   S	35      es  snnf s  snnf s  snnf 
Nrs  r]  r\  rt  r]  ru  r^  rv  rw  )r[  r   r=  r?   r]  r  rx  r  ry  r  r   )rg   r{  run_managerrs   paramsr|  r\  r  s           rJ   _get_relevant_documents7AzureSearchVectorStoreRetriever._get_relevant_documents  s-    2D&&1&1|+##11%L466LVLD8 7 !== #..VV!VV'-FC   4 ) )##11%L466LVLD& % !99 #..RR!VV'-FC   "  !22##::5UDFFUfUD  !BB #..PP!VV'-FC     t/?/?.@NOO3s   GGGc               <  #    0 U R                   EUEnU R                  S:X  a3  U R                  R                  " U4SU R                  0UD6I S h  vN nU$ U R                  S:X  aH  U R                  R
                  " U4SU R                  0UD6I S h  vN nU VVs/ sH  u  pxUPM	     nnnU$ U R                  S:X  a3  U R                  R                  " U4SU R                  0UD6I S h  vN nU$ U R                  S:X  aH  U R                  R                  " U4SU R                  0UD6I S h  vN nU VVs/ sH  u  pxUPM	     nnnU$ U R                  S:X  a3  U R                  R                  " U4SU R                  0UD6I S h  vN nU$ U R                  S:X  aF  U R                  R                  " U4SU R                  0UD6I S h  vN  VVs/ sH  u  pxUPM	     nnnU$ [        SU R                   S	35      e GN GNls  snnf  GN Ns  snnf  N NKs  snnf 7frh  )r[  r   r=  r  r]  r  r  r  r  r  r   )	rg   r{  ri  rs   rj  r|  r  r\  r  s	            rJ   _aget_relevant_documents8AzureSearchVectorStoreRetriever._aget_relevant_documents  se     2D&&1&1|+))88S$&&SFSSD< ; !==&&OO!VV'-  
 '66oFCCoD6. - )))88S$&&SFSSD* ) !99&&KK!VV'-  
 '66oFCCoD6  !22))AA#) D  !BB %)$4$4$W$W%!VV%'-%  FC     t/?/?.@NOO; T 7S 7s   AHG;AHG>	HH)AH*H+AH-H
.	H7HAHHAHH	HHH>HH
HHHHr8   N)rd  r
   rz   r   )r{  rv   ri  r   rs   r   rz   rP  )r{  rv   ri  r   rs   r   rz   rP  )r{   r|   r}   r~   rV  __annotations__r   r]  r[  r_  r   model_configr   rX  re  rk  rn  r   r8   rL   rJ   r@  r@    s    7?K- AsJ(M473   $L (#	  $	%% 4% 	%
 
%N(( 9	(
 ( 
(rL   r@  c                `    U  Vs/ sH  n[        U5      [        US   5      4PM     nnU$ s  snf Nr  _result_to_documentr  r  r  r|  s      rJ   r  r    sK     
 F  '&)*	
  	  Ks   "+c                x   #    U  Vs/ s S h  vN n[        U5      [        US   5      4PM$   N
 Os  snf nnU$ 7frs  rt  rv  s      rJ   r  r  +  sN      $ 
   '&)*	
 D  Ks$   :1/-
/1/1
:c                $  #    U  Vs/ s S h  vN n[        U5      [        US   5      U[           4PM,   N'
 Os  snf nn[        [        [        U6 5      u  pgn[        XX2S9n	/ n
U	 H#  nUS:X  a    U
$ U
R                  Xk   X{   45        M%     U
$ 7fNr  )r]  r  ru  r  r   mapr   r$  r   rS  r  r  r  r]  r  r|  r8  scoresvectorsnew_orderingretr   s               rJ   r  r  8  s      $  	  '&)*()	
 D  "%T3:!6Iw .AL
 )+C7 J 	

IL&),-	  Js'   B975
7$979ABc                   U  Vs/ sH$  n[        U5      [        US   5      U[           4PM&     nnU(       d  / $ [        [        [        U6 5      u  pgn[        XX2S9n	/ n
U	 H#  nUS:X  a    U
$ U
R                  Xk   X{   45        M%     U
$ s  snf ry  r{  r}  s               rJ   r  r  Y  s      F	  '&)*()	

  	  	!$T3:!6Iw .AL
 )+C7 J 	

IL&),-	  J3s   *B
c                   [         U ;   aD  [        U [            [        5      (       a
  U [            nOS[        R                  " U [            5      nO5U R                  5        VVs0 sH  u  p#U[        [        4;  d  M  X#_M     nnn[        U ;   a  [        U R                  [        5      0nO0 n[        U [           0 UEUES9$ s  snnf )Nr  )r   r   rZ  rP  r  r   r   r   r   r  r   )r  fields_metadatar-   r   	fields_ids        rJ   ru  ru  |  s    & f_-t44$_5O"jj)@AO %lln
,
0.AA CJ, 	 
 F

9 56		N+


 
s   "C;Cc                     [        U 5      n[        U5      n[        R                  " U/U5      n X4$ ! [         a    X4s $ f = fr7   )iternext	itertoolschainStopIteration)iterabler/   iteratorr   s       rJ   r3  r3    sK    !>X??E7H5 !  !s   03 AA)NNNNNNNNN"langchain-comm-python-azure-searchNFNNN)$r:   rv   r;   rv   r-   rx   r<   rx   r=   rx   r>   rC  r?   rD  r@   rE  rA   rF  rB   rx   rC   rC  rD   rx   rE   rG  rF   zLiteral[False]rG   rH  rH   rI  rI   rJ  rz   zUnion[SearchClient])NNNNNNNNNr  NTNNN)$r:   rv   r;   rv   r-   rx   r<   rx   r=   rx   r>   rC  r?   rD  r@   rE  rA   rF  rB   rx   rC   rC  rD   rx   rE   rG  rF   zLiteral[True]rG   rH  rH   rI  rI   rJ  rz   zUnion[AsyncSearchClient])$r:   rv   r;   rv   r-   rx   r<   rx   r=   rx   r>   rC  r?   rD  r@   rE  rA   rF  rB   rx   rC   rC  rD   rx   rE   rG  rF   ry   rG   rH  rH   rI  rI   rJ  rz   z&Union[SearchClient, AsyncSearchClient])r  SearchItemPaged[Dict]rz   rQ  )r  AsyncSearchItemPaged[Dict]rz   rQ  )rT  r   )
r  r  r  
np.ndarrayr  r  r]  rd   rz   rQ  )
r  r  r  r  r  r  r]  rd   rz   rQ  )r  r
   rz   r   r7   )r  r   r/   zOptional[Any]rz   zTuple[Iterable, Any])R
__future__r   r  rH  r   r  rP  loggingre   rF  typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   numpyrL  langchain_core.callbacksr   r   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.exceptionsr   langchain_core.retrieversr   langchain_core.utilsr   langchain_core.vectorstoresr   pydanticr   r   &langchain_community.vectorstores.utilsr   	getLoggerr!  r   r   r   r!   r   r"   r#   r   r$   r   r   r&   r'   r(   r)   r*   r   r   r   r   rT  rK   r   r@  r  r  r  r  ru  r3  r8   rL   rJ   <module>r     s   "             $  . 0 8 3 - 3 0 M				6AD  )@$	 $(
 %+/ 
  *BJ   
 +/15*.,0 	7;-126 D*."AE26=A' 
 )	
 "/ ( * 5 + 0  (  !" '?#$ 0%& ;'( ) 
. 
 +/15*.,0 	7;-126 D*. AE26=A'### 
# )	#
 "/# (# *## 5# +# 0# # (#  !#" '?##$ 0%#& ;'#( )# 
#4 +/15*.,0 	7;-126 D*.AE26=A'i
i
i
 
i
 )	i

 "/i
 (i
 *i
i
 5i
 +i
 0i
 i
 (i
  !i
" '?#i
$ 0%i
& ;'i
( ,)i
XhV+ hVV)~m ~B
"
!

'
!
  	'  	
 "H 	 "     	 
 " F6!rL   