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

Improvements to the Embedding functionality #776

Merged
merged 4 commits into from
Jun 11, 2024

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Jun 7, 2024

Description of the Change

In testing out another plugin that uses the Embedding functionality from ClassifAI, ran into a few issues that could be improved.

  1. The OpenAI API allows you to generate Embeddings from either a single string or an array of strings. In Updates to the OpenAI Embeddings Provider #758 we made some major improvements to Embeddings, one of which was to break content down into smaller chunks and embed each chunk. This was done with individual API requests as I didn't realize you could send array data. This PR fixes that by checking the size of the content and if it's below the token limit, we send that as a single request. For any bulk processing, this reduces the number of API requests significantly, helping with performance and helping to avoid rate limit errors
  2. Also discovered a bug in our chunking code where each chunk would be larger than the last. We want an overlap with each chunk but there was a bug here where each iteration we would increase that overlap. This wasn't noticeable for smaller posts but for long posts, you'd end up with huge chunks that were over the token limit, resulting in API failures. This also meant more tokens were being used that necessary. For any bulk processing, this helps reduce the tokens used significantly
  3. Ensure we set a higher timeout for the Azure OpenAI Embedding requests, as these can timeout at the default 5 seconds

How to test the Change

  1. Setup the Classification Feature to use either OpenAI or Azure OpenAI (or try both)
  2. Preview a post and ensure results show
  3. (Optional) Test classifying a post and ensure results show

Changelog Entry

Added - Higher timeout for Azure OpenAI Embedding requests
Changed - Add the ability to send chunked content in a single request to the Embedding API
Fixed - Ensure we chunk content correctly, keeping each chunk roughly the same size

Credits

Props @dkotter

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@dkotter dkotter added this to the 3.1.0 milestone Jun 7, 2024
@dkotter dkotter self-assigned this Jun 7, 2024
@dkotter dkotter requested review from jeffpaul and a team as code owners June 7, 2024 20:19
@github-actions github-actions bot added the needs:code-review This requires code review. label Jun 7, 2024
@dkotter dkotter requested review from iamdharmesh and removed request for a team and jeffpaul June 7, 2024 20:46
@jeffpaul jeffpaul mentioned this pull request Jun 10, 2024
22 tasks
Copy link
Member

@iamdharmesh iamdharmesh 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 improvement @dkotter Code Looks good and it tests well.

@dkotter dkotter merged commit fdddf1d into develop Jun 11, 2024
14 of 15 checks passed
@dkotter dkotter deleted the fix/faster-embedding-requests branch June 11, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants