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

Batch Request For Embeds #43

Merged
merged 2 commits into from
Feb 7, 2022
Merged

Batch Request For Embeds #43

merged 2 commits into from
Feb 7, 2022

Conversation

OrenLeung
Copy link
Contributor

@OrenLeung OrenLeung commented Jan 31, 2022

What it does

  • Add non-parallel Batch Embeds
  • Parallel Batch Embeds through python Threading Workers or concurrent.futures.ThreadPoolExecutor (still researching to figure out which is better)

Design Decision

  • chose thread executor over multi processing executor as it is IO-bound and not CPU-bound so most of the time the threads are waiting for a network response
  • the response must be in order (test added)

Future PR

Tests

  • added unit tests for multiple batches
  • test that it is in order

Basic Performance Test for 25k texts

  • @jalammar reported it takes 5 hours for non-parallel

  • batching resulted in 3mins & 30 secs

letters = string.ascii_lowercase

def random_word():
    return ''.join(random.choice(letters) for i in range(10))

def random_sentence(num):
    sentence = ""

    for i in range(num):
        sentence += random_word()

    return sentence

def list_of_list(num):
    arr = []

    for i in range(num):
        arr.append(random_sentence(50))
    
    return arr

co = cohere.Client(
    API_KEY)

prediction = co.embed(
    model='small',
    texts=list_of_list(25000))

print(len(prediction.embeddings))

cohere/__init__.py Outdated Show resolved Hide resolved
cohere/client.py Outdated Show resolved Hide resolved
cohere/client.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jimwu6 jimwu6 left a comment

Choose a reason for hiding this comment

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

LGTM

@jimwu6 jimwu6 merged commit f8f0498 into main Feb 7, 2022
@jimwu6 jimwu6 deleted the batch-requests-for-embeds branch February 7, 2022 22:25
vshmyhlo pushed a commit that referenced this pull request Feb 21, 2023
* ⚡ Batch Request For Embeds

* ⚡ Parallel Batching
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.

None yet

3 participants