
    i#                         S SK JrJrJr  S SK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	KJrJrJr  S S
KJr  SSKJrJrJrJrJr  S SKr\R>                  " \ 5      r! " S S\
5      r"g)    )AnyListOptionalN)TextNodeWithScore)OMIT)BaseRetriever)	BaseModel)DEFAULT_PROJECT_NAME)get_aclient
get_client)NodeWithScoreQueryBundleTextNode)MetadataFilters   )resolve_project_and_pipeline(page_screenshot_nodes_to_node_with_score$page_figure_nodes_to_node_with_score)apage_screenshot_nodes_to_node_with_score%apage_figure_nodes_to_node_with_scorec            7         ^  \ rS rSrSSSS\SSSSSSSSSSSSSSSSSSSS4S\\   S\\   S\\   S\\   S\\   S	\\   S
\\   S\\   S\\   S\\   S\S\\R                     S\\R                     S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\\   S\SS46U 4S jjjrS \\   S\\   4S! jrS"\S\\   4S# jrS"\S\\   4S$ jrS%rU =r$ )&LlamaCloudRetriever   N<   nameindex_ididpipeline_idproject_name
project_idorganization_idapi_keybase_urlapp_urltimeouthttpx_clientasync_httpx_clientdense_similarity_top_ksparse_similarity_top_kenable_rerankingrerank_top_nalphafiltersretrieval_modefiles_top_kretrieve_image_nodesretrieve_page_screenshot_nodesretrieve_page_figure_nodessearch_filters_inference_schemakwargsreturnc                   > [        [        U5      [        U5      [        U5      [        U5      /5      S:w  a  [        S5      eXl        Xl        [        XXU5      U l        [        XXU5      U l        U=(       d    U=(       d    Un[        U R                  XXVU5      u  U l
        U l        U R                  R                  U l        U R                  R                  U l        Ub  UO[        U l        Ub  UO[        U l        Ub  UO[        U l        Ub  UO[        U l        Ub  UO[        U l        Ub  UO[        U l        Ub  UO[        U l        Ub  UO[        U l        Ub  [.        R1                  S5        U(       a  USL d  USL a  [        S5      eSnSnUb  UO[        U l        Ub  UO[        U l        UU l        [8        TU ]u  UR=                  S5      UR=                  S	S5      S
9  g)z"Initialize the Platform Retriever.r   z`Exactly one of `name`, `id`, `pipeline_id` or `index_id` must be provided to identify the index.NzThe `retrieve_image_nodes` parameter is deprecated. Use `retrieve_page_screenshot_nodes` and `retrieve_page_figure_nodes` instead.FzIf `retrieve_image_nodes` is set to True, both `retrieve_page_screenshot_nodes` and `retrieve_page_figure_nodes` must also be set to True or omitted.Tcallback_managerverbose)r7   r8   )sumbool
ValueError_httpx_client_async_httpx_clientr   _clientr   _aclientr   projectpipeliner   r   r   _dense_similarity_top_k_sparse_similarity_top_k_enable_reranking_rerank_top_n_alpha_filters_retrieval_mode_files_top_kloggerwarning_retrieve_page_screenshot_nodes_retrieve_page_figure_nodes _search_filters_inference_schemasuper__init__get)selfr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   	__class__s                              ^/home/james-whalen/.local/lib/python3.13/site-packages/llama_cloud_services/index/retriever.pyrP   LlamaCloudRetriever.__init__   s   D R$x.${*;T$ZHIQNr 
 *#5 !'W|T#w1C
 3H3&BLL$\'
#dm MM&&	 LL-- '=&H"d 	$ (?'J#PT 	% !1 <$ 	 .:-E\4$0ed#*#6D1?1K~QU+6+BK+NNa  .%7-6 B  .2*)-& .9 + 	, *5 ' 	(
 1P-#ZZ(:;JJy%0 	 	
    result_nodesc                     / nU HS  n[         R                  " UR                  R                  5       5      nUR	                  [        XCR                  S95        MU     U$ )N)nodescore)r   	parse_objrY   dictappendr   rZ   )rR   rW   nodesres	text_nodes        rT    _result_nodes_to_node_with_score4LlamaCloudRetriever._result_nodes_to_node_with_score   sI     C **388==?;ILLIYYGH   rV   query_bundlec                 L   [         nU R                  b  U R                  R                  5       nU R                  R                  R                  UR                  U R                  R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  U R$                  US9nU R'                  UR(                  5      nU R"                  (       aD  UR+                  [-        U R                  UR.                  U R0                  R                  5      5        U R$                  (       aD  UR+                  [3        U R                  UR4                  U R0                  R                  5      5        U$ )zRetrieve from the platform.queryr   r(   r)   r*   r+   r,   search_filtersr/   r.   r1   r2   r3   )r   rN   model_json_schemar>   	pipelines
run_search	query_strrA   r   rB   rC   rD   rE   rF   rG   rI   rH   rL   rM   ra   retrieval_nodesextendr   image_nodesr@   r   page_figure_nodesrR   rc   r3   resultsrW   s        rT   	_retrieveLlamaCloudRetriever._retrieve   sM   *.'00<55GGI , ,,((33((((#'#?#?$($A$A!33++++==))//+/+O+O'+'G'G,K 4 
  <<W=T=TU//8LL'"5"5t||
 ++4LL'";";T\\__ rV   c                   #    [         nU R                  b  U R                  R                  5       nU R                  R                  R                  UR                  U R                  R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  U R$                  US9I Sh  vN nU R'                  UR(                  5      nU R"                  (       aL  UR+                  [-        U R                  UR.                  U R0                  R                  5      I Sh  vN 5        U R$                  (       aL  UR+                  [3        U R                  UR4                  U R0                  R                  5      I Sh  vN 5        U$  N Ni N7f)z*Asynchronously retrieve from the platform.Nre   )r   rN   rh   r?   ri   rj   rk   rA   r   rB   rC   rD   rE   rF   rG   rI   rH   rL   rM   ra   rl   rm   r   rn   r@   r   ro   rp   s        rT   
_aretrieveLlamaCloudRetriever._aretrieve   sn    *.'00<55GGI , //::((((#'#?#?$($A$A!33++++==))//+/+O+O'+'G'G,K ; 
 
  <<W=T=TU//?MM7#6#6 
 ++;MM7#<#<dlloo  =
&s8   C"G$G %A3GGAG5G6GGG)r?   rF   r=   r>   rB   rD   rI   rG   r<   rE   rH   rM   rL   rN   rC   r   rA   r@   r   )__name__
__module____qualname____firstlineno__r
   r   strinthttpxClientAsyncClientr:   floatr   r	   r   rP   r   r   r   ra   r   rr   ru   __static_attributes____classcell__)rS   s   @rT   r   r      sL    #"& %)&:$()-!%"&!%/3:>0415+/&*!%-1(,%)/39=59?C=d
 smd
 3-	d

 SMd
 c]d
 smd
 SMd
 "#d
 #d
 3-d
 #d
 d
  u||,!d
" %U%6%67#d
& !)'d
( "*#)d
* #4.+d
, sm-d
. /d
0 /*1d
2 !3d
4 c]5d
6 'tn7d
8 )19d
: %-TN;d
< *2))<=d
> ?d
@ 
Ad
 d
L !23	m	%k %d=6I %N%[ %T-=P % %rV   r   )#typingr   r   r   r}   llama_cloudr   &llama_cloud.resources.pipelines.clientr   $llama_index.core.base.base_retrieverr    llama_index.core.bridge.pydanticr	   llama_index.core.constantsr
   $llama_index.core.ingestion.api_utilsr   r   llama_index.core.schemar   r   r   $llama_index.core.vector_stores.typesr   	api_utilsr   r   r   r   r   logging	getLoggerrw   rJ   r    rV   rT   <module>r      s\    & &  8 > 6 ; H H H @   
		8	$}- }rV   