
    Bhz*                       S SK Jr  S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SK
Jr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r\ " S S5      5       r " S S5      r " S S\R&                  5      rg)    )annotationsN)	dataclass)Enum)Optional)Union)Floatc                  "    \ rS rSrSrSr SrSrg)VectorIndexType   zEnum representing different types of VECTOR index structures.

See :ref:`oracle_vector_datatype` for background.

.. versionadded:: 2.0.41

HNSWIVF N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r       d/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sqlalchemy/dialects/oracle/vector.pyr
   r
      s     D Cr   r
   c                  .    \ rS rSrSrSr Sr Sr SrSr	g)	VectorDistanceType)   zEnum representing different types of vector distance metrics.

See :ref:`oracle_vector_datatype` for background.

.. versionadded:: 2.0.41

	EUCLIDEANDOTCOSINE	MANHATTANr   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )   s7     I C F Ir   r   c                  .    \ rS rSrSrSr Sr Sr SrSr	g)	VectorStorageFormatH   zEnum representing the data format used to store vector components.

See :ref:`oracle_vector_datatype` for background.

.. versionadded:: 2.0.41

INT8BINARYFLOAT32FLOAT64r   N)
r   r   r   r   r   r!   r"   r#   r$   r   r   r   r   r   r   H   s7     D F G Gr   r   c                  "    \ rS rSrSrSr SrSrg)VectorStorageTypec   zqEnum representing the vector type,

See :ref:`oracle_vector_datatype` for background.

.. versionadded:: 2.0.43

SPARSEDENSEr   N)r   r   r   r   r   r(   r)   r   r   r   r   r&   r&   c   s     F Er   r&   c                      \ rS rSr% Sr\R                  rS\S'   Sr	S\S'   Sr
S\S	'   SrS\S
'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   S rSrg)VectorIndexConfigx   a8  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                    [        U R                  5      U l        S HK  n[        X5      nUc  M  [        U[        5      (       a  M*  [        U S[        U5      R                   35      e   g )N)r0   r1   r2   r3   r4   r5   r/   z$ must be an integer ifprovided, got )r
   r-   getattr
isinstanceint	TypeErrortyper   )selffieldvalues      r   __post_init__VectorIndexConfig.__post_init__   sh    )$//:
E D(E E3)?)?g %%)%[%9%9$:< 
r   )r-   )r   r   r   r   r   r
   r   r-   __annotations__r.   r/   r0   r1   r2   r3   r4   r5   r?   r   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                  4    \ rS rSrSr      SS jrS rSrg)SparseVector   zt
Lightweight SQLAlchemy-side version of SparseVector.
This mimics oracledb.SparseVector.

.. versionadded:: 2.0.43

c                f   [        U[        R                  5      (       a  UR                  S:w  a  [        R                  " SU5      n[        U[        R                  5      (       d  [        R                  " SU5      n[        U5      [        U5      :w  a  [	        S5      eXl        X l        X0l        g )NIdz.indices and values must be of the same length!)r8   arraytypecodelenr:   num_dimensionsindicesvalues)r<   rK   rL   rM   s       r   __init__SparseVector.__init__   s     '5;;//73C3Cs3Jkk#w/G&%++..[[f-Fw<3v;&LMM,r   c                |    SU R                    S[        U R                  5       SU R                  R                   S3$ )NzSparseVector(num_dimensions=z, size=z, typecode=))rK   rJ   rL   rM   rI   )r<   s    r   __str__SparseVector.__str__   sC    *4+>+>*? @%&k$++2F2F1GqJ	
r   )rL   rK   rM   N)rK   r9   rL   Union[list, array.array]rM   rT   )r   r   r   r   r   rN   rR   r   r   r   r   rC   rC      s-     * )	"
r   rC   c                      \ rS rSrSrSrS r\R                  S\R                  S\R                  S\R                  S0rSS	 jrS
 rS rS r " S S\R$                  R&                  5      rSrg)VECTOR   zOracle VECTOR datatype.

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

.. versionadded:: 2.0.41

TbBfrG   Nc                    Ub   [        U[        5      (       d  [        S5      eUb   [        U[        5      (       d  [        S5      eUb   [        U[        5      (       d  [        S5      eXl        X l        X0l        g)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)r8   r9   r:   r   r&   dimstorage_formatstorage_type)r<   r\   r]   r^   s       r   rN   VECTOR.__init__   s      ?:c3#7#7566%j//
 /
 L  #J+-
 -
 H  ,(r   c                   ^ ^ UU 4S jnU$ )z
Converts a Python-side SparseVector instance into an
oracledb.SparseVectormor a compatible array format before
binding it to the database.
c                  > U b  [        U [        R                  5      (       a  U $ [        U [        5      (       a3  TR                  TR                  5      n[        R                  " X5      n U $ [        U [
        5      (       a;  TR                  R                  U R                  U R                  U R                  5      $ [        S5      e)Nz
                    Invalid input for VECTOR: expected a list, an array.array,
                    or a SparseVector object.
                    )r8   rH   list_array_typecoder]   rC   dbapirK   rL   rM   r:   )r>   rI   dialectr<   s     r   process.VECTOR._cached_bind_processor.<locals>.process(  s    }
5%++ > > E4((//0C0CDH4 E<00}}11((MMLL    r   r   )r<   re   rf   s   `` r   _cached_bind_processorVECTOR._cached_bind_processor!  s    	4 r   c                   ^ U4S jnU$ )z
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                   > U c  g [        U [        R                  5      (       a  [        U 5      $ [        U TR                  R                  5      (       a)  [	        U R
                  U R                  U R                  S9$ g )N)rK   rL   rM   )r8   rH   rb   rd   rC   rK   rL   rM   )r>   re   s    r   rf   0VECTOR._cached_result_processor.<locals>.processM  sh    }E5;;//E{" E7==#=#=>>##(#7#7!MM <<  ?r   r   )r<   re   coltyperf   s    `  r   _cached_result_processorVECTOR._cached_result_processorD  s    	 r   c                :    U R                   R                  US5      $ )z'
Map storage format to array typecode.
rG   )_typecode_mapget)r<   rI   s     r   rc   VECTOR._array_typecode^  s     !!%%h44r   c                  &    \ rS rSrS rS rS rSrg)VECTOR.comparator_factoryid  c                6    U R                  S[        S9" U5      $ )Nz<->return_typeopr   r<   others     r   l2_distance%VECTOR.comparator_factory.l2_distancee      775e74U;;r   c                6    U R                  S[        S9" U5      $ )Nz<#>rw   ry   r{   s     r   inner_product'VECTOR.comparator_factory.inner_producth  r   r   c                6    U R                  S[        S9" U5      $ )Nz<=>rw   ry   r{   s     r   cosine_distance)VECTOR.comparator_factory.cosine_distancek  r   r   r   N)r   r   r   r   r}   r   r   r   r   r   r   comparator_factoryru   d  s    	<	<	<r   r   )r\   r]   r^   )NNN)r   r   r   r   r   cache_ok__visit_name__r   r!   r"   r#   r$   rq   rN   rh   rn   rc   types
TypeEngine
Comparatorr   r   r   r   r   rV   rV      sv     HN 	  #""C##S##S	M!)F!F45<U--88 <r   rV   )
__future__r   rH   dataclassesr   enumr   typingr   r   sqlalchemy.typesr   r   r
   r   r   r&   r+   rC   r   rV   r   r   r   <module>r      s    #  !      "d & >$ 6 * M M M`
 
BB<U B<r   