ó
    øÞ j?*  ã                  ó  • 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é   zŒEnum 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   ó    Ú[/var/www/html/gaurav/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é)   zŒEnum 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)	ÚVectorStorageFormatéH   z‘Enum 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)ÚVectorStorageTypeéc   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)ÚVectorIndexConfigéx   a6  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                óÚ   • [        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ØÓ ¬°E¼3×)?Ó)?ÜØ�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Ñ"6€J�Ó6Ø-1€HÐ*Ó1Ø"€HˆmÓ"Ø$(€N�MÓ(Ø)-Ð˜Ó-Ø-1Ð˜]Ó1Ø.2Ð˜mÓ2Ø37Ð! =Ó7Ø"€HˆmÓ"õ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§;¡;×/Ñ/°7×3CÑ3CÀsÓ3JÜ—k’k # wÓ/ˆGÜ˜&¤%§+¡+×.Ñ.Ü—[’[  fÓ-ˆFÜˆw‹<œ3˜v›;Ó&ÜÐ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°$·+±+×2FÑ2FÐ1GÀqð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éê   zƒOracle 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 integerz: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Š   € ð  ‰?¤:¨c´3×#7Ñ#7ÜÐ4Ó5Ð5ØÑ%¬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´%·+±+× >Ñ >Ø�ô ˜E¤4×(Ñ(Ø×/Ñ/°×0CÑ0CÓD�ÜŸš HÓ4�Ø�ô ˜E¤<×0Ñ0Ø—}‘}×1Ñ1Ø×(Ñ(Ø—M‘MØ—L‘Lóð ô  ð !ó ð r   r   )r>   rg   rh   s   `` r   Ú_cached_bind_processorÚVECTOR._cached_bind_processor"  s   ù€ ö	ð0 ˆ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>.processL  sh   ø€ Ø‰}Øä˜E¤5§;¡;×/Ñ/Ü˜E“{Ð"ô ˜E 7§=¡=×#=Ñ#=×>Ñ>Ü#Ø#(×#7Ñ#7Ø!ŸM™MØ Ÿ<™<ñð ð ?r   r   )r>   rg   Úcoltyperh   s    `  r   Ú_cached_result_processorÚVECTOR._cached_result_processorC  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_factoryic  c                ó6   • U R                  S[        S9" U5      $ )Nz<->©Úreturn_type©Úopr
   ©r>   Úothers     r   Úl2_distanceÚ%VECTOR.comparator_factory.l2_distanced  ó   € Ø—7‘7˜5¬e�7Ñ4°UÓ;Ð;r   c                ó6   • U R                  S[        S9" U5      $ )Nz<#>ry   r{   r}   s     r   Úinner_productÚ'VECTOR.comparator_factory.inner_productg  r�   r   c                ó6   • U R                  S[        S9" U5      $ )Nz<=>ry   r{   r}   s     r   Úcosine_distanceÚ)VECTOR.comparator_factory.cosine_distancej  r�   r   r   N)r   r   r   r   r   rƒ   r†   r   r   r   r   Úcomparator_factoryrw   c  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òBò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A<ˆU×Ñõ A<r   