o
    Zh                      @  s   d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlmZ erDd dlmZmZ eeZed	d
ddG dd deZdS )    )annotationsN)TYPE_CHECKINGAnyAsyncIteratorCallableDictIteratorListOptional)
deprecated)Document)
BaseLoader)_AstraDBEnvironment)AstraDBAsyncAstraDBz0.0.29z1.0zlangchain_astradb.AstraDBLoader)ZsinceZremovalZalternative_importc                   @  sN   e Zd Zdddddddddejd
d#ddZd$ddZd%ddZd&d!d"ZdS )'AstraDBLoaderNi  )
tokenapi_endpointastra_db_clientasync_astra_db_client	namespacefilter_criteria
projectionfind_optionsnb_prefetchedextraction_functioncollection_namestrr   Optional[str]r   r   Optional[AstraDB]r   Optional[AsyncAstraDB]r   r   Optional[Dict[str, Any]]r   r   r   intr   Callable[[Dict], str]returnNonec       
         C  sR   t |||||d}|| _|j|| _|| _|| _|| _|	pi | _|
| _|| _	dS )a  Load DataStax Astra DB documents.

        Args:
            collection_name: name of the Astra DB collection to use.
            token: API token for Astra DB usage.
            api_endpoint: full URL to the API endpoint,
                such as `https://<DB-ID>-us-east1.apps.astra.datastax.com`.
            astra_db_client: *alternative to token+api_endpoint*,
                you can pass an already-created 'astrapy.db.AstraDB' instance.
            async_astra_db_client: *alternative to token+api_endpoint*,
                you can pass an already-created 'astrapy.db.AsyncAstraDB' instance.
            namespace: namespace (aka keyspace) where the
                collection is. Defaults to the database's "default namespace".
            filter_criteria: Criteria to filter documents.
            projection: Specifies the fields to return.
            find_options: Additional options for the query.
            nb_prefetched: Max number of documents to pre-fetch. Defaults to 1000.
            extraction_function: Function applied to collection documents to create
                the `page_content` of the LangChain Document. Defaults to `json.dumps`.
        )r   r   r   r   r   N)
r   	astra_envastra_db
collectionr   filterr   r   r   r   )selfr   r   r   r   r   r   r   r   r   r   r   r&    r+   c/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/astradb.py__init__"   s   #

zAstraDBLoader.__init__Iterator[Document]c                 c  sT    | j j| j| j| jd | jdD ]}t| || j jj	| j jj
| jddV  qd S N)r)   optionsr   sortZ
prefetched)r   r   r(   )Zpage_contentmetadata)r(   paginated_findr)   r   r   r   r   r   r'   r   base_urlr   )r*   docr+   r+   r,   	lazy_loadU   s    

zAstraDBLoader.lazy_loadList[Document]c                   s   dd |   2 I dH S )z Load data into Document objects.c                   s   g | z3 d H W }|q6 S )Nr+   ).0r5   r+   r+   r,   
<listcomp>h   s    z'AstraDBLoader.aload.<locals>.<listcomp>N)
alazy_load)r*   r+   r+   r,   aloadf   s   zAstraDBLoader.aloadAsyncIterator[Document]c                 C sn   | j j| jI d H }|j| j| j| jd | jd2 z3 d H W }t	| 
||jj|jj| jddV  q6 d S r/   )r&   Zasync_astra_dbr(   r   r3   r)   r   r   r   r   r   r'   r   r4   )r*   Zasync_collectionr5   r+   r+   r,   r:   j   s&   

zAstraDBLoader.alazy_load)r   r   r   r   r   r   r   r   r   r    r   r   r   r!   r   r!   r   r!   r   r"   r   r#   r$   r%   )r$   r.   )r$   r7   )r$   r<   )	__name__
__module____qualname__jsondumpsr-   r6   r;   r:   r+   r+   r+   r,   r      s    

3
r   )
__future__r   r@   loggingtypingr   r   r   r   r   r   r	   r
   Zlangchain_core._api.deprecationr   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z%langchain_community.utilities.astradbr   Z
astrapy.dbr   r   	getLoggerr=   loggerr   r+   r+   r+   r,   <module>   s"    (
