
    hz*                       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)Floatc                      e Zd ZdZdZ	 dZy)VectorIndexTypezEnum 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/eduruby.in/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)VectorDistanceTypezEnum 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)VectorStorageFormatzEnum 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: interger. 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: interger. 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-   r.   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 E3)?g %%)%[%9%9$:< 	r   )r   r   r   r   r
   r   r&   __annotations__r'   r(   r)   r*   r+   r,   r-   r.   r8   r   r   r   r%   r%   x   st    0d #2"6"6J6-1H*1"Hm"$(NM()---1]1.2m237!=7"Hm"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!)r1   arraytypecodelenr3   num_dimensionsindicesvalues)r5   rB   rC   rD   s       r   __init__zSparseVector.__init__   s     '5;;/73C3Cs3Jkk#w/G&%++.[[f-Fw<3v;&LMM,r   c                |    d| j                    dt        | j                         d| j                  j                   dS )NzSparseVector(num_dimensions=z, size=z, typecode=))rB   rA   rC   rD   r@   )r5   s    r   __str__zSparseVector.__str__   sC    *4+>+>*? @%&k$++2F2F1GqJ	
r   N)rB   r2   rC   Union[list, array.array]rD   rI   )r   r   r   r   rE   rH   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)VECTORzOracle 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 intergerz:storage_format must be an enum of type VectorStorageFormatz6storage_type must be an enum of type VectorStorageType)r1   r2   r3   r   r!   dimstorage_formatstorage_type)r5   rP   rQ   rR   s       r   rE   zVECTOR.__init__   s      ?:c3#7566%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.
                    )r1   r?   list_array_typecoderQ   r;   dbapirB   rC   rD   r3   )r7   r@   dialectr5   s     r   processz.VECTOR._cached_bind_processor.<locals>.process(  s    }
5%++ > E4(//0C0CDHe4 E<0}}11((MMLL    r   r   )r5   rX   rY   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)rB   rC   rD   )r1   r?   rU   rW   r;   rB   rC   rD   )r7   rX   s    r   rY   z0VECTOR._cached_result_processor.<locals>.processM  sb    }E5;;/E{" E7==#=#=>##(#7#7!MM <<  ?r   r   )r5   rX   coltyperY   s    `  r   _cached_result_processorzVECTOR._cached_result_processorD  s    	 r   c                :    | j                   j                  |d      S )z7
        Map storage format to array typecode.
        r>   )_typecode_mapget)r5   r@   s     r   rV   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   r5   others     r   l2_distancez%VECTOR.comparator_factory.l2_distancee      44775e74U;;r   c                <     | j                  dt              |      S )Nz<#>re   rg   ri   s     r   inner_productz'VECTOR.comparator_factory.inner_producth  rl   r   c                <     | j                  dt              |      S )Nz<=>re   rg   ri   s     r   cosine_distancez)VECTOR.comparator_factory.cosine_distancek  rl   r   N)r   r   r   rk   rn   rp   r   r   r   comparator_factoryrc   d  s    	<	<	<r   rq   )NNN)r   r   r   r   cache_ok__visit_name__r   r   r   r   r   r`   rE   rZ   r^   rV   types
TypeEngine
Comparatorrq   r   r   r   rK   rK      sv     HN 	  #""C##S##S	M!)F!F45<U--88 <r   rK   )
__future__r   r?   dataclassesr   enumr   typingr   r   sqlalchemy.typesrt   r   r
   r   r   r!   r%   r;   ru   rK   r   r   r   <module>r|      s    #  !      "d & >$ 6 * M M M`
 
BB<U B<r   