HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langchain/indexes/__pycache__/vectorstore.cpython-310.pyc
o

���g/%�@s�dZddlmZmZmZmZmZddlmZddl	m
Z
ddlmZddl
mZddlmZddlmZmZdd	lmZmZmZdd
lmZddlmZdefd
d�ZGdd�de�Zdeefdd�ZGdd�de�ZdS)z'Vectorstore stubs for the indexing api.�)�Any�Dict�List�Optional�Type)�
BaseLoader)�Document)�
Embeddings)�BaseLanguageModel)�VectorStore)�RecursiveCharacterTextSplitter�TextSplitter)�	BaseModel�
ConfigDict�Field)�RetrievalQAWithSourcesChain)�RetrievalQA�returncCstddd�S)z=Return the default text splitter used for chunking documents.i�r)�
chunk_size�
chunk_overlap)r�rr�H/usr/local/lib/python3.10/dist-packages/langchain/indexes/vectorstore.py�_get_default_text_splittersrc@s�eZdZUdZeed<eddd�Z		ddede	e
d	e	eeefd
edef
dd
�Z
		ddede	e
d	e	eeefd
edef
dd�Z		ddede	e
d	e	eeefd
edef
dd�Z		ddede	e
d	e	eeefd
edef
dd�ZdS)�VectorStoreIndexWrapperz-Wrapper around a vectorstore for easy access.�vectorstoreT�forbid��arbitrary_types_allowed�extraN�question�llm�retriever_kwargs�kwargsrcKsR|durtd��|pi}tj|fd|jjdi|��i|��}|�|j|i�|jS)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.
        N��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��selfrr r!r"�chainrrr�query s����zVectorStoreIndexWrapper.queryc�sZ�|dur	td��|pi}tj|fd|jjdi|��i|��}|�|j|i�IdH|jS)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%rr&rr'�ainvoker)r*r+rrr�aquery@s�����zVectorStoreIndexWrapper.aquerycKsL|durtd��|pi}tj|fd|jjdi|��i|��}|�|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:
            A dictionary containing the answer and source documents.
        Nr#r$r)r%rr&rr'r(�question_keyr+rrr�query_with_sources`s����z*VectorStoreIndexWrapper.query_with_sourcesc�sT�|dur	td��|pi}tj|fd|jjdi|��i|��}|�|j|i�IdHS)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%rr&rr'r/r1r+rrr�aquery_with_sources�s�����z+VectorStoreIndexWrapper.aquery_with_sources)NN)�__name__�
__module__�__qualname__�__doc__r�__annotations__r�model_config�strrr
rrr.r0�dictr2r3rrrrrsv
������
�#�����
�#�����
�#������rcCs>ddl}zddlm}Wntytd��w|�d�|S)zGet the InMemoryVectorStore.rN)�InMemoryVectorStorezBPlease install langchain-community to use the InMemoryVectorStore.z�Using InMemoryVectorStore as the default vectorstore.This memory store won't persist data. You should explicitlyspecify a vectorstore when using VectorstoreIndexCreator)�warnings�)langchain_community.vectorstores.inmemoryr<�ImportError�warn)r=r<rrr�_get_in_memory_vectorstore�s���rAc@s�eZdZUdZeed�Zeee	d<e
e	d<eed�Ze
e	d<eed�Zee	d<eddd	�Zd
eedefdd
�Zd
eedefdd�Zdeedefdd�Zdeedefdd�ZdS)�VectorstoreIndexCreatorzLogic for creating indexes.)�default_factory�vectorstore_cls�	embedding�
text_splitter�vectorstore_kwargsTrr�loadersrcCs&g}|D]	}|�|���q|�|�S)z�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.
        )�extend�load�from_documents)r,rH�docs�loaderrrr�from_loaders�s	
z$VectorstoreIndexCreator.from_loadersc�sB�g}|D]}|��2z3dHW}|�|�q6q|�|�IdHS)aAsynchronously 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)�
alazy_load�append�afrom_documents)r,rHrLrM�docrrr�
afrom_loaders�s�	�z%VectorstoreIndexCreator.afrom_loaders�	documentscCs0|j�|�}|jj||jfi|j��}t|d�S)z�Create a vectorstore index from a list of documents.

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

        Returns:
            A `VectorStoreIndexWrapper` containing the constructed vectorstore.
        �r)rF�split_documentsrDrKrErGr�r,rT�sub_docsrrrrrK�s	��
z&VectorstoreIndexCreator.from_documentsc�s8�|j�|�}|jj||jfi|j��IdH}t|d�S)z�Asynchronously create a vectorstore index from a list of documents.

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

        Returns:
            A `VectorStoreIndexWrapper` containing the constructed vectorstore.
        NrU)rFrVrDrQrErGrrWrrrrQ�s���
z'VectorstoreIndexCreator.afrom_documentsN)r4r5r6r7rrArDrrr8r	rrFr
r;rGrr9rrrrNrSrrKrQrrrrrB�s(
����rBN) r7�typingrrrrr�langchain_core.document_loadersr�langchain_core.documentsr�langchain_core.embeddingsr	�langchain_core.language_modelsr
�langchain_core.vectorstoresr�langchain_text_splittersrr
�pydanticrrr�*langchain.chains.qa_with_sources.retrievalr�"langchain.chains.retrieval_qa.baserrrrArBrrrr�<module>s