
    ei:              	       X    d dl mZmZmZ d dlmZ 	 d	dee   dee   deee      defdZ	y)
    )ListOptionalTuple)SparseVectorNindicesvalueslabelsreturnc                 H   | st        g g d      S |Nt        t        | ||      d       }t        | \  }}}t        t        |      t        |      t        |            S t        t        | |      d       }t        | \  }}t        t        |      t        |      d      S )aG  Normalize and create a SparseVector by sorting indices and values together.

    This function takes raw indices and values (which may be unsorted or have duplicates)
    and returns a properly constructed SparseVector with sorted indices.

    Args:
        indices: List of dimension indices (may be unsorted)
        values: List of values corresponding to each index
        labels: Optional list of string labels corresponding to each index

    Returns:
        SparseVector with indices sorted in ascending order

    Raises:
        ValueError: If indices and values have different lengths
        ValueError: If there are duplicate indices (after sorting)
        ValueError: If indices are negative
        ValueError: If values are not numeric
        ValueError: If labels is provided and has different length than indices
    N)r   r   r	   c                     | d   S Nr    xs    o/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/chromadb/utils/sparse_embedding_utils.py<lambda>z)normalize_sparse_vector.<locals>.<lambda>#   s
    AaD     )keyc                     | d   S r   r   r   s    r   r   z)normalize_sparse_vector.<locals>.<lambda>+   s
    !A$ r   )r   sortedziplist)r   r   r	   sorted_triplessorted_indicessorted_valuessorted_labelssorted_pairss           r   normalize_sparse_vectorr      s    2 Br$?? GVV <.Q7:N7K4}(&&
 	
 c'62G(+\(:%(&
 	
r   )N)
typingr   r   r   chromadb.base_typesr   intfloatstrr   r   r   r   <module>r$      sM    ( ( , #',
#Y,
K,
 T#Y,
 	,
r   