
    Cj&4                    `   % S r SSKJr  / SQ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  SSK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  SSK J!r!  SSK"J#r#J$r$  SSK%J&r&  SSK'J(r(  \	(       a  SSKJ)r)  \\\\\S.r*S\+S'   SS jr,    S           SS jjr-\(     S             S S jj5       r.  S!           S"S jjr/\(  S!           S"S jj5       r0\(  S!           S#S jj5       r1\(     S             S$S jj5       r2g)%z
RAG Ingest API for LiteLLM.

Provides an all-in-one API for document ingestion:
Upload -> (OCR) -> Chunk -> Embed -> Vector Store
    )annotations)ingestaingestqueryaqueryN)partial)	TYPE_CHECKINGAny	CoroutineDictListOptionalTupleTypeUnion)BaseRAGIngestion)BedrockRAGIngestion)GeminiRAGIngestion)OpenAIRAGIngestion)S3VectorsRAGIngestion)VertexAIRAGIngestion)RAGQuery)RAGIngestOptionsRAGIngestResponse)ModelResponse)client)Router)openaibedrockgemini
s3_vectors	vertex_aiz!Dict[str, Type[BaseRAGIngestion]]INGESTION_REGISTRYc                    [         R                  U 5      nUc4  SR                  [         R                  5       5      n[	        SU  SU 35      eU$ )z
Get the ingestion class for a given provider.

Args:
    provider: The vector store provider name (e.g., 'openai')

Returns:
    The ingestion class for the provider

Raises:
    ValueError: If provider is not supported
z, z
Provider 'z;' is not supported for RAG ingestion. Supported providers: )r#   getjoinkeys
ValueError)provideringestion_class	supporteds      b/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/litellm/rag/main.pyget_ingestion_classr-   :   s]     ),,X6OII05578	
 #$$-;0
 	
     c                   #    U R                  S5      =(       d    0 nUR                  SS5      n[        U5      nU" U US9nUR                  UUUS9I Sh  vN $  N7f)a  
Execute the RAG ingest pipeline using provider-specific implementation.

Args:
    ingest_options: Configuration for the ingest pipeline
    file_data: Tuple of (filename, content_bytes, content_type)
    file_url: URL to fetch file from
    file_id: Existing file ID to use
    router: Optional LiteLLM router for load balancing

Returns:
    RAGIngestResponse with status and IDs
vector_storecustom_llm_providerr   )ingest_optionsrouter)	file_datafile_urlfile_idN)r%   r-   r   )	r2   r4   r5   r6   r3   vector_store_configr)   r*   	ingestions	            r,   _execute_ingest_pipeliner9   Q   s{     * ),,^<B"&&'<hGH *(3O  %I !! "    s   AAAAc           
       #    [        5       n [        R                  " 5       nSUS'   [        [        4U UUUUUS.UD6n	[
        R                  " 5       n
[        U
R                  U	5      nUR                  SU5      I Sh  vN n[        R                  " U5      (       a  UI Sh  vN nU$ UnU$  N/ N! [         a<  n[        R                  " SU R                  S0 5      R                  S5      UUUS9eSnAff = f7f)a  
Async: Ingest a document into a vector store.

Args:
    ingest_options: Configuration for the ingest pipeline
    file_data: Tuple of (filename, content_bytes, content_type)
    file: Dict with {filename, content (base64), content_type} - for JSON API
    file_url: URL to fetch file from
    file_id: Existing file ID to use

Example:
    ```python
    response = await litellm.aingest(
        ingest_options={
            "vector_store": {
                "custom_llm_provider": "openai",
                "litellm_credential_name": "my-openai-creds",  # optional
            }
        },
        file_url="https://example.com/doc.pdf",
    )
    ```
Tr   )r2   r4   filer5   r6   timeoutNr0   r1   modelr1   original_exceptioncompletion_kwargsextra_kwargs)localsasyncioget_event_loopr   r   contextvarscopy_contextrunrun_in_executoriscoroutine	Exceptionlitellmexception_typer%   )r2   r4   r;   r5   r6   r<   kwargs
local_varsloopfuncctxfunc_with_contextinit_responseresponsees                  r,   r   r   }   s    B J"
%%' y	
)	
 	
 &&(#CGGT2"2249JKK}--**H  %H L +
  	
$$ . 2 2>2 F J J%!  !(
 	
	
sY   C<A1B3 ?B/ $B3 $B1%B3 *C<+B3 .C</B3 1B3 3
C9=7C44C99C<c           
       #    UR                  SS5      n[        R                  " U5      nU(       d  [        S5      e[        R
                  R                  " SUS   UUR                  SS5      UR                  SS5      S	.UD6I Sh  vN nSn	UR                  S
/ 5      n
U(       a{  UR                  S5      (       ae  [        R                  " U5      nU(       aH  [        R                  " US   UUUR                  SS5      S9I Sh  vN n	[        R                  " X5      n
[        R                  " U
5      nUSS U/-   US   /-   nUb  UR                  " SU UUS.UD6I Sh  vN nO"[        R                  " SU UUS.UD6I Sh  vN nU(       d+  [        U[        5      (       a  [        R                  " UUU	S9nU$  GN9 N N` N?7f)z!
Execute the RAG query pipeline.
r3   Nz(No query found in messages for RAG queryvector_store_idtop_k
   r1   r   )rW   r   max_num_resultsr1   dataenabledr>   top_n   )r>   r   	documentsr]   )r>   messagesstream)rT   search_resultsrerank_results )popr   extract_query_from_messagesr(   rK   vector_storesasearchr%   extract_documents_from_searcharerankget_top_chunks_from_rerankbuild_context_messageacompletion
isinstancer   add_search_results_to_response)r>   ra   retrieval_configrerankrb   rM   r3   
query_textsearch_responsererank_responsecontext_chunksr_   context_messagemodified_messagesrT   s                  r,   _execute_query_pipelinery      s     "(Hd!;F 55h?JCDD $1199 ():;(,,Wb9,001FQ	
  O O$((4N &**Y''::?K	$+OOWo #jj!,	% O &@@N
 44^DO "(99Xb\NJ ++ 
&
 	
 
 !,, 
&
 	
 
 j=99::**
 Ok 

sJ   BG
G	A?G
G	AG
%G&"G
G	9G
G
G
G
c           	       #    [        5       n [        R                  " 5       nSUS'   [        [        4U UUUUS.UD6n[
        R                  " 5       n	[        U	R                  U5      n
UR                  SU
5      I Sh  vN n[        R                  " U5      (       a  UI Sh  vN nU$ UnU$  N/ N! [         a,  n[        R                  " U UR                  S5      UUUS9eSnAff = f7f)z
Async: Query a RAG pipeline.
Tr   r>   ra   rq   rr   rb   Nr1   r=   )rB   rC   rD   r   r   rE   rF   rG   rH   rI   rJ   rK   rL   r%   )r>   ra   rq   rr   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   s                 r,   r   r     s     J
%%'x
-
 
 &&(#CGGT2"2249JKK}--**H  %H L +
  
$$ 0 4 45J K (
 	

sY   C+A0B2 >B.?$B2 #B0$B2 )C+*B2 -C+.B2 0B2 2
C(<'C##C((C+c                H   [        5       n UR                  SS5      SL nU(       a  [        SU UUUUS.UD6$ [        R                  " 5       R                  [        SU UUUUS.UD65      $ ! [         a,  n[        R                  " U UR                  S5      UUUS9eSnAff = f)	z
Query a RAG pipeline.
r   FTr{   r1   r=   Nre   )
rB   rf   ry   rC   rD   run_until_completerJ   rK   rL   r%   )	r>   ra   rq   rr   rb   rM   rN   	_is_asyncrU   s	            r,   r   r   @  s     J
JJx/47	* !!1   ))+>>' %%5!! 	 	  
$$ 0 4 45J K (
 	

s   +A+ 2A+ +
B!5'BB!c           
     $   SSK n[        5       n UR                  SS5      SL n	UR                  S5      n
UbN  UcK  UR                  SS5      nUR                  S	S
5      nUR                  SS5      nUR	                  U5      nXU4nU	(       a  [        U UUUU
S9$ [        R                  " 5       R                  [        U UUUU
S95      $ ! [         a<  n[        R                  " SU R                  S0 5      R                  S5      UUUS9eSnAff = f)a  
Ingest a document into a vector store.

Args:
    ingest_options: Configuration for the ingest pipeline
    file_data: Tuple of (filename, content_bytes, content_type)
    file: Dict with {filename, content (base64), content_type} - for JSON API
    file_url: URL to fetch file from
    file_id: Existing file ID to use

Example:
    ```python
    response = litellm.ingest(
        ingest_options={
            "vector_store": {
                "custom_llm_provider": "openai",
                "litellm_credential_name": "my-openai-creds",  # optional
            }
        },
        file_data=("doc.txt", b"Hello world", "text/plain"),
    )
    ```
r   Nr   FTr3   filenamedocumentcontent content_typezapplication/octet-stream)r2   r4   r5   r6   r3   r0   r1   r=   )base64rB   rf   r%   	b64decoder9   rC   rD   r}   rJ   rK   rL   )r2   r4   r;   r5   r6   r<   rM   r   rN   r~   r3   r   content_b64r   content_bytesrU   s                   r,   r   r   n  s4   B J'
JJy%0D8	%+ZZ%9 	 1xx
J7H((9b1K88N4NOL",,[9M!,?I+-#!  ))+>>(#1'%#!   	
$$ . 2 2>2 F J J%!  !(
 	
	
s   B	C	 .C	 	
D7D

D)r)   strreturnzType[BaseRAGIngestion])NNNN)r2   r   r4    Optional[Tuple[str, bytes, str]]r5   Optional[str]r6   r   r3   zOptional['Router']r   r   )NNNNN)r2   Dict[str, Any]r4   r   r;   Optional[Dict[str, str]]r5   r   r6   r   r<   %Optional[Union[float, httpx.Timeout]]r   r   )NF)r>   r   ra   	List[Any]rq   r   rr   Optional[Dict[str, Any]]rb   boolr   r   )r>   r   ra   r   rq   r   rr   r   rb   r   r   z8Union[ModelResponse, Coroutine[Any, Any, ModelResponse]])r2   r   r4   r   r;   r   r5   r   r6   r   r<   r   r   z@Union[RAGIngestResponse, Coroutine[Any, Any, RAGIngestResponse]])3__doc__
__future__r   __all__rC   rE   	functoolsr   typingr	   r
   r   r   r   r   r   r   r   httpxrK   $litellm.rag.ingestion.base_ingestionr   'litellm.rag.ingestion.bedrock_ingestionr   &litellm.rag.ingestion.gemini_ingestionr   &litellm.rag.ingestion.openai_ingestionr   *litellm.rag.ingestion.s3_vectors_ingestionr   )litellm.rag.ingestion.vertex_ai_ingestionr   litellm.rag.rag_queryr   litellm.types.ragr   r   litellm.types.utilsr   litellm.utilsr   r   r#   __annotations__r-   r9   r   ry   r   r   r   re   r.   r,   <module>r      s   #
2   
 
 
   A G E E L J * .  
 !" '%9 5 2 37"!!%&$&/& & 	&
 & &X  37%)"!59C
"C
/C
 #C
 	C

 C
 3C
 C
 C
T (,JJJ %J %	J
 J JZ 
 (,+
+
+
 %+
 %	+

 +
 +
 +
\ 
 (,*
*
*
 %*
 %	*

 *
 >*
 *
Z  37%)"!59J
"J
/J
 #J
 	J

 J
 3J
 FJ
 J
r.   