
    i$                        S SK JrJrJr  S SK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Jr  S SK r \ RB                  " \"5      r#\" \SS9 " S S\5      5       r$g)    )AnyListOptional)
deprecatedN)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_scoreDEPRECATION_REASONz0.9.1)reasonversionc            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.   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)r;   r<   )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/   r0   r1   r2   r3   r4   r5   r6   r7   	__class__s                              k/home/james-whalen/.local/lib/python3.13/site-packages/llama_index/indices/managed/llama_cloud/retriever.pyrT   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_objr]   dictappendr   r^   )rV   r[   nodesres	text_nodes        rX    _result_nodes_to_node_with_score4LlamaCloudRetriever._result_nodes_to_node_with_score   sI     C **388==?;ILLIYYGH   rZ   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_filtersr2   r1   r4   r5   r6   )r   rR   model_json_schemarB   	pipelines
run_search	query_strrE   r    rF   rG   rH   rI   rJ   rK   rM   rL   rP   rQ   re   retrieval_nodesextendr   image_nodesrD   r   page_figure_nodesrV   rg   r6   resultsr[   s        rX   	_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\\__ rZ   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.Nri   )r   rR   rl   rC   rm   rn   ro   rE   r    rF   rG   rH   rI   rJ   rK   rM   rL   rP   rQ   re   rp   rq   r   rr   rD   r   rs   rt   s        rX   
_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)rC   rJ   rA   rB   rF   rH   rM   rK   r@   rI   rL   rQ   rP   rR   rG   r   rE   rD   r"   )__name__
__module____qualname____firstlineno__r   r   strinthttpxClientAsyncClientr>   floatr   r
   r   rT   r   r   r   re   r   rv   ry   __static_attributes____classcell__)rW   s   @rX   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 % %rZ   r   )%typingr   r   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   1llama_index.indices.managed.llama_cloud.api_utilsr   r   r   r   r   r   logging	getLoggerr{   rN   r    rZ   rX   <module>r      sz    & & !  8 > 6 ; H H H @   
		8	$ }- }	}rZ   