
    jC                        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 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jV                  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jV                  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jV                  f      de
e)   defd$       Z0e#	 	 	 	 	 	 	 	 	 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jV                  f      de
e)   deeeeeef   f   fd%       Z1y))z@
LiteLLM SDK Functions for Creating and Searching Vector Stores
    N)partial)Any	CoroutineDictListOptionalUnion)request_timeout)get_llm_provider)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    s/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/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_responser:   <   sS     1!!$- #
( r%   r1   file_idsr5   chunking_strategyr8   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)
r1   r;   r5   r<   r8   r=   r>   r?   r@   rA   modelrA   original_exceptioncompletion_kwargsextra_kwargs)localsasyncioget_event_loopr   createcontextvarscopy_contextrunrun_in_executoriscoroutine	Exceptionlitellmexception_type)r1   r;   r5   r<   r8   r=   r>   r?   r@   rA   kwargs
local_varsloopfuncctxfunc_with_contextinit_responseresponsees                      r#   rD   rD   X   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        |	d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_idNrD   FTr9   rE   rG   rA   litellm_paramsproviderapi_typez)Vector store create is not supported for r1   rG   optional_paramsrd   rA   r   )
#vector_store_create_optional_paramsvector_store_provider_configrA   rd   logging_objr=   r?   r@   	_is_asyncr   rF    )rK   getpopr   r&   
isinstancedictr:   r   r   r   !get_provider_vector_stores_configrU   LlmProviders
ValueErrorupdater   0get_requested_vector_store_create_optional_paramupdate_environment_variablesbase_llm_http_handlervector_store_create_handlerr
   rT   rV   )r1   r;   r5   r<   r8   r=   r>   r?   r@   rA   rW   rX   ra   rb   rm   rd   rg   _rk   rj   r^   r_   s                         r#   rN   rN      s   < JR
17<Q1R)/4Et)LJJy%0D8	 .77 ''J(($-
 57W.:V:VW 
 &"*.>% $/
+%q! "CC --.AB! 	% (/;<O;PQ  	&! $TT 	, 	885
 "? !4 	9 
	
 )DD0S)E 3)+'!.::h' E 
  
$$ 3 (
 	

s   BE C	E 	F&F  F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asearchNrE   )r|   r}   r~   r   r   r   r=   r>   r?   r@   rA   rF   )rK   rL   rM   r   searchrO   rP   rQ   rR   rS   rT   rU   rV   )r|   r}   r~   r   r   r   r=   r>   r?   r@   rA   rW   rX   rY   rZ   r[   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                 V   t               }	 |j                  d      }|j                  dd      }|j                  dd      du }|j                  d|       }t        j                  3|1	 t        j                  j                  |      }|j                  |       t        dd| i|}|j                  rTt        |j                  t        t        f      r4d}t        |j                  t              r|j                  }t        |      S |
d	}
d
|
v rt        |
dd      \  }}
}}nd}|
}
t        j                   t        j"                  |
      |      }|t%        d|
       |j                  |       t'        j(                  ||      }|j+                  || |d||| d|j-                  d      |
       t.        j1                  | ||||
|||||	xs t2        ||j                  d            }|S # t        $ r Y dw xY w# t        $ r}t        j4                  d|
|||      d}~ww xY w)a[  
    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.
    ra   rb   Nr   FTr|   r"   rE   /rc   re   z)Vector store search is not supported for )rk   )r|   r}   )rb   r|   )exclude_nonerh   r   )r|   r}   #vector_store_search_optional_paramsrk   rA   rd   rl   r=   r?   r@   rm   r   rF   rn   )rK   ro   rp   rU   vector_store_registry get_credentials_for_vector_storerv   rT   r   r&   rq   strlistr$   r   r   rs   rt   ru   r   0get_requested_vector_store_search_optional_paramrx   
model_dumpry   vector_store_search_handlerr
   rV   )r|   r}   r~   r   r   r   r=   r>   r?   r@   rA   rW   rX   ra   rb   rm   vector_store_id_for_credentialsregistry_credentialsrd   r   rg   r{   rk   r   r^   r_   s                             r#   r   r   O  s   @ Jm
17<Q1R)/4Et)LJJy%0D8	 +1**5F*X'))5/;11RR7 %
 23
 .XoXQWX ''J((3+-
  L.66=-;;4,OO &"*%%2B)$(#3/H)1a H"5 "CC --.AB! 	% (/;<O;PQ  	&! $TT-I 	, 	88#2 6 $3#2 !+++>
 !4 	9 	
 )DD+0S)E 3)+'!.::h' E 
 g  h  
$$ 3 (
 	

sD   AH  (0G0 A,H  C*H  0	G=9H  <G==H   	H(	H##H()N)
NNNNNNNNNN)	NNNNNNNNN)2__doc__rL   rO   	functoolsr   typingr   r   r   r   r   r	   httpxrU   litellm.constantsr
   1litellm.litellm_core_utils.get_llm_provider_logicr   *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   ry   r$   r:   r   floatTimeoutrD   rN   intboolr   r   rn   r%   r#   <module>r      s      > >   - N 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)-p

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

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

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

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