
    Ji                     z   d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlm Z  ddl!m"Z" dd	l#m$Z$ dd
l%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 ddl:Z: e:jv                  e<      Z= G d de)      Z>y)zr
Managed index.

A managed Index - where the index is accessible via some API that
interfaces a managed service.

    N)Any	AwaitableCallableListOptionalSequenceTypeDict)override)
quote_plus)ManagedIngestionStatusResponsePipelineCreatePipelineCreateEmbeddingConfigPipelineCreateTransformConfig%PipelineFileCreateCustomMetadataValuePipelineTypeProjectCreateManagedIngestionStatusCloudDocumentCreateCloudDocumentPipelineFileCreateLlamaParseParameters)BaseQueryEngine)BaseRetriever)CallbackManager)DEFAULT_APP_URLDEFAULT_PROJECT_NAME)BaseManagedIndex)ApiError)get_aclient
get_client)BaseNodeDocumentTransformComponent)Settings)
RefDocInfo   )default_transform_configresolve_project_and_pipelinec            '       @   e Zd ZdZdddddedddddddddddfdee   dee   dee   dee   d	ee   d
edee   dee   dee   dee   dedeej                     deej                     dedee   deee      deee      deddf&dZedefd       Zdee   deegef   dededededdfd Zdee   deegee   f   dededededdfd!Z	 	 	 	 	 	 dTd"eee      d#eee      ded$edededee   fd%Z	 	 	 	 	 	 dTd"eee      d#eee      ded$edededee   fd&Zeeddddddddddfd'ed    ded
edee   d	ee   dee   dee   dee   deded(ee   d)ee    d*ee!   dedd fd+       Z"eedddddddddf
d'ed    ded
edee   dee   dee   dee   deded(ee   d)ee    d*ee!   dedd fd,       Z#eedddddddddddfd'ed    d-ee$   ded
edee   d	ee   dee   dee   dee   dededed(ee   d)ee    deee      dedd f"d.       Z%dede&fd/Z'e(dede)fd0       Z*edUd1ede+ee,f   fd2       Z-	 dVd3e$ded4eddfd5Z.	 dVd3e$ded4eddfd6Z/	 dVd3e$ded7eddfd8Z0	 dVd3e$ded7eddfd9Z1d-ee$   d7edee   fd:Z2d-ee$   d7edee   fd;Z3	 	 	 dWd<ed=eded>ed?eddfd@Z4	 	 	 dWd<ed=eded>ed?eddfdAZ5	 	 	 	 dXdBedCee6eee7   f      dedDededefdEZ8	 	 	 	 dXdBedCee6eee7   f      dedDededefdFZ9	 	 	 	 	 	 	 	 dYdGedHedCee6eee7   f      dIee   dJee+eef      dKedLededDededefdMZ:	 	 	 	 	 	 	 	 dYdGedHedCee6eee7   f      dIee   dJee+eef      dKedLededDededefdNZ;dee   d4eddfdOZ<e(dee   ddfdP       Z=dee   d4eddfdQZ>	 dVdRee   d=ed?eddfdSZ?y)ZLlamaCloudIndexa  
    A managed index that stores documents in LlamaCloud.

    There are two main ways to use this index:

    1. Connect to an existing LlamaCloud index:
        ```python
        # Connect using index ID (same as pipeline ID)
        index = LlamaCloudIndex(id="<index_id>")

        # Or connect using index name
        index = LlamaCloudIndex(
            name="my_index",
            project_name="my_project",
            organization_id="my_org_id"
        )
        ```

    2. Create a new index with documents:
        ```python
        documents = [Document(...), Document(...)]
        index = LlamaCloudIndex.from_documents(
            documents,
            name="my_new_index",
            project_name="my_project",
            organization_id="my_org_id"
        )
        ```

    The index supports standard operations like retrieval and querying
    through the as_query_engine() and as_retriever() methods.
    N<   Fnamepipeline_idindex_idid
project_idproject_nameorganization_idapi_keybase_urlapp_urltimeouthttpx_clientasync_httpx_clientshow_progresscallback_managernodestransformationskwargsreturnc                 ~   t        t        |      t        |      t        |      t        |      g      dk7  rt        d      |t        d      |t        d      || _        || _        t        ||	|
||      | _        t        ||	|
||      | _        || _	        |xs |xs |}t        | j                  |||||      \  | _        | _        | j                  j                  | _        | j                  j                  | _        || _        |	| _        |
| _        || _        || _        |xs t(        j*                  | _        y)zInitialize the Platform Index.r'   z`Exactly one of `name`, `id`, `pipeline_id` or `index_id` must be provided to identify the index.Nz8LlamaCloudIndex does not support nodes on initializationzSetting transformations is deprecated for LlamaCloudIndex, please use the `transform_config` and `embedding_config` parameters instead.)r4   r5   r6   r7   r8   )sumbool
ValueError_httpx_client_async_httpx_clientr!   _clientr    _aclientr3   r)   projectpipeliner-   r2   _api_key	_base_url_app_url_timeout_show_progressr%   r;   _callback_manager)selfr-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   s                      q/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/llama_cloud_services/index/base.py__init__zLlamaCloudIndex.__init__Y   sK   6 R$x.${*;T$ZHIQNr  WXX& Z 
 *#5 !%
 $+
  /3H3&BLL$\:'
#dm MM&&	 LL--!+!1!NX5N5N    c                 .    | j                   j                  S )z#Return the pipeline (aka index) ID.)rI   r0   )rP   s    rQ   r0   zLlamaCloudIndex.id   s     }}rS   resource_idsget_status_fnresource_nameverboseraise_on_errorsleep_intervalc                    |sy|r t        d| t        |      dkD  rdnd        t        |      }|rt               }|D ]  }		  ||	      }
|
j                  }|t        j
                  t        j                  fv r;|t        j                  k(  r@|rt        |j                          d|	        |rt        |j                          d|	       |j                  |	       |rt        |j                          d|	         ||z  }|rt        j                   |       |r|rt        d	       yy# t        j                  $ r%}|j                  j                  dv rn Y d}~"d}~ww xY w
u  
        Poll `get_status_fn` until every id in `resource_ids` is finished.

        Args:
            resource_ids: Iterable of resource ids to watch.
            get_status_fn: Callable that maps a resource id → ManagedIngestionStatus.
            resource_name: Text used in log / error messages: "file", "document", ….
            verbose: Print a progress bar.
            raise_on_error: Whether to raise on ManagedIngestionStatus.ERROR.
            sleep_interval: Seconds between polls (min 0.5 s to avoid rate-limits).

        NzLoading r'   s z ingestion failed for z ingestion finished for i  i  i  i  i  Done!)printlensetstatusr   NOT_STARTEDIN_PROGRESSERROR
capitalizerC   addhttpxHTTPStatusErrorresponsestatus_codetimesleeprP   rU   rV   rW   rX   rY   rZ   pendingfinishedridstatus_responserd   es                rQ   _wait_for_resourcesz#LlamaCloudIndex._wait_for_resources   s   * =/\1BQ1F#B)OP  -!$H &3C&8O,33F.::.::"  !!7!=!=="!#0#;#;#=">>TUXTY Z *",#0#;#;#=">>TUXTY Z#  LL%,779::RSVRWX-@ xG

>*K N 'N  ,, zz--1JJ s   6D.:BD..E&E!!E&c                   K   |sy|r t        d| t        |      dkD  rdnd        t        |      }|rt               }|D ]  }		  ||	       d{   }
|
j                  }|t        j
                  t        j                  fv rC|t        j                  k(  r@|rt        |j                          d|	        |rt        |j                          d|	       |j                  |	       |rt        |j                          d|	         ||z  }|rt        j                   |       d{    |r|rt        d	       yy7 # t        j                  $ r%}|j                  j                  dv rn Y d}~4d}~ww xY w7 Swr\   )ra   rb   rc   rd   r   re   rf   rg   rh   rC   ri   rj   rk   rl   rm   asyncioro   rp   s                rQ   _await_for_resourcesz$LlamaCloudIndex._await_for_resources   s    * =/\1BQ1F#B)OP  -!$H ,9#,>&>O,33F.::.::"  !!7!=!=="!#0#;#;#=">>TUXTY Z *",#0#;#;#=">>TUXTY Z#  LL%,779::RSVRWX-@ xGmmN333K N 'N G '?0 ,, zz--1JJ  4sa   AE?EE 2EE?BE!E?)E=*E?1E? EE:E5/E?5E::E?file_idsdoc_idsraise_on_partial_successc                 R    |r j                  | fdd|||       |r j                  | fdd|||       |r"t        d j                  j                          d}	 	  j                  j
                  j                   j                  j                        }|j                  }|t        j                  k(  s|rF|t        j                   k(  r3t#        d
 j                  j                   d|j%                                |t        j&                  t        j(                  fv r%|rt        dd       t        j                  |       n|rt        d       |S # t        j                  $ r9}	|	j                  j                  d	v rt        j                  |       Y d}	~	@ d}	~	ww xY w)  
        Block until the requested ingestion work is finished.

        - If `file_ids` is given → wait for those files.
        - If `doc_ids` is given → wait for those documents.
        - If neither is given → wait for the pipeline itself last so that retrieval works.
        - Always waits for the pipeline itself last so that retrieval works.

        Returns the final PipelineStatus response (or None if only waiting on
        files / documents).
        c                 z    j                   j                  j                  j                  j                  |       S N)r.   file_id)rF   pipeline_filesget_pipeline_file_statusrI   r0   fidrP   s    rQ   <lambda>z5LlamaCloudIndex.wait_for_completion.<locals>.<lambda>Q  s1    DLL77PP $ 0 0# Q  rS   filerW   rX   rY   rZ   c                     j                   j                  j                  j                  j                  t        t        |                   S Nr.   document_id)rF   	pipelinesget_pipeline_document_statusrI   r0   r   didrP   s    rQ   r   z5LlamaCloudIndex.wait_for_completion.<locals>.<lambda>^  s;    DLL22OO $ 0 0 *:c? ; P  rS   documentSyncing pipeline Nr.   r_   Pipeline ingestion failed for . Details: .r^   endr`   )rv   ra   rI   r0   rF   r   get_pipeline_statusrd   rj   rk   rl   rm   rn   ro   r   rg   PARTIAL_SUCCESSrC   jsonre   rf   
rP   rz   r{   rX   r|   rY   rZ   rt   rd   ru   s
   `         rQ   wait_for_completionz#LlamaCloudIndex.wait_for_completion9  s   * $$ %-- % 	 $$ )-- % 
 %dmm&6&6%789DH
"&,,"8"8"L"L $ 0 0 #M # )// /555(4DDD 4T]]5E5E4F G  / 4 4 679 
 &22&22  #2&

>*'N&&C  (( ::))-FFJJ~.s   "AE F&--F! F!!F&c                    K   |r" j                  | fdd|||       d{    |r" j                  | fdd|||       d{    |r"t        d j                  j                          d}	 	  j                  j
                  j                   j                  j                         d{   }|j                  }|t        j                  k(  s|rF|t        j                   k(  r3t#        d
 j                  j                   d|j%                                |t        j&                  t        j(                  fv r-|rt        dd       t        j                  |       d{    n|rt        d       |S 
7 Z7 97 # t        j                  $ rB}	|	j                  j                  d	v r$t        j                  |       d{  7   Y d}	~	b d}	~	ww xY w7 vw)r~   c                 z    j                   j                  j                  j                  j                  |       S r   )rG   r   r   rI   r0   r   s    rQ   r   z6LlamaCloudIndex.await_for_completion.<locals>.<lambda>  s1    DMM88QQ $ 0 0# R  rS   r   r   Nc                     j                   j                  j                  j                  j                  t        t        |                   S r   )rG   r   r   rI   r0   r   r   s    rQ   r   z6LlamaCloudIndex.await_for_completion.<locals>.<lambda>  s;    DMM33PP $ 0 0 *:c? ; Q  rS   r   r   r   r_   r   r   r   r^   r   r`   )ry   ra   rI   r0   rG   r   r   rd   rj   rk   rl   rm   rx   ro   r   rg   r   rC   r   re   rf   r   s
   `         rQ   await_for_completionz$LlamaCloudIndex.await_for_completion  s    * ++ %-- , 	 	 	 ++ )-- , 
 
 
 %dmm&6&6%789DH
(,(?(?(S(S $ 0 0 )T ) # )// /555(4DDD 4T]]5E5E4F G  / 4 4 679 
 &22&22  #2&mmN333'N&&C =	
&# (( ::))-FF!--777, 4s|    GE=#GF +G4=F 1F2F B$G&G'G GF G0GG	GGGGGclsembedding_configtransform_configllama_parse_parametersc           	      D   |xs$ t         j                  j                  dt              }t	        ||||      }|F|j
                  j                  |t        |            }|j                  }|	rt        d| d|        t        |t        j                  |
|xs
 t               |xs
 t                     }|j                  j!                  ||      }|j                  t#        d|       |	r%t        d	|j                   d|j$                           | |f|||||d
|S )&Create a new LlamaCloud managed index.LLAMA_CLOUD_APP_URLr-   r3   requestCreated project  with name r-   pipeline_typer   r   r   r1   r   Failed to create/get pipeline Created pipeline )r1   r4   r5   r6   r7   )osenvirongetr   r!   projectsupsert_projectr   r0   ra   r   r   MANAGEDr(   r   r   upsert_pipelinerC   r-   )r   r-   r2   r3   r1   r4   r5   r6   r7   rX   r   r   r   r>   clientrH   pipeline_createrI   s                     rQ   create_indexzLlamaCloudIndex.create_index  s?   & SRZZ^^,A?SGXw@oo44 /%<8 5 G !J(K~NO )&..--K1I1K#9#S=Q=S
 ##33!? 4 
 ;;=dVDEE%hkk]+hmm_MN
!
 
 	
rS   c           
        K   |xs$ t         j                  j                  dt              }t	        ||||      }|j
                  j                  |t        |             d{   }|j                  t        d|       |r%t        d|j                   d|j                          t        |t        j                  |	|
xs
 t               |xs
 t!                     }|j"                  j%                  |j                  |	       d{   }|j                  t        d
|       |r%t        d|j                   d|j                           | |f|j                  |j&                  ||||d|S 7 7 lw)r   r   r   r   NzFailed to create/get project r   r   r   r   r   r   )r2   r3   r4   r5   r6   r7   )r   r   r   r   r    r   r   r   r0   rC   ra   r-   r   r   r   r(   r   r   r   r3   )r   r-   r2   r3   r4   r5   r6   r7   rX   r   r   r   r>   aclientrH   r   rI   s                    rQ   acreate_indexzLlamaCloudIndex.acreate_index!  s    $ SRZZ^^,A?Sgx'B  ((77+]5U 8 
 
 ::<\NKLL$WZZLGLL>JK )&..--K1I1K#9#S=Q=S
 !**::zz? ; 
 
 ;;=dVDEE%hkk]+hmm_MN	
 #33	
 	
 		
3
"
s&   A!E8#E3$B%E8	E6
A*E86E8	documentsc                    | j                  |||||||	|
|||      }|xs$ t        j                  j                  dt              }t        ||||	      }|j                  j                  |j                  j                  |D cg c]D  }t        |j                  |j                  |j                  |j                  |j                        F c}      }|j                  j!                  |j                  j                         |D cg c]  }|j                   }}|j#                  ||
|       t%        d| d|j&                  j                   d	|j                  j                          |S c c}w c c}w )
z>Build a LlamaCloud managed index from a sequence of documents.)r-   r2   r3   r4   r5   r6   r7   rX   r   r   r1   r   textmetadataexcluded_embed_metadata_keysexcluded_llm_metadata_keysr0   r.   r   r   r{   rX   rY   zFind your index at z	/project/z/deploy/)r   r   r   r   r   r!   r   upsert_batch_pipeline_documentsrI   r0   r   r   r   r   r   id_sync_pipeliner   ra   rH   )r   r   r-   r2   r3   r1   r4   r5   r6   r7   rX   rY   r   r   r=   r>   indexr   docupserted_documentsr{   s                        rQ   from_documentszLlamaCloudIndex.from_documents[  ss   ,   %+--! ! 
 SRZZ^^,A?SGXw@ $--MM)) %	  $ \\141Q1Q/2/M/Mww	 N 
 	&&5>>3D3D&E%78c36688!!W^ 	" 	
 	!')EMM4D4D3EXennN_N_M`a	
 1	 9s   A	E-
E2c                 `   ddl m} |j                  dd      }|j                  dd      }||} |d| j                  j                  | j
                  j                  | j                  | j                  | j                  | j                  | j                  || j                  | j                  d
|S )z*Return a Retriever for this managed index.r'   )LlamaCloudRetrieversimilarity_top_kNdense_similarity_top_k)
r1   r.   r4   r5   r6   r7   r3   r   r8   r9    )	retrieverr   poprH   r0   rI   rJ   rK   rL   rM   r3   rD   rE   )rP   r>   r   r   r   s        rQ   as_retrieverzLlamaCloudIndex.as_retriever  s    	
 "::&8$?!',Dd!K'%5"" 
||((MM^^MMMM 00#9++#77
 
 	
rS   c                 \    ddl m}  | j                  di ||d<    |j                  di |S )Nr   )RetrieverQueryEnginer   r   )4llama_index.core.query_engine.retriever_query_enginer   r   	from_args)rP   r>   r   s      rQ   as_query_enginezLlamaCloudIndex.as_query_engine  s:    	
 0d//9&9{-#--777rS   
batch_sizec                 *   | j                   j                  }g }d}|}	 | j                  j                  j	                  |||      }|sn|j                  |       ||z  }B|D ci c]$  }|j                  t        |j                  g       & c}S c c}w )zZRetrieve a dict mapping of ingested documents and their metadata. The nodes list is empty.r   )r.   skiplimit)r   node_ids)rI   r0   rF   r   list_pipeline_documentsextendr&   r   )rP   r   r.   pipeline_documentsr   r   batchr   s           rQ   ref_doc_infozLlamaCloudIndex.ref_doc_info  s     mm&&24LL**BB' C E
 %%e,EMD  *
 FFJrBB
 	
 
s   $)Br   insert_kwargsc                    | j                   j                  d      5  | j                  j                  j	                  | j
                  j                  t        |j                  |j                  |j                  |j                  |j                        g      }| j                  j                  j                  | j
                  j                         |d   }| j                  |j                  g|d       ddd       y# 1 sw Y   yxY w)	Insert a document.insertr   r   r   r   Tr   N)rO   as_tracerF   r   create_batch_pipeline_documentsrI   r0   r   r   r   r   r   r   r   r   rP   r   rX   r   r   upserted_documents         rQ   r   zLlamaCloudIndex.insert  s     ##,,X6 	!%!7!7!W!W MM,,'%]]!)!2!25=5Z5Z3;3V3V#<< "X " LL""00T]]=M=M0N 21 5$$*--.PT % %	 	 	   CD  D	c                 \  K   | j                   j                  d      5  | j                  j                  j	                  | j
                  j                  t        |j                  |j                  |j                  |j                  |j                        g       d{   }| j                  j                  j                  | j
                  j                         d{    |d   }| j                  |j                  g|d       d{    ddd       y7 {7 ;7 # 1 sw Y   yxY ww)	r   r   r   r   Nr   r   Tr   )rO   r   rG   r   r   rI   r0   r   r   r   r   r   r   r   r   r   s         rQ   ainsertzLlamaCloudIndex.ainsert       ##,,X6 	'+}}'>'>'^'^ MM,,'%]]!)!2!25=5Z5Z3;3V3V#<< (_ ( " --))77DMMDTDT7UUU 21 5++*--.PT ,   #	 	" V#	 	T   D,B D DAD  D!+D DD 	D,D D D  D)%D,update_kwargsc                    | j                   j                  d      5  | j                  j                  j	                  | j
                  j                  t        |j                  |j                  |j                  |j                  |j                        g      }| j                  j                  j                  | j
                  j                         |d   }| j                  |j                  g|d       ddd       y# 1 sw Y   yxY w)	/Upserts a document and its corresponding nodes.updater   r   r   r   Tr   N)rO   r   rF   r   r   rI   r0   r   r   r   r   r   r   r   r   rP   r   rX   r   r   r   s         rQ   update_ref_doczLlamaCloudIndex.update_ref_doc
  s     ##,,X6 	!%!7!7!W!W MM,,'%]]!)!2!25=5Z5Z3;3V3V#<< "X " LL""00T]]=M=M0N 21 5$$*--.PT % #	 	 	r   c                 \  K   | j                   j                  d      5  | j                  j                  j	                  | j
                  j                  t        |j                  |j                  |j                  |j                  |j                        g       d{   }| j                  j                  j                  | j
                  j                         d{    |d   }| j                  |j                  g|d       d{    ddd       y7 {7 ;7 # 1 sw Y   yxY ww)	r   r   r   r   Nr   r   Tr   )rO   r   rG   r   r   rI   r0   r   r   r   r   r   r   r   r   r   s         rQ   aupdate_ref_doczLlamaCloudIndex.aupdate_ref_doc#  r   r   c                 v   | j                   j                  d      5  | j                  j                  j	                  | j
                  j                  |D cg c]D  }t        |j                  |j                  |j                  |j                  |j                        F c}      }| j                  j                  j                  | j
                  j                         |D cg c]  }|j                   }}| j                  |dd       dgt        |      z  cddd       S c c}w c c}w # 1 sw Y   yxY w)2Refresh an index with documents that have changed.refreshr   r   r   Tr   N)rO   r   rF   r   r   rI   r0   r   r   r   r   r   r   r   r   rb   rP   r   r   r   r   r{   s         rQ   refresh_ref_docsz LlamaCloudIndex.refresh_ref_docs<  s    ##,,Y7 	)!%!7!7!W!W MM,,  )	  ( XX!$585U5U363Q3Q77	 "X " LL""00T]]=M=M0N);<#svv<G<$$WdSW$X6CL('	) 	)	 =#	) 	)s+   9D/A	D%AD/$D*7$D/%
D//D8c                   K   | j                   j                  d      5  | j                  j                  j	                  | j
                  j                  |D cg c]D  }t        |j                  |j                  |j                  |j                  |j                        F c}       d{   }| j                  j                  j                  | j
                  j                         d{    |D cg c]  }|j                   }}| j                  |dd       d{    dgt        |      z  cddd       S c c}w 7 7 Xc c}w 7 *# 1 sw Y   yxY ww)r   r   r   r   Nr   Tr   )rO   r   rG   r   r   rI   r0   r   r   r   r   r   r   r   r   rb   r   s         rQ   arefresh_ref_docsz!LlamaCloudIndex.arefresh_ref_docsU  s@     ##,,Y7 	)'+}}'>'>'^'^ MM,,  )	  ( XX!$585U5U363Q3Q77	 (_ ( " --))77DMMDTDT7UUU);<#svv<G<++d ,    6CL(+	) 	)	" V<%	) 	)sl   E9EA	D? E+E,AE-E.E6E	E"E#E5
E?EEEEE
ref_doc_iddelete_from_docstoreraise_if_not_founddelete_kwargsc                 J   	 | j                   j                  j                  | j                  j                  t        t        |                   | j                  |d       y# t        $ r6}|j                  dk(  r|st        j                  d| d       n Y d}~Nd}~ww xY w)4Delete a document and its nodes by using ref_doc_id.r     ref_doc_id  not found, nothing deleted.NFrX   r|   )rF   r   delete_pipeline_documentrI   r0   r   r   rm   loggerwarningr   rP   r  r  rX   r  r  ru   s          rQ   delete_ref_doczLlamaCloudIndex.delete_ref_docp  s    
	LL"";; MM,,&z*'=> <  	  5 Q  	}}#,>ZL8TUV W	s   AA# #	B",,BB"c                 z  K   	 | j                   j                  j                  | j                  j                  t        t        |                   d{    | j                  |d       d{    y7  # t        $ r6}|j                  dk(  r|st        j                  d| d       n Y d}~Xd}~ww xY w7 Iw)r  r   Nr	  r
  r  Fr  )rG   r   r  rI   r0   r   r   rm   r  r  r   r  s          rQ   adelete_ref_doczLlamaCloudIndex.adelete_ref_doc  s     
	--))BB MM,,&z*'=> C    ''RW'XXX  	}}#,>ZL8TUV W	 	YsM   B;AA7 A5A7 B;/B90B;5A7 7	B6 ,B1,B;1B66B;	file_pathcustom_metadatawait_for_ingestionc                    t        |d      5 }| j                  j                  j                  | j                  j
                  |      }|r%t        d|j
                   d|j                          ddd       t        j
                  |      }| j                  j                  j                  | j                  j
                  |g       |r| j                  |j
                  g||       |j
                  S # 1 sw Y   xY w)	Upload a file to the index.rbr1   upload_fileUploaded file r   Nr   r  r   rz   rX   rY   )openrF   filesr  rH   r0   ra   r-   r   r   add_files_to_pipeline_apirI   r   	rP   r  r  rX   r  rY   fr   pipeline_file_creates	            rQ   r  zLlamaCloudIndex.upload_file  s     )T" 	Ha<<%%11<<?? 2 D twwi{499+FG	H  2GG_ 
 	##==((3G2H 	> 	
 $$''GN %  ww'	H 	Hs   A#C88Dc                 L  K   t        |d      5 }| j                  j                  j                  | j                  j
                  |       d{   }|r%t        d|j
                   d|j                          ddd       t        j
                  |      }| j                  j                  j                  | j                  j
                  |g       d{    |r'| j                  |j
                  g||       d{    |j
                  S 7 # 1 sw Y   xY w7 G7  w)	r  r  r  Nr  r   r  r   r  )r  rG   r   r  rH   r0   ra   r-   r   r   r!  rI   r   r"  s	            rQ   aupload_filezLlamaCloudIndex.aupload_file  s     )T" 	Ha,,88<<?? 9  D twwi{499+FG	H  2GG_ 
 mm**DD((3G2H E 
 	
 	
 ++''GN ,    ww'	H 	H	

sM   D$?DD+D:AD$D (D$D"D$DDD$"D$	file_nameurl	proxy_urlrequest_headers
verify_sslfollow_redirectsc           	         | j                   j                  j                  | j                  j                  ||||||      }|r%t        d|j                   d|j                          t        |j                  |      }| j                   j                  j                  | j                  j                  |g       |	r| j                  |j                  g||
       |j                  S )&Upload a file from a URL to the index.r1   r-   r(  r)  r*  r+  r,  r  	 with ID r  r   r  )rF   r   upload_file_from_urlrH   r0   ra   r   r   r!  rI   r   rP   r'  r(  r  r)  r*  r+  r,  rX   r  rY   r   r$  s                rQ   r1  z$LlamaCloudIndex.upload_file_from_url  s      ||!!66||+!- 7 
 N477)9TWWI>?  2GG_ 
 	##==((3G2H 	> 	
 $$''GN %  wwrS   c           	        K   | j                   j                  j                  | j                  j                  ||||||       d{   }|r%t        d|j                   d|j                          t        |j                  |      }| j                   j                  j                  | j                  j                  |g       d{    |	r'| j                  |j                  g||
       d{    |j                  S 7 7 ;7 w)r.  r/  Nr  r0  r  r   r  )rG   r   r1  rH   r0   ra   r   r   r!  rI   r   r2  s                rQ   aupload_file_from_urlz%LlamaCloudIndex.aupload_file_from_url  s	      ]]((==||+!- > 
 
 N477)9TWWI>?  2GG_ 
 mm**DD((3G2H E 
 	
 	
 ++''GN ,    ww3
 	

s7   ADDBDD	(D1D2DDDc                     t        d      )z=Index-specific logic for inserting nodes to the index struct.z,_insert not implemented for LlamaCloudIndex.NotImplementedErrorrP   r<   r   s      rQ   _insertzLlamaCloudIndex._insert8  s    !"PQQrS   c                     t        d      )zBuild the index from nodes.z;build_index_from_nodes not implemented for LlamaCloudIndex.r6  )rP   r<   s     rQ   build_index_from_nodesz&LlamaCloudIndex.build_index_from_nodes<  s     "I
 	
rS   c                     t        d      )zInsert a set of nodes.z1insert_nodes not implemented for LlamaCloudIndex.r6  r8  s      rQ   insert_nodeszLlamaCloudIndex.insert_nodesC  s    !"UVVrS   r   c                     t        d      )zDelete a set of nodes.z1delete_nodes not implemented for LlamaCloudIndex.r6  )rP   r   r  r  s       rQ   delete_nodeszLlamaCloudIndex.delete_nodesG  s     ""UVVrS   )NNFFFg      ?)d   )F)FFF)NFTF)NNNTTFTF)@__name__
__module____qualname____doc__r   r   strintrj   ClientAsyncClientrB   r   r   r"   r$   r   rR   propertyr0   r   r   r   floatrv   r   ry   r   r   classmethodr	   r   r   r   r   r   r#   r   r   r   r   r   r   r
   r&   r   r   r   r   r   r   r  r  r  dictr   r  r&  r1  r4  r9  r;  r=  r?  r   rS   rQ   r+   r+   7   s2   H #%)"& $(0)-!%"&!%/3:>#6:*.>B/IO smIO c]	IO
 3-IO SMIO SMIO IO "#IO #IO 3-IO #IO IO  u||,!IO" %U%6%67#IO& 'IO( #?3)IO, X'-IO. "$'9":;/IO0 1IO2 
3IOV  C    FsmF  'E EFF 	F
 F F F 
FPFsmF  y1O'P PQF 	F
 F F F 
FT -1+/).$ #U'8C=)U' (3-(U' 	U'
 #'U' U' U' 
0	1U'r -1+/).$ #U'8C=)U' (3-(U' 	U'
 #'U' U' U' 
0	1U'n  1)-$(!%"&!%DHDHAE7
#$7
7
 7
 "#	7

 SM7
 #7
 3-7
 #7
 7
 7
 ##@A7
 ##@A7
 !))= >7
 7
  
!7
 7
r  1)-!%"&!%DHDHAE7
#$7
7
 7
 "#	7

 #7
 3-7
 #7
 7
 7
 ##@A7
 ##@A7
 !))= >7
 7
 
7
 7
r 
 1)-$(!%"&!%$DHDH>B#A#$A>A A 	A
 "#A SMA #A 3-A #A A A A ##@AA ##@AA" "$'9":;#A$ %A& 
'A AF
S 
] 
2 8 8 8 8 
s 
T#z/5J 
 
, 38 +/JM	6 38 +/JM	4 38 +/JM	4 38 +/JM	2)!(+)>A)	d)2)!(+)>A)	d)< &+#(RR #R 	R
 !R R 
R6 &+#(YY #Y 	Y
 !Y Y 
Y: #'$ "hDEEF
  !  
J #'$ "hDEEF
  !  
N #'48!%#'$(( ( "hDEEF
	( C=( "$sCx.1( ( ( ( !( ( 
(` #'48!%#'$)) ) "hDEEF
	) C=) "$sCx.1) ) ) ) !) ) 
)ZRXh/ R# R$ R 
HX,> 
4 
 
W(8"4 Ws Wt W &+Ws)W #W 	W
 
WrS   r+   )?rD  rx   rj   r   rn   typingr   r   r   r   r   r   r	   r
   typing_extensionsr   urllib.parser   llama_cloudr   r   r   r   r   r   r   r   r   r   r   r   'llama_index.core.base.base_query_enginer   $llama_index.core.base.base_retrieverr   llama_index.core.callbacks.baser   llama_index.core.constantsr   r   %llama_index.core.indices.managed.baser   llama_cloud.core.api_errorr   $llama_index.core.ingestion.api_utilsr    r!   llama_index.core.schemar"   r#   r$   llama_index.core.settingsr%   'llama_index.core.storage.docstore.typesr&   	api_utilsr(   r)   logging	getLoggerrA  r  r+   r   rS   rQ   <module>r^     s      	  Q Q Q & #    D > ; L B / K J . > 			8	$WW& WWrS   