Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'truncate' parameter for CohereEmbeddings #798

Merged
merged 4 commits into from
Feb 1, 2023

Conversation

ephe-meral
Copy link
Contributor

Currently, the 'truncate' parameter of the cohere API is not supported.

This means that by default, if trying to generate and embedding that is too big, the call will just fail with an error (which is frustrating if using this embedding source e.g. with GPT-Index, because it's hard to handle it properly when generating a lot of embeddings).
With the parameter, one can decide to either truncate the START or END of the text to fit the max token length and still generate an embedding without throwing the error.

In this PR, I added this parameter to the class.

Arguably, there should be a better way to handle this error, e.g. by optionally calling a function or so that gets triggered when the token limit is reached and can split the document or some such. Especially in the use case with GPT-Index, its often hard to estimate the token counts for each document and I'd rather sort out the troublemakers or simply split them than interrupting the whole execution.
Thoughts?

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this! really curious to hear more about your last comment - do you want to dm me to discuss more?

@hwchase17 hwchase17 merged commit ebea40c into langchain-ai:master Feb 1, 2023
hwchase17 pushed a commit that referenced this pull request Feb 24, 2023
As #798, this commit adds the option to truncate the user's inputs
larger than what the model can handle.

This defaults to None in the Cohere SDK instead of directly passing
"NONE", so I maintained the same default value (see:
https://github.com/cohere-ai/cohere-python/blob/7f30bfd40c98b88f7d08f8c05db5b91ddb1310d1/cohere/client.py#L127)


PS: I think that both this and #798 should default to the same value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants