
    Wi                     V    d dl Z d dlZd dlmZ d dlmZmZmZ d dlm	Z	  G d de	      Z
y)    N)tqdm)AnyListMapping)BaseEmbedderc                        e Zd ZdZdddi fdededz  dedz  deeef   f fdZ	dd	e
e   d
edej                  fdZd Z xZS )CohereBackenda  Cohere Embedding Model.

    Arguments:
        client: A `cohere` client.
        embedding_model: A Cohere model. Default is "large".
                         For an overview of models see:
                         https://docs.cohere.ai/docs/generation-card
        delay_in_seconds: If a `batch_size` is given, use this set
                          the delay in seconds between batches.
        batch_size: The size of each batch.
        embed_kwargs: Kwargs passed to `cohere.Client.embed`.
                            Can be used to define additional parameters
                            such as `input_type`

    Examples:
    ```python
    import cohere
    from bertopic.backend import CohereBackend

    client = cohere.Client("APIKEY")
    cohere_model = CohereBackend(client)
    ```

    If you want to specify `input_type`:

    ```python
    cohere_model = CohereBackend(
        client,
        embedding_model="embed-english-v3.0",
        embed_kwargs={"input_type": "clustering"}
    )
    ```
    largeNembedding_modeldelay_in_seconds
batch_sizeembed_kwargsc                     t         |           || _        || _        || _        || _        || _        | j                  j                  d      r|j                  d      | _        y | j                  | j                  d<   y )Nmodel)super__init__clientr   r   r   r   get)selfr   r   r   r   r   	__class__s         d/home/sietch6/trending-topics-pipeline/venv/lib/python3.12/site-packages/bertopic/backend/_cohere.pyr   zCohereBackend.__init__+   ss     	. 0$(  )#/#3#3G#<D )-)=)=Dg&    	documentsverbosereturnc                    | j                   g }t        | j                  |      |       D ]q  } | j                  j                  dd|i| j
                  }|j                  |j                         | j                  sSt        j                  | j                         s n4 | j                  j                  dd|i| j
                  }|j                  }t        j                  |      S )a  Embed a list of n documents/words into an n-dimensional
        matrix of embeddings.

        Arguments:
            documents: A list of documents or words to be embedded
            verbose: Controls the verbosity of the process

        Returns:
            Document/words embeddings with shape (n, m) with `n` documents/words
            that each have an embeddings size of `m`
        )disabletexts )r   r   _chunksr   embedr   extend
embeddingsr   timesleepnparray)r   r   r   r#   batchresponses         r   r!   zCohereBackend.embed?   s     ??&Jdll957{K 6,4;;,,N5ND<M<MN!!("5"56 ((JJt4456 )t{{((NyND<M<MNH!,,Jxx
##r   c              #   ~   K   t        dt        |      | j                        D ]  }|||| j                  z      y w)Nr   )rangelenr   )r   r   is      r   r    zCohereBackend._chunks\   s<     q#i.$//: 	5AADOO 344	5s   ;=)F)__name__
__module____qualname____doc__strfloatintr   r   r   r   boolr&   ndarrayr!   r    __classcell__)r   s   @r   r	   r	      s|     J  ')-!%*,> >  $,	>
 $J> c3h'>($tCy $4 $BJJ $:5r   r	   )r$   numpyr&   r   typingr   r   r   bertopic.backendr   r	   r   r   r   <module>r;      s%       % % )V5L V5r   