
    +#h?                         d dl mZmZ d dlmZ 	 d dlmZ d dlmZ d dl	m
Z
  G d d      Zdd	ed
edededef
dZde
dedefdZy# e$ r	  ed      w xY w)    )AnyUnion)dotdict)AzureKeyCredential)SearchClient)SearchItemPagedzlYou need to install azure-search-documents libraryPlease use the command: pip install azure-search-documentsc            
       X    e Zd ZdZdededededef
dZdded	ed
eee   ee	   f   fdZ
y)AzureCognitiveSearchz1Wrapper for the Azure Cognitive Search Retrieval.search_service_namesearch_api_keysearch_index_name
field_textfield_scorec                 
   || _         || _        || _        d| j                    d| _        || _        || _        t        | j                        | _        t        | j                  | j                  | j                        | _	        y )Nzhttps://z.search.windows.net)endpoint
index_name
credential)
r   r   r   r   r   r   r   r   r   client)selfr   r   r   r   r   s         ]/var/www/html/sandstorm/venv/lib/python3.12/site-packages/dsp/modules/azurecognitivesearch.py__init__zAzureCognitiveSearch.__init__   sw     $7 ,!2 !9!9 ::MN$&,T-@-@A"DMM#'#9#9#'??4    querykreturnc                     t        d       t        | j                  | j                  | j                  ||      }|D cg c]  }i |d|d   i }}|D cg c]  }t        |       c}S c c}w c c}w )Nz# Deprecated: This module is scheduled for removal in future releases.
                Please use the AzureAISearchRM class from dspy.retrieve.azureaisearch_rm instead.
                For more information, refer to the updated documentation.	long_texttext)printazure_search_requestr   r   r   r   )r   r   r   topkdpsgs         r   __call__zAzureCognitiveSearch.__call__+   sy     M 	N &:$//4K[K[]a]h]hjoqr%s7;<!-1-k1V9-<<(,--- =-s   A*A/N)
   )__name__
__module____qualname____doc__strr   intr   listr   r$    r   r   r
   r
      sf    ;4 4 4 	4
 4 4*.c .c .5cDM9Q3R .r   r
   key_content	key_scorer   r   topc                 F    |j                  ||      }t        || |       }|S )z0
    Search in Azure Cognitive Search Index
    )search_textr0   )searchprocess_azure_result)r.   r/   r   r   r0   resultss         r   r    r    5   s)     mm#m6G"7KEGNr   r5   content_keycontent_scorec                     g }| D ]H  }i }|j                         D ]   \  }}||k(  r||d<   ||k(  r||d<   |||<   " |j                  |       J |S )z}
    process received result from Azure Cognitive Search as dictionary array and map content and score to correct format
    r   score)itemsappend)r5   r6   r7   resresulttmpkeyvalues           r   r4   r4   >   su     C 	 ,,. 	!JCk!#F%$G C	! 	

3	 Jr   N)   )typingr   r   	dsp.utilsr   azure.core.credentialsr   azure.search.documentsr   azure.search.documents._pagingr   ImportErrorr
   r*   r+   r    r4   r-   r   r   <module>rH      s     93> .  .Dc c L Y\ cf  c RU k  
	E s   A A