fix(db): release connection before embedding in process_files_batch (#20576)
Remove Depends(get_session) from POST /process/files/batch endpoint to prevent database connections from being held during batch embedding API calls (5-60+ seconds for large batches). The save_docs_to_vector_db() function makes external embedding API calls. Post-embedding file updates (Files.update_file_by_id) manage their own short-lived sessions internally, releasing connections promptly.
This commit is contained in:
1 parent
3fc866117d
commit
182d5e8591
1 file changed
+6
-2
@@ -2626,10 +2626,14 @@ async def process_files_batch(
|
|||||||
request: Request,
|
request: Request,
|
||||||
form_data: BatchProcessFilesForm,
|
form_data: BatchProcessFilesForm,
|
||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
db: Session = Depends(get_session),
|
|
||||||
) -> BatchProcessFilesResponse:
|
) -> BatchProcessFilesResponse:
|
||||||
"""
|
"""
|
||||||
Process a batch of files and save them to the vector database.
|
Process a batch of files and save them to the vector database.
|
||||||
|
|
||||||
|
NOTE: We intentionally do NOT use Depends(get_session) here.
|
||||||
|
The save_docs_to_vector_db() call makes external embedding API calls which
|
||||||
|
can take 5-60+ seconds for batch operations. Database operations after
|
||||||
|
embedding (Files.update_file_by_id) manage their own short-lived sessions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
collection_name = form_data.collection_name
|
collection_name = form_data.collection_name
|
||||||
@@ -2690,7 +2694,7 @@ async def process_files_batch(
|
|||||||
# Update all files with collection name
|
# Update all files with collection name
|
||||||
for file_update, file_result in zip(file_updates, file_results):
|
for file_update, file_result in zip(file_updates, file_results):
|
||||||
Files.update_file_by_id(
|
Files.update_file_by_id(
|
||||||
id=file_result.file_id, form_data=file_update, db=db
|
id=file_result.file_id, form_data=file_update
|
||||||
)
|
)
|
||||||
file_result.status = "completed"
|
file_result.status = "completed"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user