-
Notifications
You must be signed in to change notification settings - Fork 96
Improve observability in EmbeddingService model lifecycle in #193 #199
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe embedding service now includes internal state tracking with model loading and access counters. Enhancements add concurrency detection during lazy-loading, emit debug logs tracking access counts and load state, and improve error handling with enhanced logging throughout the initialization flow. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
backend/app/services/embedding_service/service.py (2)
43-49: Add spacing around the+=operator.The access tracking logic is good for observability. However, line 44 is missing spaces around the
+=operator.🔎 Style fix
- self._model_access_count+=1 + self._model_access_count += 1
73-75: Simplify exception string conversion.The addition of
exc_info=Trueis excellent for debugging. However,str(e)in the f-string is redundant since the exception will be automatically converted to a string.🔎 Simplification
- logger.error(f"Error loading model {self.model_name}: {str(e)}", + logger.error(f"Error loading model {self.model_name}: {e}", exc_info=True )As per static analysis hint RUF010.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
backend/app/services/embedding_service/service.py
🧰 Additional context used
🪛 Ruff (0.14.10)
backend/app/services/embedding_service/service.py
73-73: Use explicit conversion flag
Replace with conversion flag
(RUF010)
🔇 Additional comments (5)
backend/app/services/embedding_service/service.py (5)
37-38: Good addition for observability.These tracking fields will help surface concurrent access patterns and model lifecycle behavior.
54-58: Effective observability for concurrent initialization attempts.This warning will help surface race conditions during concurrent model access. As noted in the comment, this is observation-only and complements the separate fix planned for issue #193.
60-71: Excellent use of finally block and enhanced logging.The flag management with a finally block ensures
_model_loadingis always reset, and the detailed logging messages provide clear visibility into the model lifecycle.Also applies to: 77-78
79-83: Great addition for complete observability.Logging model reuse alongside initialization provides a complete picture of the model lifecycle and helps distinguish between cached and fresh model access.
37-38: Note: Access counter may be inaccurate under concurrent access.Since
_model_access_countis incremented without synchronization, concurrent accesses may result in lost increments and an undercount. This is acceptable for observability purposes where exact counts aren't critical, but worth noting for interpretation of the logs.If precise counting becomes important in the future, consider using
threading.Lockor atomic operations. For now, this provides useful approximate metrics.Also applies to: 43-49
|
@coderabbitai generate docstrings |
✅ Actions performedInitiated docstring generation; will generate only if new commits exist. |
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @tanii1125. * #199 (comment) The following files were modified: * `backend/app/services/embedding_service/service.py`
Related Issue
📝 Description
This PR adds logging and observability around
EmbeddingServicemodel initialization and reuse.It does not modify model loading logic, concurrency, or locking.
🔧 Changes Made
added logs like :
In
__init__of classEmbeddingService-Added access count of model -
Case 1 :
if self._model is None:Set _model_loading to True before model initialization to detect concurrent access. -
and after loading made it
false-Case 2 :
if self._model is None:isFalse(or else simply)Notes
This PR is intended to complement the race-condition fix discussed in #193 by improving visibility
into model lifecycle behavior under concurrent access.
✅ Checklist
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.