
    NgN                     4    d dl mZmZmZ  G d d          ZdS )    )AnyDictListc            
           e Zd ZdZddededdfdZedefd            Zi fd	ed
e	de
eeef                  fdZddZdS )	KuzuGraphu  Kùzu wrapper for graph operations.

    *Security note*: Make sure that the database connection uses credentials
        that are narrowly-scoped to only include necessary permissions.
        Failure to do so may result in data corruption or loss, since the calling
        code may attempt commands that would result in deletion, mutation
        of data if appropriately prompted or reading sensitive data if such
        data is present in the database.
        The best way to guard against such negative outcomes is to (as appropriate)
        limit the permissions granted to the credentials used with this tool.

        See https://python.langchain.com/docs/security for more information.
    kuzudbdatabasereturnNc                     	 dd l }n# t          $ r t          d          w xY w|| _        |                    | j                  | _        || _        |                                  d S )Nr   uS   Could not import Kùzu python package.Please install Kùzu with `pip install kuzu`.)r   ImportErrorr	   
Connectionconnr
   refresh_schema)selfr	   r
   r   s       a/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/graphs/kuzu_graph.py__init__zKuzuGraph.__init__   s    	KKKK 	 	 	@  	
 OODG,,	 s    !c                     | j         S )u(   Returns the schema of the Kùzu database)schema)r   s    r   
get_schemazKuzuGraph.get_schema    s     {    queryparamsc                 @   | j                             ||          }|                                }g }|                                rX|                                }|                    t          t          ||                               |                                X|S )u   Query Kùzu database)r   executeget_column_nameshas_nextget_nextappenddictzip)r   r   r   resultcolumn_namesreturn_listrows          r   r   zKuzuGraph.query%   s    ""5&11..00oo 	=//##CtCc$:$:;;<<< oo 	= r   c           
         g }| j                                         }|D ]}g |d}| j                             |          }|D ]}||         d         }d}||         d         dk    rGd||         v r||         d         D ]
}	|d|	z  z  }n#t          ||         d                   D ]}
|dz  }||z  }|d	                             ||f           |                    |           g }| j                                         }|D ]3}|                    d
|d         d|d         d|d         d           4g }|D ]}|d         }g |d}| j                             d| d          }|                                rU|                                }|d         }|d         }|d	                             ||f           |                                U|                    |           d| d| d| d| _	        dS )u,   Refreshes the Kùzu graph schema information)
propertieslabeltype 	dimensionr   shapez[%s]z[]r'   z(:srcz)-[:namez]->(:dst)zCALL table_info('z') RETURN *;      zNode properties: z
Relationships properties: z
Relationships: 
N)
r   _get_node_table_names_get_node_property_namesranger   _get_rel_table_namesr   r   r   r   )r   node_propertiesnode_table_names
table_namecurrent_table_schemar'   property_nameproperty_typelist_type_flagsirelationships
rel_tablestablerel_propertiesquery_resultr%   	prop_name	prop_types                      r   r   zKuzuGraph.refresh_schema/   s   9::<<* 	9 	9J24z#J#J ;;JGGJ!+   *= 9& A!#m,[9A==*]";;;!+M!:7!C 9 9A*fqj8NN9 "'z-'@'M!N!N 3 3A*d2NN/$\299"M2    ""#78888Y3355
 	 	E   (-eeFmmmU5\\\R     	8 	8EvJ24z#J#J 9,,<J<<< L '')) R"++--F	F	$\2999i:PQQQ	 '')) R
 !!"677770 0 0)70 0+0 0 0 	r   )r   )r   N)__name__
__module____qualname____doc__r   strr   propertyr   r    r   r   r   r    r   r   r   r      s          3 # 4     C    X 02  3  d4S>6J    0
 0
 0
 0
 0
 0
r   r   N)typingr   r   r   r   rN   r   r   <module>rP      s_    " " " " " " " " " "[
 [
 [
 [
 [
 [
 [
 [
 [
 [
r   