fix: optimize category initialization to avoid unnecessary embedding#388
Open
fix: optimize category initialization to avoid unnecessary embedding#388
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Pull Request Summary
Please provide a short summary explaining the purpose of this PR.
✅ What does this PR do?
_initialize_categoriesto skip unnecessary embedding API calls during category initialization. Instead of always embedding all category texts upfront, the method now pre-checks existing categories vialist_categories, classifies each config as create, update, or ready, and only batch-embeds the categories that actually need it (new categories, missing embeddings, or changed descriptions).get_or_create_category, while categories needing a description or embedding refresh useupdate_categorydirectly.🤔 Why is this change needed?
_initialize_categoriesgenerated embeddings for all configured categories unconditionally, even when those categories already existed in the database with all fields populated. In steady state (the common case after first run), this meant paying for embedding tokens on every initialization with zero benefit.🔍 Type of Change
Please check what applies:
✅ PR Quality Checklist
📌 Optional