
    h>                        d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlZddlZddlmZ ddl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 dd
lm Z m!Z! ddl"m#Z#  e       Z$	 d%de
e	e      fdZ%	 d%de
e   fdZ&e!	 	 	 	 	 	 	 	 	 	 d&de
e'   de
e	e'      de
e   de
e   de
ee'e'f      de
ee'ef      de
ee'ef      de
ee'ef      de
ee(ejR                  f      de
e'   defd       Z*e!	 	 	 	 	 	 	 	 	 	 d&de
e'   de
e	e'      de
e   de
e   de
ee'e'f      de
ee'ef      de
ee'ef      de
ee'ef      de
ee(ejR                  f      de
e'   deeeeeef   f   fd       Z+e!	 	 	 	 	 	 	 	 	 d'de'dee'e	e'   f   de
e   d e
e,   d!e
e   d"e
e-   de
ee'ef      de
ee'ef      de
ee'ef      de
ee(ejR                  f      de
e'   defd#       Z.e!	 	 	 	 	 	 	 	 	 d'de'dee'e	e'   f   de
e   d e
e,   d!e
e   d"e
e-   de
ee'ef      de
ee'ef      de
ee'ef      de
ee(ejR                  f      de
e'   deeeeeef   f   fd$       Z/y)(z@
LiteLLM SDK Functions for Creating and Searching Vector Stores
    N)partial)Any	CoroutineDictListOptionalUnion)request_timeout)Logging)BaseLLMHTTPHandler)GenericLiteLLMParams)&VectorStoreCreateOptionalRequestParamsVectorStoreCreateResponseVectorStoreFileCountsVectorStoreResultContent&VectorStoreSearchOptionalRequestParamsVectorStoreSearchResponseVectorStoreSearchResult)ProviderConfigManagerclient)VectorStoreRequestUtilsmock_resultsc                 V    | t        dt        dd      g      g} t        dd|       S )	z%Mock response for vector store searchgffffff?z5This is a sample search result from the vector store.text)r   type)scorecontentz vector_store.search_results.pagezsample query)objectsearch_querydata)r   r   r   r   s    V/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/vector_stores/main.py!mock_vector_store_search_responser#   "   sG     #,T#

 %1#     mock_responsec                 R    | $t        dddddt        ddddd      ddddd	      } | S )
z%Mock response for vector store createN
vs_mock123vector_storeiEezMock Vector Storer   )in_progress	completedfailed	cancelledtotalr*   )idr   
created_atnamebytesfile_countsstatusexpires_after
expires_atlast_active_atmetadata)r   r   r%   s    r"   !mock_vector_store_create_responser9   :   sS     1!!$- #
( r$   r0   file_idsr4   chunking_strategyr7   extra_headersextra_query
extra_bodytimeoutcustom_llm_providerreturnc
                   K   t               }	 t        j                         }d|
d<   |	d}	t        t        f| |||||||||	d
|
}t        j                         }t        |j                  |      }|j                  d|       d{   }t        j                  |      r| d{   }|S |}|S 7 )7 # t        $ r}t        j                  d|	|||
      d}~ww xY ww)z'
    Async: Create a vector store.
    TacreateNopenai)
r0   r:   r4   r;   r7   r<   r=   r>   r?   r@   modelr@   original_exceptioncompletion_kwargsextra_kwargs)localsasyncioget_event_loopr   createcontextvarscopy_contextrunrun_in_executoriscoroutine	Exceptionlitellmexception_type)r0   r:   r4   r;   r7   r<   r=   r>   r?   r@   kwargs
local_varsloopfuncctxfunc_with_contextinit_responseresponsees                      r"   rC   rC   V   s    ( J(
%%' y &"*
'/'#! 3
 
 &&(#CGGT2"2249JKK}-**H  %H L +
  
$$ 3 (
 	

sY   CA7B3 B/B3 $B1%B3 *C+B3 .C/B3 1B3 3	C<CCCc
                    t               }	 |
j                  d      }|
j                  dd      }|
j                  dd      du }t        di |
}|j                  r9t        |j                  t              rt        t        di |j                        S |	d}	t        j                  t        j                  |	      	      }|t        d
|	       |j                  |
       t        j                   |      }|j#                  dd| i|d|i|	       t$        j'                  |||	|||||xs t(        ||
j                  d      
      }|S # t*        $ r}t        j,                  d|	|||
      d}~ww xY w)a  
    Create a vector store.
    
    Args:
        name: The name of the vector store.
        file_ids: A list of File IDs that the vector store should use.
        expires_after: The expiration policy for the vector store.
        chunking_strategy: The chunking strategy used to chunk the file(s).
        metadata: Set of 16 key-value pairs that can be attached to an object.
        
    Returns:
        VectorStoreCreateResponse containing the created vector store details.
    litellm_logging_objlitellm_call_idNrC   FTr8   rD   providerz)Vector store create is not supported for r0   rF   optional_paramslitellm_paramsr@   r   )
#vector_store_create_optional_paramsvector_store_provider_configr@   rf   logging_objr<   r>   r?   	_is_asyncr   rE    )rJ   getpopr   r%   
isinstancedictr9   r   r   !get_provider_vector_stores_configrT   LlmProviders
ValueErrorupdater   0get_requested_vector_store_create_optional_paramupdate_environment_variablesbase_llm_http_handlervector_store_create_handlerr
   rS   rU   )r0   r:   r4   r;   r7   r<   r=   r>   r?   r@   rV   rW   r`   ra   rj   rf   rh   rg   r]   r^   s                       r"   rM   rM      s   < JI
17<Q1R)/4Et)LJJy%0D8	 .77 ''J(($-
 57W.:V:VW 
 &"* (='^'^))*=>(
$ (/;<O;PQ  	&! $TT 	, 	885
 "? !4 	9 
	
 )DD0S)E 3)+'!.::h' E 
  
$$ 3 (
 	

s   BE	 B5E	 		E1E,,E1vector_store_idqueryfiltersmax_num_resultsranking_optionsrewrite_queryc                   K   t               }	 t        j                         }d|d<   |
d}
t        t        f| |||||||||	|
d|}t        j                         }t        |j                  |      }|j                  d|       d{   }t        j                  |      r| d{   }|S |}|S 7 )7 # t        $ r}t        j                  d|
|||      d}~ww xY ww)zg
    Async: Search a vector store for relevant chunks based on a query and file attributes filter.
    TasearchNrD   )rx   ry   rz   r{   r|   r}   r<   r=   r>   r?   r@   rE   )rJ   rK   rL   r   searchrN   rO   rP   rQ   rR   rS   rT   rU   )rx   ry   rz   r{   r|   r}   r<   r=   r>   r?   r@   rV   rW   rX   rY   rZ   r[   r\   r]   r^   s                       r"   r   r     s    * J)
%%' y &"*
+++''#! 3
 
  &&(#CGGT2"2249JKK}-**H  %H L +
  
$$ 3 (
 	

sY   CA8B4 B0B4 %B2&B4 +C,B4 /C0B4 2B4 4	C=CCCc                 &   t               }	 |j                  d      }|j                  dd      }|j                  dd      du }t        di |}|j                  rTt        |j                  t        t        f      r4d}t        |j                  t              r|j                  }t        |      S |
d}
t        j                  t        j                  |
      	      }|t        d
|
       |j                  |       t        j                   |      }|j#                  d| |d||| d|
       t$        j'                  | ||||
|||||	xs t(        ||j                  d            }|S # t*        $ r}t        j,                  d|
|||      d}~ww xY w)ag  
    Search a vector store for relevant chunks based on a query and file attributes filter.
    
    Args:
        vector_store_id: The ID of the vector store to search.
        query: A query string or array for the search.
        filters: Optional filter to apply based on file attributes.
        max_num_results: Maximum number of results to return (1-50, default 10).
        ranking_options: Optional ranking options for search.
        rewrite_query: Whether to rewrite the natural language query for vector search.
        
    Returns:
        VectorStoreSearchResponse containing the search results.
    r`   ra   Nr   FTr!   rD   rb   z)Vector store search is not supported for )rx   ry   )ra   rx   rd   r   )rx   ry   #vector_store_search_optional_paramsrh   r@   rf   ri   r<   r>   r?   rj   r   rE   rk   )rJ   rl   rm   r   r%   rn   strlistr#   r   rp   rT   rq   rr   rs   r   0get_requested_vector_store_search_optional_paramru   rv   vector_store_search_handlerr
   rS   rU   )rx   ry   rz   r{   r|   r}   r<   r=   r>   r?   r@   rV   rW   r`   ra   rj   rf   r   rh   r   r]   r^   s                         r"   r   r   C  s   @ JN
17<Q1R)/4Et)LJJy%0D8	 .77 ''J((3+-
  L.66=-;;4,OO &"* (='^'^))*=>(
$ (/;<O;PQ  	&! $TT 	, 	88#2 6 $3#2 !4 	9 	
 )DD+0S)E 3)+'!.::h' E 
  
$$ 3 (
 	

s   B!E( .B9E( (	F1FF)N)
NNNNNNNNNN)	NNNNNNNNN)0__doc__rK   rN   	functoolsr   typingr   r   r   r   r   r	   httpxrT   litellm.constantsr
   *litellm.litellm_core_utils.litellm_loggingr   LiteLLMLoggingObj*litellm.llms.custom_httpx.llm_http_handlerr   litellm.types.routerr   litellm.types.vector_storesr   r   r   r   r   r   r   litellm.utilsr   r   litellm.vector_stores.utilsr   rv   r#   r9   r   floatTimeoutrC   rM   intboolr   r   rk   r$   r"   <module>r      s      > >   - S I 5   8 ? +, 
 =A4 7892 :>568 $($((,)- /3,0+/59)-<

3-<
tCy!<
 D><
  ~	<

 tCH~&<
 DcN+<
 $sCx.)<
 c3h(<
 eE5==012<
 "#<
 <
 <
~ $($((,)- /3,0+/59)-g

3-g
tCy!g
 D>g
  ~	g

 tCH~&g
 DcN+g
 $sCx.)g
 c3h(g
 eE5==012g
 "#g
 $iS:S0S&TTUg
 g
T  #%)&*$( /3,0+/59)->
>
d3i >
 d^>
 c]	>

 d^>
 D>>
 DcN+>
 $sCx.)>
 c3h(>
 eE5==012>
 "#>
  !>
 >
B  #%)&*$( /3,0+/59)-n
n
d3i n
 d^n
 c]	n

 d^n
 D>n
 DcN+n
 $sCx.)n
 c3h(n
 eE5==012n
 "#n
  $iS:S0S&TTU!n
 n
r$   