Ë
    ðmxie*  ã                  ó  — 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y)é    )ÚannotationsN)Ú	dataclass)ÚEnum)ÚOptional)ÚUnioné   )Útypes)ÚFloatc                  ó   — e Zd ZdZdZ	 dZy)Ú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   © ó    úX/home/htdocs/ttos/venv/lib/python3.12/site-packages/sqlalchemy/dialects/oracle/vector.pyr   r      s   „ ñð €Dðð €Cðr   r   c                  ó&   — e Zd ZdZdZ	 dZ	 dZ	 dZy)Ú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   )   s7   „ ñð €Iðð €Cðð €Fðð €Iðr   r   c                  ó&   — e Zd ZdZdZ	 dZ	 dZ	 dZy)Ú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   s7   „ ñð €Dðð €Fðð €Gðð €Gðr   r   c                  ó   — e Zd ZdZdZ	 dZy)Ú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   s   „ ñð €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y)Ú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 ]D  }t        | |«      }|€Œt        |t        «      rŒ#t        |› dt        |«      j                  › �«      ‚ y )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__¶   sl   € Ü)¨$¯/©/Ó:ˆŒð
ò 	ˆEô ˜D %Ó(ˆEØÑ ¬°E¼3Õ)?ÜØ�gð %Ü%)¨%£[×%9Ñ%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   st   … ñ0ðd #2×"6Ñ"6€J�Ó6Ø-1€HÐ*Ó1Ø"€HˆmÓ"Ø$(€N�MÓ(Ø)-Ð˜Ó-Ø-1Ð˜]Ó1Ø.2Ð˜mÓ2Ø37Ð! =Ó7Ø"€HˆmÓ"ór   r'   c                  ó*   — e Zd ZdZ	 	 	 	 	 	 dd„Zd„ Zy)ÚSparseVectorz„
    Lightweight SQLAlchemy-side version of SparseVector.
    This mimics oracledb.SparseVector.

    .. versionadded:: 2.0.43

    c                óP  — t        |t        j                  «      r|j                  dk7  rt        j                  d|«      }t        |t        j                  «      st        j                  d|«      }t        |«      t        |«      k7  rt	        d«      ‚|| _        || _        || _        y )NÚIÚdz.indices and values must be of the same length!)r3   ÚarrayÚtypecodeÚlenr5   Únum_dimensionsÚindicesÚvalues)r7   rD   rE   rF   s       r   Ú__init__zSparseVector.__init__Ò   s   € ô ˜'¤5§;¡;Ô/°7×3CÑ3CÀsÒ3JÜ—k‘k # wÓ/ˆGÜ˜&¤%§+¡+Ô.Ü—[‘[  fÓ-ˆFÜˆw‹<œ3˜v›;Ò&ÜÐLÓMÐMà,ˆÔØˆŒØˆ�r   c                ó|   — d| j                   › dt        | j                  «      › d| j                  j                  › d�S )NzSparseVector(num_dimensions=z, size=z, typecode=ú))rD   rC   rE   rF   rB   )r7   s    r   Ú__str__zSparseVector.__str__ã   sC   € à*¨4×+>Ñ+>Ð*?ð @Ü˜Ÿ™Ó%Ð& k°$·+±+×2FÑ2FÐ1GÀqðJð	
r   N)rD   r4   rE   úUnion[list, array.array]rF   rK   )r   r   r   r   rG   rJ   r   r   r   r=   r=   É   s-   „ ñðàðð *ðð )ó	ó"
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y)ÚVECTORz“Oracle VECTOR datatype.

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

    .. versionadded:: 2.0.41

    TÚbÚBÚfr@   Nc                óÜ   — |�t        |t        «      st        d«      ‚|�t        |t        «      st        d«      ‚|�t        |t        «      st        d«      ‚|| _        || _        || _        y)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   rG   zVECTOR.__init__ÿ   sƒ   € ð  ˆ?¤:¨c´3Ô#7ÜÐ4Ó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                ór  •— | �t        | t        j                  «      r| S t        | t        «      r3‰j                  ‰j                  «      }t        j                  || «      } | S t        | t
        «      r;‰j                  j                  | j                  | j                  | j                  «      S t        d«      ‚)Nz’
                    Invalid input for VECTOR: expected a list, an array.array,
                    or a SparseVector object.
                    )r3   rA   ÚlistÚ_array_typecoderS   r=   ÚdbapirD   rE   rF   r5   )r9   rB   Údialectr7   s     €€r   Úprocessz.VECTOR._cached_bind_processor.<locals>.process)  sŸ   ø€ Øˆ}¤
¨5´%·+±+Ô >Ø�ô ˜E¤4Ô(Ø×/Ñ/°×0CÑ0CÓD�ÜŸ™ H¨eÓ4�Ø�ô ˜E¤<Ô0Ø—}‘}×1Ñ1Ø×(Ñ(Ø—M‘MØ—L‘Lóð ô  ðóð r   r   )r7   rZ   r[   s   `` r   Ú_cached_bind_processorzVECTOR._cached_bind_processor"  s   ù€ õ	ð4 ˆ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                óî   •— | €y t        | t        j                  «      rt        | «      S t        | ‰j                  j                  «      r,t	        | j
                  | j                  | j                  ¬«      S y )N)rD   rE   rF   )r3   rA   rW   rY   r=   rD   rE   rF   )r9   rZ   s    €r   r[   z0VECTOR._cached_result_processor.<locals>.processN  sb   ø€ Øˆ}Øä˜E¤5§;¡;Ô/Ü˜E“{Ð"ô ˜E 7§=¡=×#=Ñ#=Ô>Ü#Ø#(×#7Ñ#7Ø!ŸM™MØ Ÿ<™<ôð ð ?r   r   )r7   rZ   Úcoltyper[   s    `  r   Ú_cached_result_processorzVECTOR._cached_result_processorE  s   ø€ ô	ð ˆr   c                ó:   — | j                   j                  |d«      S )z7
        Map storage format to array typecode.
        r@   )Ú_typecode_mapÚget)r7   rB   s     r   rX   zVECTOR._array_typecode_  s   € ð ×!Ñ!×%Ñ% h°Ó4Ð4r   c                  ó   — e Zd Zd„ Zd„ Zd„ Zy)úVECTOR.comparator_factoryc                ó<   —  | j                  dt        ¬«      |«      S )Nz<->©Úreturn_type©Úopr
   ©r7   Úothers     r   Úl2_distancez%VECTOR.comparator_factory.l2_distancef  ó   € Ø4�4—7‘7˜5¬e�7Ó4°UÓ;Ð;r   c                ó<   —  | j                  dt        ¬«      |«      S )Nz<#>rg   ri   rk   s     r   Úinner_productz'VECTOR.comparator_factory.inner_producti  rn   r   c                ó<   —  | j                  dt        ¬«      |«      S )Nz<=>rg   ri   rk   s     r   Úcosine_distancez)VECTOR.comparator_factory.cosine_distancel  rn   r   N)r   r   r   rm   rp   rr   r   r   r   Úcomparator_factoryre   e  s   „ ò	<ò	<ó	<r   rs   )NNN)r   r   r   r   Úcache_okÚ__visit_name__r   r   r   r    r!   rb   rG   r\   r`   rX   r	   Ú
TypeEngineÚ
Comparatorrs   r   r   r   rM   rM   ê   sv   „ ñð €Hà€Nð 	× Ñ  #Ø×"Ñ" CØ×#Ñ# SØ×#Ñ# Sð	€Mó!)òF!òFò45ô<˜U×-Ñ-×8Ñ8õ <r   rM   )Ú
__future__r   rA   Ú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÷`
ñ 
ôBC<ˆU×Ñõ C<r   