diff --git a/backend/app/api/endpoints/assistant_chat.py b/backend/app/api/endpoints/assistant_chat.py index 5edf53c5..42bd104c 100644 --- a/backend/app/api/endpoints/assistant_chat.py +++ b/backend/app/api/endpoints/assistant_chat.py @@ -155,6 +155,7 @@ async def post_message( raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e)) except Exception as e: logger.exception("Assistant chat message failed: %s", e) + await db.rollback() await record_ai_usage( user_id=current_user.id, account_id=current_user.account_id, diff --git a/backend/app/services/rag_service.py b/backend/app/services/rag_service.py index 080c0098..806f9b1a 100644 --- a/backend/app/services/rag_service.py +++ b/backend/app/services/rag_service.py @@ -143,13 +143,13 @@ async def search( te.chunk_text, te.chunk_type, te.node_id, - 1 - (te.embedding <=> :embedding::vector) as similarity + 1 - (te.embedding <=> CAST(:embedding AS vector)) as similarity FROM tree_embeddings te JOIN trees t ON t.id = te.tree_id WHERE te.account_id = :account_id AND t.deleted_at IS NULL {exclude_clause} - ORDER BY te.embedding <=> :embedding::vector + ORDER BY te.embedding <=> CAST(:embedding AS vector) LIMIT :limit """), params,