switch to celery.chain for certain vector_search tasks - #3484
Conversation
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
There was a problem hiding this comment.
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_embeddingstask rate limit from300/mto200/m. - Switch content-file embedding/removal task fan-out from
celery.group(parallel) tocelery.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. |
| return self.replace( | ||
| celery.group( | ||
| celery.chain( | ||
| [ | ||
| generate_embeddings.si(ids, CONTENT_FILE_TYPE, overwrite=True) | ||
| for ids in chunks( |
| autoretry_for=(RetryError,), | ||
| retry_backoff=True, | ||
| rate_limit="300/m", | ||
| rate_limit="200/m", |
There was a problem hiding this comment.
leaving this as-is for now (may need to tweak further and potentially make it independant of the settings rate limit
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
left a comment
There was a problem hiding this comment.
LGTM, one minor change suggested which could potentially prevent errors under one condition (no contentfiles) flagged by copilot
| if not tasks: | ||
| return None |
There was a problem hiding this comment.
Add this to remove_unpublished_run_content_files and remove_run_content_files too?
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:
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