
    *'&h                        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  G d de          Z G d	 d
e          Z G d de          Ze G d d                      Z G d de
j                  ZdS )    )annotationsN)	dataclass)Enum)Optional)Floatc                      e Zd ZdZdZ	 dZdS )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/reinick/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 )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   (   sI          I C F I r   r   c                  (    e Zd ZdZdZ	 dZ	 dZ	 dZdS )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   G   sI          D F G G 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: 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 ]O}t          | |          }|;t          |t                    s&t          | dt          |          j                   Pd S )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__   s    )$/::
 	 	E D%((E E3)?)?  < <%)%[[%9< <  	 	r   )r   r   r   r   r	   r
   r!   __annotations__r"   r#   r$   r%   r&   r'   r(   r)   r3   r   r   r   r    r    b   s         0 0d #2"6J6666-1H1111"H""""$(N(((()------11111.2222237!7777"H""""    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 )VECTORzOracle VECTOR datatype.

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

    .. versionadded:: 2.0.41

    TbBfdNc                    |$t          |t                    st          d          |$t          |t                    st          d          || _        || _        dS )aP  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 may be Enum values form
         :class:`.VectorStorageFormat` INT8, BINARY, FLOAT32, or FLOAT64.

        Nzdim must be an intergerz:storage_format must be an enum of type VectorStorageFormat)r,   r-   r.   r   dimstorage_format)r0   r<   r=   s      r   __init__zVECTOR.__init__   so     ?:c3#7#7?5666%j//
 /
% L   ,r   c                      fd}|S )zT
        Convert a list to a array.array before binding it to the database.
        c                    | t          | t          j                  r| S t          | t                    r1                    j                  }t          j        ||           } | S t          d          )Nz$VECTOR accepts list or array.array())r,   arraylist_array_typecoder=   r.   )r2   typecoder0   s     r   processz.VECTOR._cached_bind_processor.<locals>.process   so    }
5%+ > >} E4(( H//0CDDHe44   FGGGr   r   )r0   dialectrE   s   `  r   _cached_bind_processorzVECTOR._cached_bind_processor   s(    
	H 	H 	H 	H 	H r   c                    d }|S )zR
        Convert a array.array to list before binding it to the database.
        c                X    t          | t          j                  rt          |           S d S )N)r,   rA   rB   )r2   s    r   rE   z0VECTOR._cached_result_processor.<locals>.process   s,    %-- #E{{"# #r   r   )r0   rF   coltyperE   s       r   _cached_result_processorzVECTOR._cached_result_processor   s    
	# 	# 	# r   c                8    | j                             |d          S )z7
        Map storage format to array typecode.
        r:   )_typecode_mapget)r0   rD   s     r   rC   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   r0   others     r   l2_distancez%VECTOR.comparator_factory.l2_distance  "    44775e744U;;;r   c                L     |                      dt                    |          S )Nz<#>rR   rT   rV   s     r   inner_productz'VECTOR.comparator_factory.inner_product  rY   r   c                L     |                      dt                    |          S )Nz<=>rR   rT   rV   s     r   cosine_distancez)VECTOR.comparator_factory.cosine_distance	  rY   r   N)r   r   r   rX   r[   r]   r   r   r   comparator_factoryrP     sA        	< 	< 	<	< 	< 	<	< 	< 	< 	< 	<r   r^   )NN)r   r   r   r   cache_ok__visit_name__r   r   r   r   r   rM   r>   rG   rK   rC   types
TypeEngine
Comparatorr^   r   r   r   r6   r6      s          HN 	 #"C#S#S	M- - - -,  (	 	 	5 5 5< < < < <U-8 < < < < <r   r6   )
__future__r   rA   dataclassesr   enumr   typingr   sqlalchemy.typesra   r   r	   r   r   r    rb   r6   r   r   r   <module>ri      sx   # " " " " "  ! ! ! ! ! !                         " " " " " "    d   &       >    $   6 M M M M M M M M`W< W< W< W< W<U W< W< W< W< W<r   