
    Ng                     v    d dl Z d dlmZmZmZ d dlmZ d dlmZ  e j	        e
          Z G d de          ZdS )    N)IteratorListOptional)Document)
BaseLoaderc                       e Zd ZdZddddededededeee                  d	eee                  d
dfdZd
ee	         fdZ
dS )CouchbaseLoaderaU  Load documents from `Couchbase`.

    Each document represents one row of the result. The `page_content_fields` are
    written into the `page_content`of the document. The `metadata_fields` are written
    into the `metadata` of the document. By default, all columns are written into
    the `page_content` and none into the `metadata`.
    N)page_content_fieldsmetadata_fieldsconnection_stringdb_usernamedb_passwordqueryr
   r   returnc                N   	 ddl m} ddlm} ddlm}	 n"# t          $ r}
t          d          |
d}
~
ww xY w|st          d          |st          d          |st          d	           |||          } || |	|                    | _        || _	        || _
        || _        dS )
a  Initialize Couchbase document loader.

        Args:
            connection_string (str): The connection string to the Couchbase cluster.
            db_username (str): The username to connect to the Couchbase cluster.
            db_password (str): The password to connect to the Couchbase cluster.
            query (str): The SQL++ query to execute.
            page_content_fields (Optional[List[str]]): The columns to write into the
                `page_content` field of the document. By default, all columns are
                written.
            metadata_fields (Optional[List[str]]): The columns to write into the
                `metadata` field of the document. By default, no columns are written.
        r   )PasswordAuthenticator)Cluster)ClusterOptionsz]Could not import couchbase package.Please install couchbase SDK with `pip install couchbase`.Nz#connection_string must be provided.zdb_username must be provided.zdb_password must be provided.)couchbase.authr   couchbase.clusterr   couchbase.optionsr   ImportError
ValueErrorclusterr   r
   r   )selfr   r   r   r   r
   r   r   r   r   eauths               j/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/couchbase.py__init__zCouchbaseLoader.__init__   s   .	<<<<<<1111118888888 	 	 	M  	
 ! 	DBCCC 	><=== 	><===$$
 

 !((9>>$;O;O P P
#6 .s    
4/4c              #     K   ddl m} | j                             |d                     | j                            | j                  }|D ]| j        }| j        s!t                                                    |sg }fd|D             }d	                    fd
                                D                       }t          ||          V  d	S )
z1Load Couchbase data into Document objects lazily.r   )	timedelta   )secondsc                 "    i | ]}||         S  r%   ).0fieldrows     r   
<dictcomp>z-CouchbaseLoader.lazy_load.<locals>.<dictcomp>Z   s    GGGes5zGGG    
c              3   4   K   | ]\  }}|v 	| d | V  dS )z: Nr%   )r&   kvr
   s      r   	<genexpr>z,CouchbaseLoader.lazy_load.<locals>.<genexpr>\   sE       ! ! $1q<O7O7O17O7O7O7O! !r*   )page_contentmetadataN)datetimer!   r   wait_until_readyr   r   r
   listkeysjoinitemsr   )r   r!   resultr   r1   documentr
   r(   s         @@r   	lazy_loadzCouchbaseLoader.lazy_loadG   s)     &&&&&& 	%%ii&:&:&:;;; ##DJ// 	G 	GC"2O"&":& 7&*388::&6&6#" %"$GGGGGGGHyy ! ! ! !(+		! ! !  H HEEEFFFF!	G 	Gr*   )__name__
__module____qualname____doc__strr   r   r   r   r   r:   r%   r*   r   r	   r	      s          48/31/ 1/ 1/1/ 1/ 	1/
 1/ &d3i01/ "$s),1/ 
1/ 1/ 1/ 1/fG8H- G G G G G Gr*   r	   )loggingtypingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   	getLoggerr;   loggerr	   r%   r*   r   <module>rF      s     + + + + + + + + + + - - - - - - @ @ @ @ @ @		8	$	$UG UG UG UG UGj UG UG UG UG UGr*   