
    3fi<&                         d 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 ddlmZmZ dd	lmZmZmZ dd
lmZ ddlmZ defdZ G d de      Zdee   fdZ G d de      Zy)z'Vectorstore stubs for the indexing api.    )Any)
BaseLoader)Document)
Embeddings)BaseLanguageModel)VectorStore)RecursiveCharacterTextSplitterTextSplitter)	BaseModel
ConfigDictField)RetrievalQAWithSourcesChain)RetrievalQAreturnc                      t        dd      S )z=Return the default text splitter used for chunking documents.i  r   )
chunk_sizechunk_overlap)r	        c/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/indexes/vectorstore.py_get_default_text_splitterr      s    )TKKr   c                      e Zd ZU dZeed<    edd      Z	 	 ddede	dz  d	e
eef   dz  d
edef
dZ	 	 ddede	dz  d	e
eef   dz  d
edef
dZ	 	 ddede	dz  d	e
eef   dz  d
ede
f
dZ	 	 ddede	dz  d	e
eef   dz  d
ede
f
dZy)VectorStoreIndexWrapperz/Wrapper around a `VectorStore` for easy access.vectorstoreTforbidarbitrary_types_allowedextraNquestionllmretriever_kwargskwargsr   c           	          |d}t        |      |xs i }t        j                  |fd | j                  j                  di |i|}|j                  |j                  |i      |j                     S )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
model = OpenAI(temperature=0)	retrieverr   )NotImplementedErrorr   from_chain_typer   as_retrieverinvoke	input_key
output_keyselfr   r    r!   r"   msgchains          r   queryzVectorStoreIndexWrapper.query"   s    $ ;0  &c**+1r++
3d&&33G6FG
 

 ||U__h789I9IJJr   c           	         K   |d}t        |      |xs i }t        j                  |fd | j                  j                  di |i|}|j                  |j                  |i       d{   |j                     S 7 w)a  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   aqueryzVectorStoreIndexWrapper.aqueryE   s     $ ;0  &c**+1r++
3d&&33G6FG
 

 mmU__h$?@@%BRBRSS@s   A(A>*A<+A>c           	          |d}t        |      |xs i }t        j                  |fd | j                  j                  di |i|}|j                  |j                  |i      S )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:
            `dict` containing the answer and source documents.
        r$   r%   r   )r&   r   r'   r   r(   r)   question_keyr,   s          r   query_with_sourcesz*VectorStoreIndexWrapper.query_with_sourcesh   s    $ ;0  &c**+1r+;;
3d&&33G6FG
 

 ||U//:;;r   c           	         K   |d}t        |      |xs i }t        j                  |fd | j                  j                  di |i|}|j                  |j                  |i       d{   S 7 w)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:
            `dict` containing the answer and source documents.
        Nr$   r%   r   )r&   r   r'   r   r(   r2   r5   r,   s          r   aquery_with_sourcesz+VectorStoreIndexWrapper.aquery_with_sources   s     $ ;0  &c**+1r+;;
3d&&33G6FG
 

 ]]E$6$6#ABBBBs   A(A1*A/+A1)NN)__name__
__module____qualname____doc__r   __annotations__r   model_configstrr   dictr   r0   r3   r6   r8   r   r   r   r   r      sl   9 $L )-26	!K!K %!K sCx.4/	!K
 !K 
!KL )-26	!T!T %!T sCx.4/	!T
 !T 
!TL )-26	!<!< %!< sCx.4/	!<
 !< 
!<L )-26	!C!C %!C sCx.4/	!C
 !C 
!Cr   r   c                      ddl } 	 ddlm} | j	                  dd       |S # t        $ r}d}t        |      |d}~ww xY w)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.inmemoryrB   ImportErrorwarn)rE   rB   er.   s       r   _get_in_memory_vectorstorerJ      sW    &Q MM	C 	     &R#A%&s   ! 	=8=c                       e Zd ZU dZ ee      Zee   e	d<   e
e	d<    ee      Zee	d<    ee      Zee	d<    edd	      Zd
ee   defdZd
ee   defdZdee   defdZdee   defdZy)VectorstoreIndexCreatorzLogic for creating indexes.)default_factoryvectorstore_cls	embeddingtext_splittervectorstore_kwargsTr   r   loadersr   c                 t    g }|D ]!  }|j                  |j                                # | j                  |      S )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-   rR   docsloaders       r   from_loadersz$VectorstoreIndexCreator.from_loaders   s;      	'FKK&	'""4((r   c           	         K   g }|D ],  }|j                  |j                         2 cg c3 d{   }| | j                  |       d{   S 7 !6 nc c}w c}       Y7 w)a  Asynchronously 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)rT   
alazy_loadafrom_documents)r-   rR   rW   rX   docs        r   afrom_loadersz%VectorstoreIndexCreator.afrom_loaders   sb       	DFKKf.?.?.ABBs	D))$/// CBBC/sA   %A"A
AAAA
A"
A A"AA
A"	documentsc                     | j                   j                  |      } | j                  j                  || j                  fi | j
                  }t        |      S )zCreate a `VectorStore` index from a list of documents.

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

        Returns:
            A `VectorStoreIndexWrapper` containing the constructed vectorstore.
        r   )rP   split_documentsrN   rV   rO   rQ   r   r-   r_   sub_docsr   s       r   rV   z&VectorstoreIndexCreator.from_documents   sY     %%55i@9d**99NN
 %%

 ';??r   c                    K   | j                   j                  |      } | j                  j                  || j                  fi | j
                   d{   }t        |      S 7 w)zAsynchronously create a `VectorStore` index from a list of documents.

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

        Returns:
            A `VectorStoreIndexWrapper` containing the constructed vectorstore.
        Nra   )rP   rb   rN   r\   rO   rQ   r   rc   s       r   r\   z'VectorstoreIndexCreator.afrom_documents   sg      %%55i@@D00@@NN
 %%
 

 ';??
s   AA&A$A&N)r9   r:   r;   r<   r   rJ   rN   typer   r=   r   r   rP   r
   r@   rQ   r   r>   listr   r   rY   r^   r   rV   r\   r   r   r   rL   rL      s    %).2*OT+&  "'8R"SM<S$T:: $L
)D$4 )9P )04
+; 0@W 0@X @;R @"@>@ 
!@r   rL   N)r<   typingr   langchain_core.document_loadersr   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.language_modelsr   langchain_core.vectorstoresr   langchain_text_splittersr	   r
   pydanticr   r   r   2langchain_classic.chains.qa_with_sources.retrievalr   *langchain_classic.chains.retrieval_qa.baser   r   r   rf   rJ   rL   r   r   r   <module>rr      sn    -  6 - 0 < 3 Q 1 1 CLL L
TCi TCnD$5 $N@i N@r   