diff --git a/backend/src/api/dependencies/session.py b/backend/src/api/dependencies/session.py index 70bbaae..cadc2ab 100644 --- a/backend/src/api/dependencies/session.py +++ b/backend/src/api/dependencies/session.py @@ -8,9 +8,13 @@ async def get_async_session() -> typing.AsyncGenerator[SQLAlchemyAsyncSession, None]: try: yield async_db.async_session + loguru.logger.info(f"Async pool:{async_db.pool.status()}") except Exception as e: loguru.logger.info(f"Exception --- {e}") await async_db.async_session.rollback() raise + else: + # https://github.com/grillazz/fastapi-sqlalchemy-asyncpg/issues/63 + await async_db.async_session.commit() finally: await async_db.async_session.close() diff --git a/backend/src/api/routes/rag_datasets.py b/backend/src/api/routes/rag_datasets.py index b5315cc..616e654 100644 --- a/backend/src/api/routes/rag_datasets.py +++ b/backend/src/api/routes/rag_datasets.py @@ -20,6 +20,7 @@ from src.models.schemas.dataset import RagDatasetCreate, RagDatasetResponse, LoadRAGDSResponse from src.repository.rag_datasets_eng import DatasetEng from src.repository.crud.account import AccountCRUDRepository +from src.repository.crud.dataset_db import DataSetCRUDRepository from src.securities.authorizations.jwt import jwt_required from src.repository.crud.chat import SessionCRUDRepository from src.utilities.formatters.ds_formatter import DatasetFormatter @@ -39,6 +40,7 @@ ) async def get_dataset_list( token: str = fastapi.Depends(oauth2_scheme), + ds_repo: DataSetCRUDRepository = fastapi.Depends(get_repository(repo_type=DataSetCRUDRepository)), ) -> list[RagDatasetResponse]: """ Get all the pre-processed dataset list. @@ -62,7 +64,7 @@ async def get_dataset_list( """ # It is unthread safe - # list_ds = await ds_repo.get_dataset_list() + # list_ds_from_db = await ds_repo.get_dataset_list() list_ds = [settings.DEFAULT_RAG_DS_NAME] diff --git a/backend/src/repository/crud/vectors_helper.py b/backend/src/repository/crud/vectors_helper.py deleted file mode 100644 index 30f9035..0000000 --- a/backend/src/repository/crud/vectors_helper.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -# Copyright [2024] [SkywardAI] -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - diff --git a/backend/src/repository/database.py b/backend/src/repository/database.py index 11591c6..1160855 100644 --- a/backend/src/repository/database.py +++ b/backend/src/repository/database.py @@ -20,7 +20,6 @@ create_async_engine as create_sqlalchemy_async_engine, ) from sqlalchemy.pool import Pool as SQLAlchemyPool -from sqlalchemy.pool import NullPool from sqlalchemy import create_engine from src.config.manager import settings @@ -33,13 +32,14 @@ def __init__(self): self.async_engine: SQLAlchemyAsyncEngine = create_sqlalchemy_async_engine( url=self.set_async_db_uri, echo=settings.IS_DB_ECHO_LOG, + echo_pool=True, future=True, - # pool_size=settings.DB_POOL_SIZE, + pool_size=settings.DB_POOL_SIZE, + pool_timeout=60, # max_overflow=settings.DB_POOL_OVERFLOW, # pool_recycle=3600, # Periodically recycle connections (optional) - # pool_pre_ping=True, # Check the connection status before using it + pool_pre_ping=True, # Check the connection status before using it # https://github.com/MagicStack/asyncpg/issues/863 - poolclass=NullPool, ) self.sync_engine = create_engine( f"{settings.POSTGRES_SCHEMA}://{settings.POSTGRES_USERNAME}:{settings.POSTGRES_PASSWORD}@{settings.POSTGRES_HOST}:{settings.POSTGRES_PORT}/{settings.POSTGRES_DB}"