a
    bg                      @  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rd 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                   @  st   e Zd Zdddddddddejd
dddddddddd	d
ddddZddddZddddZd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strzOptional[str]zOptional[AstraDB]zOptional[AsyncAstraDB]zOptional[Dict[str, Any]]intzCallable[[Dict], str]None)collection_namer   r   r   r   r   r   r   r   r   r   returnc       
         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&   z/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/astradb.py__init__"   s    #
zAstraDBLoader.__init__zIterator[Document])r    c                 c  sR   | 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_loadz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&   ).0r/   r&   r&   r'   
<listcomp>h       z'AstraDBLoader.aload.<locals>.<listcomp>N)
alazy_load)r%   r&   r&   r'   aloadf   s    zAstraDBLoader.aloadzAsyncIterator[Document]c                 C sl   | j j| jI d H }|j| j| j| jd | jd2 z23 d H W }t	| 
||jj|jj| jddV  q26 d S r)   )r!   Zasync_astra_dbr#   r   r-   r$   r   r   r   r   r   r"   r   r.   )r%   Zasync_collectionr/   r&   r&   r'   r4   j   s"    
zAstraDBLoader.alazy_load)	__name__
__module____qualname__jsondumpsr(   r0   r5   r4   r&   r&   r&   r'   r      s   
(3r   )
__future__r   r9   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   	getLoggerr6   loggerr   r&   r&   r&   r'   <module>   s    (
