Skip to content

switch to celery.chain for certain vector_search tasks - #3484

Merged
shanbady merged 7 commits into
mainfrom
shanbady/throttle-run-embeddings-tasks
Jun 17, 2026
Merged

switch to celery.chain for certain vector_search tasks#3484
shanbady merged 7 commits into
mainfrom
shanbady/throttle-run-embeddings-tasks

Conversation

@shanbady

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/11848

Description (What does it do?)

This PR makes the contentfile embeddings (and similar) tasks in the vector_search app to use a celery chain instead of a group in order to resolve an issue where qdrant gets overwhelmed when many (100's) of runs are processed at once.

How can this be tested?

I have not found a simple way of seeing this overwhelming of qdrant locally but you can verify that the tasks continue to work as expected using celery.chain:

from vector_search.tasks import *
from learning_resources.models import *

run = LearningResourceRun.objects.first()

remove_run_content_files.apply_async([run.id])
embed_run_content_files.apply_async([run.id])
remove_unpublished_run_content_files.apply_async([run.id])

Additional Context

After this deploys I will try embedding the ~1300 runs we need to as part of the variant course workaround - If it continues being problematic we may need to adjust the throttle further

@shanbady shanbady added the Needs Review An open Pull Request that is ready for review label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@shanbady
shanbady marked this pull request as ready for review June 17, 2026 15:18
Copilot AI review requested due to automatic review settings June 17, 2026 15:18
@mbertrand mbertrand self-assigned this Jun 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the vector_search Celery task orchestration to reduce Qdrant load spikes when embedding/removing large volumes of content-file vectors, by serializing chunked work via celery.chain and tightening the embeddings task rate limit.

Changes:

  • Lower generate_embeddings task rate limit from 300/m to 200/m.
  • Switch content-file embedding/removal task fan-out from celery.group (parallel) to celery.chain (sequential).
  • Update unit tests to reflect the new Celery canvas primitive.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
vector_search/tasks.py Adjusts rate limit and changes several content-file task canvases from group to chain to reduce concurrency against Qdrant.
vector_search/tasks_test.py Updates assertions to expect celery.chain instead of celery.group in the affected tasks.

Comment thread vector_search/tasks.py Outdated
Comment thread vector_search/tasks.py Outdated
Comment on lines 398 to 402
return self.replace(
celery.group(
celery.chain(
[
generate_embeddings.si(ids, CONTENT_FILE_TYPE, overwrite=True)
for ids in chunks(
Comment thread vector_search/tasks.py Outdated
Comment thread vector_search/tasks.py Outdated
Comment thread vector_search/tasks_test.py Outdated
Comment thread vector_search/tasks_test.py Outdated
Comment thread vector_search/tasks.py
autoretry_for=(RetryError,),
retry_backoff=True,
rate_limit="300/m",
rate_limit="200/m",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

leaving this as-is for now (may need to tweak further and potentially make it independant of the settings rate limit

shanbady and others added 4 commits June 17, 2026 11:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@mbertrand mbertrand left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, one minor change suggested which could potentially prevent errors under one condition (no contentfiles) flagged by copilot

Comment thread vector_search/tasks.py Outdated
Comment on lines +404 to +405
if not tasks:
return None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add this to remove_unpublished_run_content_files and remove_run_content_files too?

@mbertrand mbertrand left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@shanbady
shanbady merged commit 875beb7 into main Jun 17, 2026
12 checks passed
@shanbady
shanbady deleted the shanbady/throttle-run-embeddings-tasks branch June 17, 2026 15:53
@odlbot odlbot mentioned this pull request Jun 17, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants