fix(db): release connection before embedding in memory /query (#20579)

Remove Depends(get_session) from POST /query endpoint to prevent database connections from being held during embedding API calls (1-5+ seconds).

The Memories.get_memories_by_user_id() function manages its own short-lived session internally, releasing the connection before the slow EMBEDDING_FUNCTION() call begins.
This commit is contained in:
Classic298
2026-01-11 20:37:47 +01:00
committed by GitHub
parent 33e8a09880
commit 1dc353433a

View File

@@ -122,8 +122,11 @@ async def query_memory(
request: Request,
form_data: QueryMemoryForm,
user=Depends(get_verified_user),
db: Session = Depends(get_session),
):
# NOTE: We intentionally do NOT use Depends(get_session) here.
# Database operations (get_memories_by_user_id) manage their own short-lived sessions.
# This prevents holding a connection during EMBEDDING_FUNCTION()
# which makes external embedding API calls (1-5+ seconds).
if not request.app.state.config.ENABLE_MEMORIES:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
@@ -138,7 +141,7 @@ async def query_memory(
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
memories = Memories.get_memories_by_user_id(user.id, db=db)
memories = Memories.get_memories_by_user_id(user.id)
if not memories:
raise HTTPException(status_code=404, detail="No memories found for user")