
    Ngd                        d dl mZ d dlZd dlZd dlmZ d dlmZ d dl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mZ  ej                    ZddZ G d de          Z G d de          ZdS )    )annotationsN)sha1)Thread)AnyDictIterableListOptionalTupleUnion)Document)
Embeddings)VectorStore)BaseSettingsSettingsConfigDictsstrargsr   returnboolc                    |D ]	}|| vr dS 
dS )z
    Check if a string contains multiple substrings.
    Args:
        s: string to check.
        *args: substrings to check.

    Returns:
        True if all substrings are in the string, False otherwise.
    FT )r   r   as      g/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/vectorstores/clickhouse.pyhas_mul_sub_strr      s-       A::55 4    c                      e Zd ZU dZdZded<   dZded<   dZd	ed
<   dZd	ed<   dZ	ded<   dZ
d	ed<   ddgZded<   i Zded<   ddddddZded<   dZded<   d Zded!<   d"Zded#<   d-d'Z ed(d)d*d+,          ZdS ).ClickhouseSettingsa  `ClickHouse` client configuration.

    Attribute:
        host (str) : An URL to connect to MyScale backend.
                             Defaults to 'localhost'.
        port (int) : URL port to connect with HTTP. Defaults to 8443.
        username (str) : Username to login. Defaults to None.
        password (str) : Password to login. Defaults to None.
        secure (bool) : Connect to server over secure connection. Defaults to False.
        index_type (str): index type string.
        index_param (list): index build parameter.
        index_query_params(dict): index query parameters.
        database (str) : Database name to find the table. Defaults to 'default'.
        table (str) : Table name to operate on.
                      Defaults to 'vector_table'.
        metric (str) : Metric to compute distance,
                       supported are ('angular', 'euclidean', 'manhattan', 'hamming',
                       'dot'). Defaults to 'angular'.
                       https://github.com/spotify/annoy/blob/main/src/annoymodule.cc#L149-L169

        column_map (Dict) : Column type map to project column name onto langchain
                            semantics. Must have keys: `text`, `id`, `vector`,
                            must be same size to number of columns. For example:
                            .. code-block:: python

                                {
                                    'id': 'text_id',
                                    'uuid': 'global_unique_id'
                                    'embedding': 'text_embedding',
                                    'document': 'text_plain',
                                    'metadata': 'metadata_dictionary_in_json',
                                }

                            Defaults to identity map.
    	localhostr   hosti  intportNOptional[str]usernamepasswordFr   secureannoy
index_typez'L2Distance'd   zOptional[Union[List, Dict]]index_paramzDict[str, str]index_query_paramsiduuiddocument	embeddingmetadata)r,   r-   r.   r/   r0   
column_mapdefaultdatabase	langchaintableangularmetricitemr   r   c                "    t          | |          S N)getattr)selfr8   s     r   __getitem__zClickhouseSettings.__getitem___   s    tT"""r   z.envutf-8clickhouse_ignore)env_fileenv_file_encoding
env_prefixextra)r8   r   r   r   )__name__
__module____qualname____doc__r    __annotations__r"   r$   r%   r&   r(   r*   r+   r1   r3   r5   r7   r=   r   model_configr   r   r   r   r   !   sJ        " "H DD"H"""""H""""F 'J''''0>/DKDDDD)+++++  " "J     HEF# # # # &%! 	  LLLr   r   c                       e Zd ZdZ	 d8d9 fdZd:d;dZed<d            Zd=dZd>dZ	d?dZ
	 	 	 d@dAd$Ze	 	 	 	 dBdCd'            ZdDd(Z	 d8dEd-Z	 dFdGd2Z	 	 dFdHd3Z	 dFdId5ZdJd6ZedDd7            Z xZS )K
Clickhouseu  ClickHouse vector store integration.

    Setup:
        Install ``langchain_community`` and ``clickhouse-connect``:

        .. code-block:: bash

            pip install -qU langchain_community clickhouse-connect

    Key init args — indexing params:
        embedding: Embeddings
            Embedding function to use.

    Key init args — client params:
        config: Optional[ClickhouseSettings]
            ClickHouse client configuration.

    Instantiate:
        .. code-block:: python

            from langchain_community.vectorstores import Clickhouse, ClickhouseSettings
            from langchain_openai import OpenAIEmbeddings

            settings = ClickhouseSettings(table="clickhouse_example")
            vector_store = Clickhouse(embedding=OpenAIEmbeddings(), config=settings)

    Add Documents:
        .. code-block:: python

            from langchain_core.documents import Document

            document_1 = Document(page_content="foo", metadata={"baz": "bar"})
            document_2 = Document(page_content="thud", metadata={"bar": "baz"})
            document_3 = Document(page_content="i will be deleted :(")

            documents = [document_1, document_2, document_3]
            ids = ["1", "2", "3"]
            vector_store.add_documents(documents=documents, ids=ids)

    Delete Documents:
        .. code-block:: python

            vector_store.delete(ids=["3"])

    # TODO: Fill out example output.
    Search:
        .. code-block:: python

            results = vector_store.similarity_search(query="thud",k=1)
            for doc in results:
                print(f"* {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            # TODO: Example output

    # TODO: Fill out with relevant variables and example output.
    Search with filter:
        .. code-block:: python

            # TODO: Edit filter if needed
            results = vector_store.similarity_search(query="thud",k=1,filter="metadata.baz='bar'")
            for doc in results:
                print(f"* {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            # TODO: Example output

    # TODO: Fill out with example output.
    Search with score:
        .. code-block:: python

            results = vector_store.similarity_search_with_score(query="qux",k=1)
            for doc, score in results:
                print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            # TODO: Example output

    # TODO: Fill out with example output.
    Async:
        .. code-block:: python

            # add documents
            # await vector_store.aadd_documents(documents=documents, ids=ids)

            # delete documents
            # await vector_store.adelete(ids=["3"])

            # search
            # results = vector_store.asimilarity_search(query="thud",k=1)

            # search with score
            results = await vector_store.asimilarity_search_with_score(query="qux",k=1)
            for doc,score in results:
                print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            # TODO: Example output

    # TODO: Fill out with example output.
    Use as Retriever:
        .. code-block:: python

            retriever = vector_store.as_retriever(
                search_type="mmr",
                search_kwargs={"k": 1, "fetch_k": 2, "lambda_mult": 0.5},
            )
            retriever.invoke("thud")

        .. code-block:: python

            # TODO: Example output

    Nr/   r   configOptional[ClickhouseSettings]kwargsr   r   Nonec           	     `   	 ddl m} n# t          $ r t          d          w xY w	 ddlm} || _        n# t          $ r d | _        Y nw xY wt                                                       ||| _        nt                      | _        | j        sJ | j        j	        r| j        j
        sJ | j        j        r$| j        j        r| j        j        r| j        j        sJ dD ]}|| j        j        v sJ | j        j        dv sJ t          |                    d	                    }t#          | j        j        t&                    rI| j        j        r;d
                    d | j        j                                        D                       nUdnSt#          | j        j        t,                    r)d
                    d | j        j        D                       n| j        j        }|                     ||          | _        || _        d| _        d| _        || _        d| _         |d| j        j	        | j        j
        | j        j        | j        j        | j        j         d|| _!        	 | j!        "                    d           n?# tF          $ r2}	tH          %                    d| j!        j&         d           Y d}	~	nd}	~	ww xY w| j!        "                    d           | j        j'        r(| j!        "                    d| j        j'         d           | j!        "                    | j                   dS )aN  ClickHouse Wrapper to LangChain

        Args:
            embedding_function (Embeddings): embedding function to use
            config (ClickHouseSettings): Configuration to ClickHouse Client
            kwargs (any): Other keyword arguments will pass into
                [clickhouse-connect](https://docs.clickhouse.com/)
        r   )
get_clientzlCould not import clickhouse connect python package. Please install it with `pip install clickhouse-connect`.)tqdmc                    | S r:   r   )xrO   s     r   <lambda>z%Clickhouse.__init__.<locals>.<lambda>   s    Q r   N)r,   r/   r.   r0   r-   )r6   	euclidean	manhattanhammingdottest,c                &    g | ]\  }}d | d| d S )'=r   ).0kvs      r   
<listcomp>z'Clickhouse.__init__.<locals>.<listcomp>  s*    SSS41a,a,,!,,,SSSr    c                ,    g | ]}t          |          S r   )r   )r`   ps     r   rc   z'Clickhouse.__init__.<locals>.<listcomp>   s    BBBQ#a&&BBBr   \)rg   r^   ASC)r    r"   r$   r%   r&   z"SET allow_experimental_json_type=1zClickhouse version=z6 - There is no allow_experimental_json_type parameter.z$SET allow_experimental_object_type=1zSET allow_experimental_z_index=1r   )(clickhouse_connectrR   ImportErrorrS   pgbarsuper__init__rM   r   r    r"   r1   r3   r5   r7   lenembed_query
isinstancer*   r   joinitemsr	   _schemaschemadimBSmust_escapeembedding_function
dist_orderr$   r%   r&   clientcommand	Exceptionloggerdebugserver_versionr(   )r<   r/   rM   rO   rR   rS   ra   ru   index_params_	__class__s             r   rm   zClickhouse.__init__   s   	5555555 	 	 	K  	
	/!!!!!!DJJ 	/ 	/ 	/..DJJJ	/ 	 DKK,..DK{{4DK$4444K"	
$	
 !	
 "		
 	
 	
 E 	/ 	/A......{! &
 
 
 
 
 )''//00 $+1488
;*SS4;3J3P3P3R3RSSSTTTR
 dk5t<<-BB$+*ABBBCCC[, 	 ll355&"+ !j 
!![)[);%
 
 
 
	K DEEEE 	 	 	LLFdk&@ F F F       	 	BCCC;! 	KJ$+*@JJJ   	DK(((((s/   
 $6 A
A'J 
J>(J99J>rd   ru   r!   r   r#   r   c                   | j         j        rd| j         j         d| j         j         d| j         j        d          d| j         j        d          d| j         j        d          d| j         j        d	          d
| j         j        d          d| j         j        d          d| d| j         j        d          d| j         j         d| dS d| j         j         d| j         j         d| j         j        d          d| j         j        d          d| j         j        d          d| j         j        d	          d| j         j        d          d| j         j        d          d| dS )a  Create table schema
        :param dim: dimension of embeddings
        :param index_params: parameters used for index

        This function returns a `CREATE TABLE` statement based on the value of
        `self.config.index_type`.
        If an index type is specified that index will be created, otherwise
        no index will be created.
        In the case of there being no index, a linear scan will be performed
        when the embedding field is queried.
        z#        CREATE TABLE IF NOT EXISTS .z(
            r,   z Nullable(String),
            r.   r/   z Array(Float32),
            r0   z JSON,
            r-   zb UUID DEFAULT generateUUIDv4(),
            CONSTRAINT cons_vec_len CHECK length(
                z) = z,
            INDEX vec_idx z TYPE         (zg) GRANULARITY 1000
        ) ENGINE = MergeTree ORDER BY uuid SETTINGS index_granularity = 8192        z+                CREATE TABLE IF NOT EXISTS z(
                    z' Nullable(String),
                    z% Array(Float32),
                    z JSON,
                    zY UUID DEFAULT generateUUIDv4(),
                    CONSTRAINT cons_vec_len CHECK length(zD
                ) ENGINE = MergeTree ORDER BY uuid
                )rM   r(   r3   r5   r1   )r<   ru   r   s      r   rs   zClickhouse._schemaH  s    ;! 	$(K$8 ;?;;L [#D)  [#J/  [#K0	 
 [#J/  [#F+  '4  ;>   ;1+>  
	  #/   
,0K,@
 
CG;CT
 
[+D1
 
 [+J7
 
 [+K8	
 

 [+J7
 
 [+F3
 
 .{;
 
 BE
 
 
 
r   c                    | j         S )a  Provides access to the embedding mechanism used by the Clickhouse instance.

        This property allows direct access to the embedding function or model being
        used by the Clickhouse instance to convert text documents into embedding vectors
        for vector similarity search.

        Returns:
            The `Embeddings` instance associated with this Clickhouse instance.
        )rx   r<   s    r   
embeddingszClickhouse.embeddingsp  s     &&r   valuec                F     d                      fd|D                       S )a  Escape special characters in a string for Clickhouse SQL queries.

        This method is used internally to prepare strings for safe insertion
        into SQL queries by escaping special characters that might otherwise
        interfere with the query syntax.

        Args:
            value: The string to be escaped.

        Returns:
            The escaped string, safe for insertion into SQL queries.
        rd   c              3  D   K   | ]}|j         v rj         | n|V  d S r:   )rw   rv   )r`   cr<   s     r   	<genexpr>z(Clickhouse.escape_str.<locals>.<genexpr>  s>      VV1!t/?*?*?$'1QVVVVVVr   )rq   )r<   r   s   ` r   
escape_strzClickhouse.escape_str}  s-     wwVVVVPUVVVVVVr   transacr   column_namesIterable[str]c           
          d                     |          }g }|D ]<}d                      fd|D                       }|                    d| d           =d j        j         d j        j         d| dd                     |           d	}|S )	a  Construct an SQL query for inserting data into the Clickhouse database.

        This method formats and constructs an SQL `INSERT` query string using the
        provided transaction data and column names. It is utilized internally during
        the process of batch insertion of documents and their embeddings into the
        database.

        Args:
            transac: iterable of tuples, representing a row of data to be inserted.
            column_names: iterable of strings representing the names of the columns
                into which data will be inserted.

        Returns:
            A string containing the constructed SQL `INSERT` query.
        r\   c                \    g | ](}d                      t          |                     d )S )r^   )r   r   )r`   _nr<   s     r   rc   z0Clickhouse._build_insert_sql.<locals>.<listcomp>  s7    FFFb9dooc"gg66999FFFr   r   )z8
                INSERT INTO TABLE 
                    r   z))
                VALUES
                z
                )rq   appendrM   r3   r5   )r<   r   r   ks_datani_strs   `      r   _build_insert_sqlzClickhouse._build_insert_sql  s      XXl## 	# 	#AFFFFAFFFGGALLQ""""[) ,0K,= @B  %	   r   c                f    |                      ||          }| j                            |           dS )a/  Execute an SQL query to insert data into the Clickhouse database.

        This method performs the actual insertion of data into the database by
        executing the SQL query constructed by `_build_insert_sql`. It's a critical
        step in adding new documents and their associated data into the vector store.

        Args:
            transac:iterable of tuples, representing a row of data to be inserted.
            column_names: An iterable of strings representing the names of the columns
                into which data will be inserted.
        N)r   rz   r{   )r<   r   r   _insert_querys       r   _insertzClickhouse._insert  s5     ..wEEM*****r       texts	metadatasOptional[List[dict]]
batch_sizeidsOptional[Iterable[str]]	List[str]c           
        |pd |D             }| j         j        }g }|d         ||d         ||d         | j                            t	          |                    i}|pd |D             }t          t          j        |          ||d         <   t          t          |          t          |          z
            dk    sJ t          |                                 \  }	}
	 d}|                     t          |
 d	t          |          
          D ]}t          ||	                    | j         j        d                                      | j        k    sJ |                    |           t          |          |k    rD|r|                                 t#          | j        ||	g          }|                                 g }t          |          dk    r,|r|                                 |                     ||	           d |D             S # t(          $ rG}t*                              dt/          |           dt1          |           d           g cY d}~S d}~ww xY w)a  Insert more texts through the embeddings and add to the VectorStore.

        Args:
            texts: Iterable of strings to add to the VectorStore.
            ids: Optional list of ids to associate with the texts.
            batch_size: Batch size of insertion
            metadata: Optional column data to be inserted

        Returns:
            List of ids from adding the texts into the VectorStore.

        c                v    g | ]6}t          |                    d                                                     7S )r>   )r   encode	hexdigest)r`   ts     r   rc   z(Clickhouse.add_texts.<locals>.<listcomp>  s8    IIIad188G,,--7799IIIr   r,   r.   r/   c                    g | ]}i S r   r   )r`   r   s     r   rc   z(Clickhouse.add_texts.<locals>.<listcomp>  s    !4!4!4"!4!4!4r   r0   r   NzInserting data...)desctotal)targetr   c                    g | ]}|S r   r   )r`   is     r   rc   z(Clickhouse.add_texts.<locals>.<listcomp>  s    ###!A###r   	[91m[1m
[0m [95m[0m)rM   r1   rx   embed_documentslistmapjsondumpsrn   setziprr   rk   indexru   r   rq   r   r   startr|   r}   errortyper   )r<   r   r   r   r   rO   colmap_r   r   keysvaluesr   rb   es                 r   	add_textszClickhouse.add_texts  sj   * III5III+(DM3JK $"9"I"I$u++"V"V

 4!4!4e!4!4!4	,/
I,F,FWZ()3w<<#l"3"33449999L..001f	AZZV#6c)nn     ! ! $**T[%;K%HIIJKKtxWWWWq!!!w<<:-- !dl'4IIIAGGIII G7||a FFHHHWd+++##s#### 	 	 	LLS477SSCFFSSSTTTIIIIII	s   D*H	 	
I<IIIOptional[List[Dict[Any, Any]]]text_idsc                L     | ||fi |}|                     ||||           |S )ar  Create ClickHouse wrapper with existing texts

        Args:
            embedding_function (Embeddings): Function to extract text embedding
            texts (Iterable[str]): List or tuple of strings to be added
            config (ClickHouseSettings, Optional): ClickHouse configuration
            text_ids (Optional[Iterable], optional): IDs for the texts.
                                                     Defaults to None.
            batch_size (int, optional): Batchsize when transmitting data to ClickHouse.
                                        Defaults to 32.
            metadata (List[dict], optional): metadata to texts. Defaults to None.
            Other keyword arguments will pass into
                [clickhouse-connect](https://clickhouse.com/docs/en/integrations/python#clickhouse-connect-driver-api)
        Returns:
            ClickHouse Index
        )r   r   r   )r   )	clsr   r/   r   rM   r   r   rO   ctxs	            r   
from_textszClickhouse.from_texts  s<    6 c)V..v..ejIVVV
r   c                ~   d| j         j         d| j         j         d}|| j         j         d| j         j         dz  }|d| j         j         dz  }|dz  }| j                            d	| j         j         d| j         j                                                   D ]}|d
|d         dd|d         ddz  }|dz  }|S )zText representation for ClickHouse Vector Store, prints backends, username
            and schemas. Easy to use with `str(ClickHouse())`

        Returns:
            repr: string to show connection info and data schema
        z	[92m[1mr   z @ :z[0m

z[1musername: z[0m

Table Schema:
z4---------------------------------------------------
zDESC z|[94mname24sz
[0m|[96mr   z[0m|
)	rM   r3   r5   r    r"   r$   rz   querynamed_results)r<   _reprrs      r   __repr__zClickhouse.__repr__  s     P$+"6OO9JOOODK$DDt{'7DDDDUT[%9UUUU "">DK(>>4;+<>>
 

-//	 	A TAfITTT1V9TTTTEE 	 r   q_embList[float]topk	where_strc                   d                     t          t          |                    }|rd| }nd}g }| j        j        r:| j        j        D ]-}|                    d| d| j        j        |                     .d| j        j        d          d| j        j        d	          d
| j        j         d| j        j         d| d| j        j        d          d| d| j	         d| dd                     |           d}|S )a  Construct an SQL query for performing a similarity search.

        This internal method generates an SQL query for finding the top-k most similar
        vectors in the database to a given query vector.It allows for optional filtering
        conditions to be applied via a WHERE clause.

        Args:
            q_emb: The query vector as a list of floats.
            topk: The number of top similar items to retrieve.
            where_str: opt str representing additional WHERE conditions for the query
                Defaults to None.

        Returns:
            A string containing the SQL query for the similarity search.
        r\   z	PREWHERE rd   zSETTING r_   z
            SELECT r.   z, 
                r0   z, dist
            FROM r   z
            z!
            ORDER BY L2Distance(r/   z, [z]) 
                AS dist z
            LIMIT  )
rq   r   r   rM   r+   r   r1   r3   r5   ry   )r<   r   r   r   	q_emb_strsettings_strsra   q_strs           r   _build_query_sqlzClickhouse._build_query_sql$  sr   $ HHSe__--	 	/I//III;) 	Y[3 Y Y$$%W%W%WDK4RST4U%W%WXXXXK*:6 '
3  +&  *.):  	 
 "&!7!D 
 JS      ((=11   r      r   ra   List[Document]c                R     | j         | j                            |          ||fi |S )a  Perform a similarity search with ClickHouse

        Args:
            query (str): query string
            k (int, optional): Top K neighbors to retrieve. Defaults to 4.
            where_str (Optional[str], optional): where condition string.
                                                 Defaults to None.

            NOTE: Please do not let end-user to fill this and always be aware
                  of SQL injection. When dealing with metadatas, remember to
                  use `{self.metadata_column}.attribute` instead of `attribute`
                  alone. The default name for it is `metadata`.

        Returns:
            List[Document]: List of Documents
        )similarity_search_by_vectorrx   ro   )r<   r   ra   r   rO   s        r   similarity_searchzClickhouse.similarity_searchK  s@    & 0t/#//669
 
HN
 
 	
r   c           	     L                          |||          }	  fd j                            |                                          D             S # t          $ rG}t
                              dt          |           dt          |           d           g cY d}~S d}~ww xY w)a  Perform a similarity search with ClickHouse by vectors

        Args:
            query (str): query string
            k (int, optional): Top K neighbors to retrieve. Defaults to 4.
            where_str (Optional[str], optional): where condition string.
                                                 Defaults to None.

            NOTE: Please do not let end-user to fill this and always be aware
                  of SQL injection. When dealing with metadatas, remember to
                  use `{self.metadata_column}.attribute` instead of `attribute`
                  alone. The default name for it is `metadata`.

        Returns:
            List[Document]: List of documents
        c                    g | ]?}t          |j        j        d                   |j        j        d                            @S )r.   r0   page_contentr0   r   rM   r1   r`   r   r<   s     r   rc   z:Clickhouse.similarity_search_by_vector.<locals>.<listcomp>{  s^       
 	 !"4;#9*#E!Ft{5jAB    r   r   r   r   N)	r   rz   r   r   r|   r}   r   r   r   )r<   r/   ra   r   rO   r   r   s   `      r   r   z&Clickhouse.similarity_search_by_vectorb  s    . %%iI>>
	   
 **511??AA     	 	 	LLS477SSCFFSSSTTTIIIIII	s   7A 
B#<BB#B#List[Tuple[Document, float]]c           	     |                           j                            |          ||          }	  fd j                            |                                          D             S # t          $ rG}t                              dt          |           dt          |           d           g cY d}~S d}~ww xY w)a  Perform a similarity search with ClickHouse

        Args:
            query (str): query string
            k (int, optional): Top K neighbors to retrieve. Defaults to 4.
            where_str (Optional[str], optional): where condition string.
                                                 Defaults to None.

            NOTE: Please do not let end-user to fill this and always be aware
                  of SQL injection. When dealing with metadatas, remember to
                  use `{self.metadata_column}.attribute` instead of `attribute`
                  alone. The default name for it is `metadata`.

        Returns:
            List[Document]: List of (Document, similarity)
        c                    g | ]G}t          |j        j        d                   |j        j        d                            |d         fHS )r.   r0   r   distr   r   s     r   rc   zFClickhouse.similarity_search_with_relevance_scores.<locals>.<listcomp>  sl     	 	 	  %&t{'=j'I%J!"4;#9*#E!F   fI	 	 	r   r   r   r   N)r   rx   ro   rz   r   r   r|   r}   r   r   r   )r<   r   ra   r   rO   r   r   s   `      r   'similarity_search_with_relevance_scoresz2Clickhouse.similarity_search_with_relevance_scores  s    & %%#//669
 
		 	 	 	 **511??AA	 	 	 	  	 	 	LLS477SSCFFSSSTTTIIIIII	s   7A* *
B;4<B60B;6B;c                n    | j                             d| j        j         d| j        j                    dS )z,
        Helper function: Drop data
        zDROP TABLE IF EXISTS r   N)rz   r{   rM   r3   r5   r   s    r   dropzClickhouse.drop  sE     	NDK$8NN4;;LNN	
 	
 	
 	
 	
r   c                &    | j         j        d         S )Nr0   )rM   r1   r   s    r   metadata_columnzClickhouse.metadata_column  s    {%j11r   r:   )r/   r   rM   rN   rO   r   r   rP   )rd   )ru   r!   r   r#   r   r   )r   r   )r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   rP   )Nr   N)r   r   r   r   r   r!   r   r   rO   r   r   r   )NNNr   )r   r   r/   r   r   r   rM   rN   r   r   r   r!   rO   r   r   rL   )r   r   )r   r   r   r!   r   r#   r   r   )r   N)
r   r   ra   r!   r   r#   rO   r   r   r   )
r/   r   ra   r!   r   r#   rO   r   r   r   )
r   r   ra   r!   r   r#   rO   r   r   r   )r   rP   )rE   rF   rG   rH   rm   rs   propertyr   r   r   r   r   classmethodr   r   r   r   r   r   r   r   __classcell__)r   s   @r   rL   rL   j   s       u ut 04d) d) d) d) d) d) d)L& & & & &P 
' 
' 
' X
'W W W W   :+ + + +$ +/'+7 7 7 7 7r 
 59/3,0    [<   * IM% % % % %P BF
 
 
 
 
4 #'	" " " " "J BF# # # # #J
 
 
 
 2 2 2 X2 2 2 2 2r   rL   )r   r   r   r   r   r   )
__future__r   r   logginghashlibr   	threadingr   typingr   r   r   r	   r
   r   r   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.vectorstoresr   pydantic_settingsr   r   	getLoggerr}   r   r   rL   r   r   r   <module>r      sf   " " " " " "               D D D D D D D D D D D D D D D D D D - - - - - - 0 0 0 0 0 0 3 3 3 3 3 3 > > > > > > > >				    F F F F F F F FRK	2 K	2 K	2 K	2 K	2 K	2 K	2 K	2 K	2 K	2r   