§
    eŠtj?*  ã                  ó<  — d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 ddl
mZ dd	lmZ  G d
„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Ze G d„ d¦  «        ¦   «         Z G d„ d¦  «        Z G d„ dej        ¦  «        ZdS )é    )ÚannotationsN)Ú	dataclass)ÚEnum)ÚOptional)ÚUnioné   )Útypes)ÚFloatc                  ó   — e Zd ZdZdZ	 dZdS )ÚVectorIndexTypez˜Enum representing different types of VECTOR index structures.

    See :ref:`oracle_vector_datatype` for background.

    .. versionadded:: 2.0.41

    ÚHNSWÚIVFN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © ó    ú_/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sqlalchemy/dialects/oracle/vector.pyr   r      s1   € € € € € ðð ð €Dðð €Cðð r   r   c                  ó(   — e Zd ZdZdZ	 dZ	 dZ	 dZdS )ÚVectorDistanceTypez˜Enum representing different types of vector distance metrics.

    See :ref:`oracle_vector_datatype` for background.

    .. versionadded:: 2.0.41

    Ú	EUCLIDEANÚDOTÚCOSINEÚ	MANHATTANN)r   r   r   r   r   r   r   r   r   r   r   r   r   )   sI   € € € € € ðð ð €Iðð €Cðð €Fðð €Iðð r   r   c                  ó(   — e Zd ZdZdZ	 dZ	 dZ	 dZdS )ÚVectorStorageFormatz�Enum representing the data format used to store vector components.

    See :ref:`oracle_vector_datatype` for background.

    .. versionadded:: 2.0.41

    ÚINT8ÚBINARYÚFLOAT32ÚFLOAT64N)r   r   r   r   r   r   r    r!   r   r   r   r   r   H   sI   € € € € € ðð ð €Dðð €Fðð €Gðð €Gðð r   r   c                  ó   — e Zd ZdZdZ	 dZdS )ÚVectorStorageTypez}Enum representing the vector type,

    See :ref:`oracle_vector_datatype` for background.

    .. versionadded:: 2.0.43

    ÚSPARSEÚDENSEN)r   r   r   r   r$   r%   r   r   r   r#   r#   c   s1   € € € € € ðð ð €Fðð €Eðð r   r#   c                  ó¢   — e Zd ZU dZej        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Zded<   dZded<   dZded<   d„ ZdS )ÚVectorIndexConfigaÆ  Define the configuration for Oracle VECTOR Index.

    See :ref:`oracle_vector_datatype` for background.

    .. versionadded:: 2.0.41

    :param index_type: Enum value from :class:`.VectorIndexType`
     Specifies the indexing method. For HNSW, this must be
     :attr:`.VectorIndexType.HNSW`.

    :param distance: Enum value from :class:`.VectorDistanceType`
     specifies the metric for calculating distance between VECTORS.

    :param accuracy: integer. Should be in the range 0 to 100
     Specifies the accuracy of the nearest neighbor search during
     query execution.

    :param parallel: integer. Specifies degree of parallelism.

    :param hnsw_neighbors: integer. Should be in the range 0 to
     2048. Specifies the number of nearest neighbors considered
     during the search. The attribute :attr:`.VectorIndexConfig.hnsw_neighbors`
     is HNSW index specific.

    :param hnsw_efconstruction: integer. Should be in the range 0
     to 65535. Controls the trade-off between indexing speed and
     recall quality during index construction. The attribute
     :attr:`.VectorIndexConfig.hnsw_efconstruction` is HNSW index
     specific.

    :param ivf_neighbor_partitions: integer. Should be in the range
     0 to 10,000,000. Specifies the number of partitions used to
     divide the dataset. The attribute
     :attr:`.VectorIndexConfig.ivf_neighbor_partitions` is IVF index
     specific.

    :param ivf_sample_per_partition: integer. Should be between 1
     and ``num_vectors / neighbor partitions``. Specifies the
     number of samples used per partition. The attribute
     :attr:`.VectorIndexConfig.ivf_sample_per_partition` is IVF index
     specific.

    :param ivf_min_vectors_per_partition: integer. From 0 (no trimming)
     to the total number of vectors (results in 1 partition). Specifies
     the minimum number of vectors per partition. The attribute
     :attr:`.VectorIndexConfig.ivf_min_vectors_per_partition`
     is IVF index specific.

    r   Ú
index_typeNzOptional[VectorDistanceType]ÚdistancezOptional[int]ÚaccuracyÚhnsw_neighborsÚhnsw_efconstructionÚivf_neighbor_partitionsÚivf_sample_per_partitionÚivf_min_vectors_per_partitionÚparallelc                óÜ   — t          | j        ¦  «        | _        dD ]O}t          | |¦  «        }|�;t          |t          ¦  «        s&t          |› dt          |¦  «        j        › �¦  «        ‚ŒPd S )N)r+   r,   r-   r.   r/   r0   r*   z$ must be an integer ifprovided, got )r   r(   ÚgetattrÚ
isinstanceÚintÚ	TypeErrorÚtyper   )ÚselfÚfieldÚvalues      r   Ú__post_init__zVectorIndexConfig.__post_init__¶   sŠ   € Ý)¨$¬/Ñ:Ô:ˆŒð
ð 	ð 	ˆEõ ˜D %Ñ(Ô(ˆEØÐ ­°E½3Ñ)?Ô)?Ð ÝØð <ð <Ý%)¨%¡[¤[Ô%9ð<ð <ñô ð øð	ð 	r   )r   r   r   r   r   r   r(   Ú__annotations__r)   r*   r+   r,   r-   r.   r/   r0   r:   r   r   r   r'   r'   x   sÒ   € € € € € € ð0ð 0ðd #2Ô"6€JÐ6Ð6Ð6Ñ6Ø-1€HÐ1Ð1Ð1Ñ1Ø"€HÐ"Ð"Ð"Ñ"Ø$(€NÐ(Ð(Ð(Ñ(Ø)-ÐÐ-Ð-Ð-Ñ-Ø-1ÐÐ1Ð1Ð1Ñ1Ø.2ÐÐ2Ð2Ð2Ñ2Ø37Ð!Ð7Ð7Ð7Ñ7Ø"€HÐ"Ð"Ð"Ñ"ðð ð ð ð r   r'   c                  ó    — e Zd ZdZd
d„Zd„ Zd	S )ÚSparseVectorz„
    Lightweight SQLAlchemy-side version of SparseVector.
    This mimics oracledb.SparseVector.

    .. versionadded:: 2.0.43

    Únum_dimensionsr4   ÚindicesúUnion[list, array.array]Úvaluesc                ó`  — t          |t          j        ¦  «        r|j        dk    rt          j        d|¦  «        }t          |t          j        ¦  «        st          j        d|¦  «        }t          |¦  «        t          |¦  «        k    rt	          d¦  «        ‚|| _        || _        || _        d S )NÚIÚdz.indices and values must be of the same length!)r3   ÚarrayÚtypecodeÚlenr5   r>   r?   rA   )r7   r>   r?   rA   s       r   Ú__init__zSparseVector.__init__Ò   s›   € õ ˜'¥5¤;Ñ/Ô/ð 	0°7Ô3CÀsÒ3JÐ3JÝ”k # wÑ/Ô/ˆGÝ˜&¥%¤+Ñ.Ô.ð 	.Ý”[  fÑ-Ô-ˆFÝˆw‰<Œ<�3˜v™;œ;Ò&Ð&ÝÐLÑMÔMÐMà,ˆÔØˆŒØˆŒˆˆr   c                ó\   — d| j         › dt          | j        ¦  «        › d| j        j        › d�S )NzSparseVector(num_dimensions=z, size=z, typecode=ú))r>   rG   r?   rA   rF   )r7   s    r   Ú__str__zSparseVector.__str__ã   sQ   € ðJ¨4Ô+>ð Jð JÝ˜œÑ%Ô%ðJð JØ26´+Ô2FðJð Jð Jð	
r   N)r>   r4   r?   r@   rA   r@   )r   r   r   r   rH   rK   r   r   r   r=   r=   É   sA   € € € € € ðð ðð ð ð ð"
ð 
ð 
ð 
ð 
r   r=   c                  ó    — e Zd ZdZdZd Zej        dej        dej	        dej
        diZdd„Zd	„ Zd
„ Zd„ Z G d„ dej        j        ¦  «        ZdS )ÚVECTORz“Oracle VECTOR datatype.

    For complete background on using this type, see
    :ref:`oracle_vector_datatype`.

    .. versionadded:: 2.0.41

    TÚbÚBÚfrD   Nc                ó  — |�$t          |t          ¦  «        st          d¦  «        ‚|�$t          |t          ¦  «        st          d¦  «        ‚|�$t          |t          ¦  «        st          d¦  «        ‚|| _        || _        || _        dS )aü  Construct a VECTOR.

        :param dim: integer. The dimension of the VECTOR datatype. This
         should be an integer value.

        :param storage_format: VectorStorageFormat. The VECTOR storage
         type format. This should be Enum values form
         :class:`.VectorStorageFormat` INT8, BINARY, FLOAT32, or FLOAT64.

        :param storage_type: VectorStorageType. The Vector storage type. This
         should be Enum values from :class:`.VectorStorageType` SPARSE or
         DENSE.

        Nzdim must be an integerz:storage_format must be an enum of type VectorStorageFormatz6storage_type must be an enum of type VectorStorageType)r3   r4   r5   r   r#   ÚdimÚstorage_formatÚstorage_type)r7   rR   rS   rT   s       r   rH   zVECTOR.__init__ÿ   s«   € ð  ˆ?¥:¨cµ3Ñ#7Ô#7ˆ?ÝÐ4Ñ5Ô5Ð5ØÐ%­jØÕ/ñ/
ô /
Ð%õ ØLñô ð ð Ð#­JØÕ+ñ-
ô -
Ð#õ ØHñô ð ð ˆŒØ,ˆÔØ(ˆÔÐÐr   c                ó   ‡ ‡— ˆˆ fd„}|S )z¬
        Converts a Python-side SparseVector instance into an
        oracledb.SparseVectormor a compatible array format before
        binding it to the database.
        c                ój  •— | �t          | t          j        ¦  «        r| S t          | t          ¦  «        r1‰                     ‰j        ¦  «        }t          j        || ¦  «        } | S t          | t
          ¦  «        r+‰j                             | j        | j        | j	        ¦  «        S t          d¦  «        ‚)Nz’
                    Invalid input for VECTOR: expected a list, an array.array,
                    or a SparseVector object.
                    )r3   rE   ÚlistÚ_array_typecoderS   r=   Údbapir>   r?   rA   r5   )r9   rF   Údialectr7   s     €€r   Úprocessz.VECTOR._cached_bind_processor.<locals>.process)  s´   ø€ Øˆ}¥
¨5µ%´+Ñ >Ô >ˆ}Ø�õ ˜E¥4Ñ(Ô(ð Ø×/Ò/°Ô0CÑDÔD�Ýœ H¨eÑ4Ô4�Ø�õ ˜E¥<Ñ0Ô0ð Ø”}×1Ò1ØÔ(Ø”MØ”Lñô ð õ  ð !ñ ô ð r   r   )r7   rZ   r[   s   `` r   Ú_cached_bind_processorzVECTOR._cached_bind_processor"  s)   øø€ ð	ð 	ð 	ð 	ð 	ð 	ð0 ˆr   c                ó   ‡— ˆfd„}|S )a  
        Converts database-returned values into Python-native representations.
        If the value is an oracledb.SparseVector, it is converted into the
        SQLAlchemy-side SparseVector class.
        If the value is a array.array, it is converted to a plain Python list.

        c                óØ   •— | €d S t          | t          j        ¦  «        rt          | ¦  «        S t          | ‰j        j        ¦  «        r!t	          | j        | j        | j        ¬¦  «        S d S )N)r>   r?   rA   )r3   rE   rW   rY   r=   r>   r?   rA   )r9   rZ   s    €r   r[   z0VECTOR._cached_result_processor.<locals>.processL  sw   ø€ Øˆ}Ø�tå˜E¥5¤;Ñ/Ô/ð 	Ý˜E‘{”{Ð"õ ˜E 7¤=Ô#=Ñ>Ô>ð Ý#Ø#(Ô#7Ø!œMØ œ<ðñ ô ð ðð r   r   )r7   rZ   Úcoltyper[   s    `  r   Ú_cached_result_processorzVECTOR._cached_result_processorC  s#   ø€ ð	ð 	ð 	ð 	ð 	ð ˆr   c                ó8   — | j                              |d¦  «        S )z7
        Map storage format to array typecode.
        rD   )Ú_typecode_mapÚget)r7   rF   s     r   rX   zVECTOR._array_typecode]  s   € ð Ô!×%Ò% h°Ñ4Ô4Ð4r   c                  ó    — e Zd Zd„ Zd„ Zd„ ZdS )úVECTOR.comparator_factoryc                óL   —  |                       dt          ¬¦  «        |¦  «        S )Nz<->©Úreturn_type©Úopr
   ©r7   Úothers     r   Úl2_distancez%VECTOR.comparator_factory.l2_distanced  ó"   € Ø4�4—7’7˜5­e�7Ñ4Ô4°UÑ;Ô;Ð;r   c                óL   —  |                       dt          ¬¦  «        |¦  «        S )Nz<#>rg   ri   rk   s     r   Úinner_productz'VECTOR.comparator_factory.inner_productg  rn   r   c                óL   —  |                       dt          ¬¦  «        |¦  «        S )Nz<=>rg   ri   rk   s     r   Úcosine_distancez)VECTOR.comparator_factory.cosine_distancej  rn   r   N)r   r   r   rm   rp   rr   r   r   r   Úcomparator_factoryre   c  sA   € € € € € ð	<ð 	<ð 	<ð	<ð 	<ð 	<ð	<ð 	<ð 	<ð 	<ð 	<r   rs   )NNN)r   r   r   r   Úcache_okÚ__visit_name__r   r   r   r    r!   rb   rH   r\   r`   rX   r	   Ú
TypeEngineÚ
Comparatorrs   r   r   r   rM   rM   ê   sÆ   € € € € € ðð ð €Hà€Nð 	Ô  #ØÔ" CØÔ# SØÔ# Sð	€Mð!)ð !)ð !)ð !)ðFð ð ðBð ð ð45ð 5ð 5ð<ð <ð <ð <ð <˜UÔ-Ô8ñ <ô <ð <ð <ð <r   rM   )Ú
__future__r   rE   Údataclassesr   Úenumr   Útypingr   r   Ú r	   r
   r   r   r   r#   r'   r=   rv   rM   r   r   r   ú<module>r}      sÝ  ðð #Ð "Ð "Ð "Ð "Ð "à €€€Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð �dñ ô ð ð&ð ð ð ð ˜ñ ô ð ð>ð ð ð ð ˜$ñ ô ð ð6ð ð ð ð ˜ñ ô ð ð* ðMð Mð Mð Mð Mñ Mô Mñ „ðMð`
ð 
ð 
ð 
ð 
ñ 
ô 
ð 
ðBA<ð A<ð A<ð A<ð A<ˆUÔñ A<ô A<ð A<ð A<ð A<r   