cohere-ai / cohere-python

Python Library for Accessing the Cohere API
https://docs.cohere.ai
MIT License
300 stars 65 forks source link

Embed API returning floats when requesting int8 primitive type #466

Closed farzad528 closed 6 months ago

farzad528 commented 6 months ago

I have the following function that was returning int8 correctly when the new Embed API that support int8 and binary embeddings was published. However, the same code blocks seems to return floats with a single decimal zero. Is this a known bug or by design? The workaround is converting to ints directly in python.

def generate_embeddings(texts, input_type="search_document"):
    model = "embed-english-v3.0"
    # Ensure texts is a list
    if isinstance(texts, str):
        texts = [texts]

    response = co.embed(
        texts=texts,
        model=model,
        input_type=input_type,
        embedding_types=["int8"],
    )
    # Bug: There seems to be a bug in Cohere's Embed API that returns the embeddings as floats instead of integers
    # Convert each embedding value to an integer
    return [[int(value) for value in embedding] for embedding in response.embeddings.int8]

image

billytrend-cohere commented 6 months ago

Hey @farzad528 thanks for flagging this! I will release a new version of the sdk tomorrow with the correct types.

billytrend-cohere commented 6 months ago

Fixed in 5.2.4 thanks!