Repository navigation
🔧 refactor: Document Processing and Health Check Functions - #221
Merged
Merged
Conversation
* Refactored `_prepare_documents_sync` to handle document preparation synchronously, improving performance and clarity. * Updated `store_data_in_vector_db` to utilize the new synchronous document preparation function, ensuring non-blocking behavior in the async context. * Changed `is_health_ok` to be asynchronous, allowing for proper handling of health checks for different database types. These changes streamline document processing and improve the responsiveness of health checks in the application.
* Replaced `asyncio.get_event_loop()` with `asyncio.get_running_loop()` in `_process_documents_batched_sync` and `store_data_in_vector_db` to ensure compatibility with the current asyncio context. * This change enhances the reliability of asynchronous operations by using the correct method for obtaining the running event loop.
danny-avila
commented
Dec 10, 2025
danny-avila
left a comment
Collaborator
Author
There was a problem hiding this comment.
Summary
I refactored the document processing pipeline and health check system to be non-blocking, preventing CPU-bound work from blocking the async event loop.
- Extracted document preparation logic (text splitting, cleaning, metadata assignment) into a synchronous
_prepare_documents_sync()function that runs in a thread executor vialoop.run_in_executor() - Fixed a bug where
len(documents)was used instead oflen(docs)when generating IDs for vector store insertion; this caused a mismatch since the post-split chunk count differs from the original document count - Converted
is_health_ok()to async and addedawaitcalls topg_health_check()andmongo_health_check() - Changed
save_upload_file_sync()tosave_upload_file_async()for non-blocking file uploads - Changed
os.remove()tocleanup_temp_file_async()for non-blocking temp file cleanup
Potential Issues
-
Deprecated event loop access:
asyncio.get_event_loop()is deprecated in Python 3.10+. Replace withasyncio.get_running_loop(). -
Health check dependencies: The PR assumes
pg_health_check()andmongo_health_check()are already async. Verify these functions have been updated or this will break. -
Caller updates needed: Any code calling
is_health_ok()synchronously will break and needs toawaitit now.
Change Type
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
Testing
Recommend testing:
- Upload large documents and verify the API remains responsive to concurrent requests during processing
- Test health endpoint with both Postgres and MongoDB configurations
- Verify document chunking produces correct number of vector store entries with matching IDs
Checklist
- My code adheres to this project's style guidelines
- I have performed a self-review of my own code
- I have commented in any complex areas of my code
- I have made pertinent documentation changes
- My changes do not introduce new warnings
- I have written tests demonstrating that my changes are effective or that my feature works
- Local unit tests pass with my changes
- Any changes dependent on mine have been merged and published in downstream modules
|
gh repo clone danny-avila/rag_api |
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.
_prepare_documents_syncto handle document preparation synchronously, improving performance and clarity.store_data_in_vector_dbto utilize the new synchronous document preparation function, ensuring non-blocking behavior in the async context.is_health_okto be asynchronous, allowing for proper handling of health checks for different database types.These changes streamline document processing and improve the responsiveness of health checks in the application.