Auto-generate embeddings on entity create/update#1639
Draft
EmanueleDeRossi1 wants to merge 7 commits intomainfrom
Draft
Auto-generate embeddings on entity create/update#1639EmanueleDeRossi1 wants to merge 7 commits intomainfrom
EmanueleDeRossi1 wants to merge 7 commits intomainfrom
Conversation
84f7ac8 to
cdf4816
Compare
- Replace session commit hooks with EmbeddableMixin after_insert/update - Remove embedding/events.py; enqueue via EmbeddingService with primitives - Add searchable_text to generator and Celery task to avoid reloading entity
33d68b9 to
7a13c1e
Compare
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.
Purpose
Automatic embedding generation is triggered by SQLAlchemy ORM instance listeners on
EmbeddableMixin(after_insert/after_update). Callers no longer need to manually enqueue embedding work after saving an entity. The pipeline passes identity + precomputed searchable text intoEmbeddingService, the generator, and the Celery task, so background work does not depend on holding the ORM instance or re-loading it just to get text.What changed
EmbeddableMixin(mixins.py)searchable_text_changed(), which hashesto_searchable_text()and compares it toEmbedding.text_hashrows (first embed, or stale when no row matches the current hash).@event.listens_for(EmbeddableMixin, "after_insert", propagate=True)and"after_update"handlers buildEmbeddingService(session)and callenqueue_embedding(...)withentity_type,entity_id,searchable_text,user_id, andorganization_id.EmbeddingService/ generator / taskenqueue_embeddingis keyword-based and passes primitives (plussearchable_text) instead of(entity, current_user).EmbeddingGenerator.generateaccepts optionalsearchable_text; when set, it can embed without loading the entity for text.generate_embedding_taskacceptssearchable_textand forwards it to the generator.Tests
enqueue_embeddingand internal_execute_sync/_enqueue_asyncsignatures; mocks are reset wherecommitruns and triggers the new listeners.