
    Ah-&                         S r SSKJr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JrJr  SS
KJr  SSKJr  S\4S jr " S S\5      rS\\   4S jr " S S\5      rg)z'Vectorstore stubs for the indexing api.    )AnyOptional)
BaseLoader)Document)
Embeddings)BaseLanguageModel)VectorStore)RecursiveCharacterTextSplitterTextSplitter)	BaseModel
ConfigDictField)RetrievalQAWithSourcesChain)RetrievalQAreturnc                      [        SSS9$ )z=Return the default text splitter used for chunking documents.i  r   )
chunk_sizechunk_overlap)r
        U/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/indexes/vectorstore.py_get_default_text_splitterr      s    )TKKr   c                   "   \ rS rSr% Sr\\S'   \" SSS9r  SS\	S	\
\   S
\
\\	\4      S\S\	4
S jjr  SS\	S	\
\   S
\
\\	\4      S\S\	4
S jjr  SS\	S	\
\   S
\
\\	\4      S\S\4
S jjr  SS\	S	\
\   S
\
\\	\4      S\S\4
S jjrSrg)VectorStoreIndexWrapper   z-Wrapper around a vectorstore for easy access.vectorstoreTforbidarbitrary_types_allowedextraNquestionllmretriever_kwargskwargsr   c           	          Uc  Sn[        U5      eU=(       d    0 n[        R                  " U4SU R                  R                  " S0 UD60UD6nUR                  UR                  U05      UR                     $ )a]  Query the vectorstore using the provided LLM.

Args:
    question: The question or prompt to query.
    llm: The language model to use. Must not be None.
    retriever_kwargs: Optional keyword arguments for the retriever.
    **kwargs: Additional keyword arguments forwarded to the chain.

Returns:
    The result string from the RetrievalQA chain.
This API has been changed to require an LLM. Please provide an llm to use for querying the vectorstore.
For example,
from langchain_openai import OpenAI
llm = OpenAI(temperature=0)	retrieverr   )NotImplementedErrorr   from_chain_typer   as_retrieverinvoke	input_key
output_keyselfr!   r"   r#   r$   msgchains          r   queryVectorStoreIndexWrapper.query    s    $ ;.  &c**+1r++
&&33G6FG
 

 ||U__h789I9IJJr   c           	        #    Uc  Sn[        U5      eU=(       d    0 n[        R                  " U4SU R                  R                  " S0 UD60UD6nUR                  UR                  U05      I Sh  vN UR                     $  N7f)ay  Asynchronously query the vectorstore using the provided LLM.

Args:
    question: The question or prompt to query.
    llm: The language model to use. Must not be None.
    retriever_kwargs: Optional keyword arguments for the retriever.
    **kwargs: Additional keyword arguments forwarded to the chain.

Returns:
    The asynchronous result string from the RetrievalQA chain.
Nr&   r'   r   )r(   r   r)   r   r*   ainvoker,   r-   r.   s          r   aqueryVectorStoreIndexWrapper.aqueryC   s     $ ;.  &c**+1r++
&&33G6FG
 

 mmU__h$?@@%BRBRSS@s   A/B1B2Bc           	          Uc  Sn[        U5      eU=(       d    0 n[        R                  " U4SU R                  R                  " S0 UD60UD6nUR                  UR                  U05      $ )a|  Query the vectorstore and retrieve the answer along with sources.

Args:
    question: The question or prompt to query.
    llm: The language model to use. Must not be None.
    retriever_kwargs: Optional keyword arguments for the retriever.
    **kwargs: Additional keyword arguments forwarded to the chain.

Returns:
    A dictionary containing the answer and source documents.
r&   r'   r   )r(   r   r)   r   r*   r+   question_keyr.   s          r   query_with_sources*VectorStoreIndexWrapper.query_with_sourcesf   s    $ ;.  &c**+1r+;;
&&33G6FG
 

 ||U//:;;r   c           	         #    Uc  Sn[        U5      eU=(       d    0 n[        R                  " U4SU R                  R                  " S0 UD60UD6nUR                  UR                  U05      I Sh  vN $  N7f)a  Asynchronously query the vectorstore and retrieve the answer and sources.

Args:
    question: The question or prompt to query.
    llm: The language model to use. Must not be None.
    retriever_kwargs: Optional keyword arguments for the retriever.
    **kwargs: Additional keyword arguments forwarded to the chain.

Returns:
    A dictionary containing the answer and source documents.
Nr&   r'   r   )r(   r   r)   r   r*   r5   r9   r.   s          r   aquery_with_sources+VectorStoreIndexWrapper.aquery_with_sources   s     $ ;.  &c**+1r+;;
&&33G6FG
 

 ]]E$6$6#ABBBBs   A/A81A62A8r   )NN)__name__
__module____qualname____firstlineno____doc__r	   __annotations__r   model_configstrr   r   dictr   r2   r6   r:   r=   __static_attributes__r   r   r   r   r      sv   7 $L ,059	!K!K '(!K #4S>2	!K
 !K 
!KL ,059	!T!T '(!T #4S>2	!T
 !T 
!TL ,059	!<!< '(!< #4S>2	!<
 !< 
!<L ,059	!C!C '(!C #4S>2	!C
 !C 
!C !Cr   r   c                  |    SSK n  SSKJn  U R	                  SSS9  U$ ! [         a  nSn[        U5      UeSnAff = f)zGet the InMemoryVectorStore.r   N)InMemoryVectorStorezBPlease install langchain-community to use the InMemoryVectorStore.zUsing InMemoryVectorStore as the default vectorstore.This memory store won't persist data. You should explicitlyspecify a vectorstore when using VectorstoreIndexCreator   )
stacklevel)warnings)langchain_community.vectorstores.inmemoryrJ   ImportErrorwarn)rM   rJ   er0   s       r   _get_in_memory_vectorstorerR      sW    &Q MM	C 	     &R#A%&s    
;6;c                       \ rS rSr% Sr\" \S9r\\	   \
S'   \\
S'   \" \S9r\\
S'   \" \S9r\\
S'   \" SS	S
9rS\\   S\4S jrS\\   S\4S jrS\\   S\4S jrS\\   S\4S jrSrg)VectorstoreIndexCreator   zLogic for creating indexes.)default_factoryvectorstore_cls	embeddingtext_splittervectorstore_kwargsTr   r   loadersr   c                 x    / nU H"  nUR                  UR                  5       5        M$     U R                  U5      $ )zCreate a vectorstore index from a list of loaders.

Args:
    loaders: A list of `BaseLoader` instances to load documents.

Returns:
    A `VectorStoreIndexWrapper` containing the constructed vectorstore.
)extendloadfrom_documents)r/   r[   docsloaders       r   from_loaders$VectorstoreIndexCreator.from_loaders   s6     FKK& ""4((r   c           	         #    / nU H,  nUR                  UR                  5        Vs/ s Sh  vN oDPM     U R                  U5      I Sh  vN $  N"
 Os  snf sn5        M[   N7f)zAsynchronously create a vectorstore index from a list of loaders.

Args:
    loaders: A list of `BaseLoader` instances to load documents.

Returns:
    A `VectorStoreIndexWrapper` containing the constructed vectorstore.
N)r]   
alazy_loadafrom_documents)r/   r[   r`   ra   docs        r   afrom_loaders%VectorstoreIndexCreator.afrom_loaders   sV      FKKf.?.?.ABBs ))$/// CBC/sA   %A$A
AAAA
A$A"A$AA
A$	documentsc                     U R                   R                  U5      nU R                  R                  " UU R                  40 U R
                  D6n[        US9$ )zCreate a vectorstore index from a list of documents.

Args:
    documents: A list of `Document` objects.

Returns:
    A `VectorStoreIndexWrapper` containing the constructed vectorstore.
r   )rY   split_documentsrW   r_   rX   rZ   r   r/   rj   sub_docsr   s       r   r_   &VectorstoreIndexCreator.from_documents   sW     %%55i@**99NN
 %%

 ';??r   c                    #    U R                   R                  U5      nU R                  R                  " UU R                  40 U R
                  D6I Sh  vN n[        US9$  N7f)zAsynchronously create a vectorstore index from a list of documents.

Args:
    documents: A list of `Document` objects.

Returns:
    A `VectorStoreIndexWrapper` containing the constructed vectorstore.
Nrl   )rY   rm   rW   rf   rX   rZ   r   rn   s       r   rf   'VectorstoreIndexCreator.afrom_documents   sd      %%55i@ 00@@NN
 %%
 

 ';??
s   AA#A!A#r   N)r?   r@   rA   rB   rC   r   rR   rW   typer	   rD   r   r   rY   r   rG   rZ   r   rE   listr   r   rb   rh   r   r_   rf   rH   r   r   r   rT   rT      s    %).2*OT+&  "'8R"SM<S$T:: $L
)D$4 )9P )04
+; 0@W 0@X @;R @"@>@ 
!@r   rT   N)rC   typingr   r   langchain_core.document_loadersr   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.language_modelsr   langchain_core.vectorstoresr	   langchain_text_splittersr
   r   pydanticr   r   r   *langchain.chains.qa_with_sources.retrievalr   "langchain.chains.retrieval_qa.baser   r   r   rs   rR   rT   r   r   r   <module>r      si    -   6 - 0 < 3 Q 1 1 R :LL L
TCi TCnD$5 $N@i N@r   