nemoguardrails.embeddings.providers.cohere

View as Markdown

Module Contents

Classes

NameDescription
CohereEmbeddingModelEmbedding model using Cohere API.

Data

async_client_var

API

class nemoguardrails.embeddings.providers.cohere.CohereEmbeddingModel(
embedding_model: str,
input_type: str = 'search_document',
kwargs = {}
)

Bases: EmbeddingModel

Embedding model using Cohere API.

To use, you must have either:

  1. The COHERE_API_KEY environment variable set with your API key, or
  2. Pass your API key using the api_key kwarg to the Cohere constructor.

Parameters:

embedding_model
str

The name of the embedding model.

input_type
strDefaults to 'search_document'

The type of input for the embedding model, default is “search_document”. “search_document”, “search_query”, “classification”, “clustering”, “image”

client
= cohere.Client(**kwargs)
embedding_size
= self.embedding_size_dict[self.model]
embedding_size_dict
engine_name
= 'cohere'
nemoguardrails.embeddings.providers.cohere.CohereEmbeddingModel.encode(
documents: typing.List[str]
) -> typing.List[typing.List[float]]

Encode a list of documents into embeddings.

Parameters:

documents
List[str]

The list of documents to be encoded.

Returns: List[List[float]]

List[List[float]]: The encoded embeddings.

nemoguardrails.embeddings.providers.cohere.CohereEmbeddingModel.encode_async(
documents: typing.List[str]
) -> typing.List[typing.List[float]]
async

Encode a list of documents into embeddings.

Parameters:

documents
List[str]

The list of documents to be encoded.

Returns: List[List[float]]

List[List[float]]: The encoded embeddings.

nemoguardrails.embeddings.providers.cohere.async_client_var: ContextVar = ContextVar('async_client', default=None)