
    ,x`ih*                       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   )types)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       j/home/webadmin/html/weedthought.com/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)r2   r3   r4   r5   r6   r7   r1   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__r0   r1   r2   r3   r4   r5   r6   r7   rA   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!)r:   arraytypecodelenr<   num_dimensionsindicesvalues)r>   rM   rN   rO   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=))rM   rL   rN   rO   rK   )r>   s    r   __str__SparseVector.__str__   sC    *4+>+>*? @%&k$++2F2F1GqJ	
r   )rN   rM   rO   N)rM   r;   rN   Union[list, array.array]rO   rV   )r   r   r   r   r   rP   rT   r   r   r   r   rE   rE      s-     * )	"
r   rE   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frI   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)r:   r;   r<   r!   r(   dimstorage_formatstorage_type)r>   r^   r_   r`   s       r   rP   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.
                    )r:   rJ   list_array_typecoder_   rE   dbapirM   rN   rO   r<   )r@   rK   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>   rg   rh   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)rM   rN   rO   )r:   rJ   rd   rf   rE   rM   rN   rO   )r@   rg   s    r   rh   0VECTOR._cached_result_processor.<locals>.processN  sh    }E5;;//E{" E7==#=#=>>##(#7#7!MM <<  ?r   r   )r>   rg   coltyperh   s    `  r   _cached_result_processorVECTOR._cached_result_processorE  s    	 r   c                :    U R                   R                  US5      $ )z'
Map storage format to array typecode.
rI   )_typecode_mapget)r>   rK   s     r   re   VECTOR._array_typecode_  s     !!%%h44r   c                  &    \ rS rSrS rS rS rSrg)VECTOR.comparator_factoryie  c                6    U R                  S[        S9" U5      $ )Nz<->return_typeopr
   r>   others     r   l2_distance%VECTOR.comparator_factory.l2_distancef      775e74U;;r   c                6    U R                  S[        S9" U5      $ )Nz<#>ry   r{   r}   s     r   inner_product'VECTOR.comparator_factory.inner_producti  r   r   c                6    U R                  S[        S9" U5      $ )Nz<=>ry   r{   r}   s     r   cosine_distance)VECTOR.comparator_factory.cosine_distancel  r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   comparator_factoryrw   e  s    	<	<	<r   r   )r^   r_   r`   )NNN)r   r   r   r   r   cache_ok__visit_name__r!   r#   r$   r%   r&   rs   rP   rj   rp   re   r	   
TypeEngine
Comparatorr   r   r   r   r   rX   rX      sv     HN 	  #""C##S##S	M!)F!F45<U--88 <r   rX   )
__future__r   rJ   dataclassesr   enumr   typingr   r    r	   r
   r   r   r!   r(   r-   rE   r   rX   r   r   r   <module>r      s    #  !     d & >$ 6 * M M M`
 
BC<U C<r   