
    Ng                         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rd dlmZmZ  ej        e          Z ed	d
d           G 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)sinceremovalalternative_importc                  P    e Zd Zdddddddddej        d
ddZd dZd!dZ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       
            t          |||||          }|| _        |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,   s                h/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/astradb.py__init__zAstraDBLoader.__init__"   s    F (%+"7
 
 
	 ##,77HH.%$(.B*#6       Iterator[Document]c              #    K   | j                             | j        | j        | j        d | j                  D ]O}t          |                     |          | j         j        j	        | j         j        j
        | j        d          V  Pd S N)r/   optionsr   sort
prefetched)r   r   r.   )page_contentmetadata)r.   paginated_findr/   r   r   r   r   r    r-   r   base_urlr!   )r0   docs     r1   	lazy_loadzAstraDBLoader.lazy_loadU   s      ?11;%) 2 
 
 	 	C !55c::!%!9!C$(O$<$E"&"6       	 	r3   List[Document]c                N   K   d |                                  2              d{V S )z Load data into Document objects.c                "   K   g | 3 d {V }|
6 S )N ).0r>   s     r1   
<listcomp>z'AstraDBLoader.aload.<locals>.<listcomp>h   s.      77777777c7777s   N)
alazy_load)r0   s    r1   aloadzAstraDBLoader.aloadf   s6      77T__%6%67777777777r3   AsyncIterator[Document]c               T  K   | j         j                            | j                   d {V }|                    | j        | j        | j        d | j                  2 3 d {V }t          | 
                    |          |j        j        |j        j        | j        d          W V  L6 d S r6   )r,   async_astra_dbr.   r!   r<   r/   r   r   r   r   r    r-   r   r=   )r0   async_collectionr>   s      r1   rF   zAstraDBLoader.alazy_loadj   s     !%!>!I!I "
 "
 
 
 
 
 
 
 *88;%) 9 
 
 	 	 	 	 	 	 	# !55c::!1!:!D$4$=$F"&"6        
 
 
s   B')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)   r4   )r)   r@   )r)   rH   )	__name__
__module____qualname__jsondumpsr2   r?   rG   rF   rC   r3   r1   r   r      s          $&*-18<#'48/315!59Z17 17 17 17 17 17f   "8 8 8 8     r3   r   )
__future__r   rO   loggingtypingr   r   r   r   r   r	   r
   r   langchain_core._api.deprecationr   langchain_core.documentsr   )langchain_community.document_loaders.baser   %langchain_community.utilities.astradbr   
astrapy.dbr   r   	getLoggerrL   loggerr   rC   r3   r1   <module>r[      sp   " " " " " "  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 7 6 6 6 6 6 - - - - - - @ @ @ @ @ @ E E E E E E 100000000		8	$	$ 
8  
[ [ [ [ [J [ [ 
[ [ [r3   