
    Zi:              	       r    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	dS )
    )ListOptionalTuple)SparseVectorNindicesvalueslabelsreturnc                    | st          g g d          S |gt          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    b/root/projects/butler/venv/lib64/python3.11/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QQ7:N7K4}((&&&&
 
 
 	
 c'622GGG(+\(:%((&&
 
 
 	
r   )N)
typingr   r   r   chromadb.base_typesr   intfloatstrr   r   r   r   <module>r$      s    ( ( ( ( ( ( ( ( ( ( , , , , , , #',
 ,
#Y,
K,
 T#Y,
 	,
 ,
 ,
 ,
 ,
 ,
r   