@@ -215,9 +215,13 @@ def __init__(
215215 embeddings : Embeddings | None = None ,
216216 cross_encoder : CrossEncoderModel | None = None ,
217217 query_analyzer : QueryAnalyzer | None = None ,
218- pool_min_size : int = 5 ,
219- pool_max_size : int = 100 ,
218+ pool_min_size : int | None = None ,
219+ pool_max_size : int | None = None ,
220+ db_command_timeout : int | None = None ,
221+ db_acquire_timeout : int | None = None ,
220222 task_backend : TaskBackend | None = None ,
223+ task_batch_size : int | None = None ,
224+ task_batch_interval : float | None = None ,
221225 run_migrations : bool = True ,
222226 operation_validator : "OperationValidatorExtension | None" = None ,
223227 tenant_extension : "TenantExtension | None" = None ,
@@ -248,9 +252,13 @@ def __init__(
248252 embeddings: Embeddings implementation. If not provided, created from env vars.
249253 cross_encoder: Cross-encoder model. If not provided, created from env vars.
250254 query_analyzer: Query analyzer implementation. If not provided, uses DateparserQueryAnalyzer.
251- pool_min_size: Minimum number of connections in the pool (default: 5)
252- pool_max_size: Maximum number of connections in the pool (default: 100)
255+ pool_min_size: Minimum number of connections in the pool. Defaults to HINDSIGHT_API_DB_POOL_MIN_SIZE.
256+ pool_max_size: Maximum number of connections in the pool. Defaults to HINDSIGHT_API_DB_POOL_MAX_SIZE.
257+ db_command_timeout: PostgreSQL command timeout in seconds. Defaults to HINDSIGHT_API_DB_COMMAND_TIMEOUT.
258+ db_acquire_timeout: Connection acquisition timeout in seconds. Defaults to HINDSIGHT_API_DB_ACQUIRE_TIMEOUT.
253259 task_backend: Custom task backend. If not provided, uses AsyncIOQueueBackend.
260+ task_batch_size: Background task batch size. Defaults to HINDSIGHT_API_TASK_BATCH_SIZE.
261+ task_batch_interval: Background task batch interval in seconds. Defaults to HINDSIGHT_API_TASK_BATCH_INTERVAL.
254262 run_migrations: Whether to run database migrations during initialize(). Default: True
255263 operation_validator: Optional extension to validate operations before execution.
256264 If provided, retain/recall/reflect operations will be validated.
@@ -306,8 +314,10 @@ def __init__(
306314 # Connection pool (will be created in initialize())
307315 self ._pool = None
308316 self ._initialized = False
309- self ._pool_min_size = pool_min_size
310- self ._pool_max_size = pool_max_size
317+ self ._pool_min_size = pool_min_size if pool_min_size is not None else config .db_pool_min_size
318+ self ._pool_max_size = pool_max_size if pool_max_size is not None else config .db_pool_max_size
319+ self ._db_command_timeout = db_command_timeout if db_command_timeout is not None else config .db_command_timeout
320+ self ._db_acquire_timeout = db_acquire_timeout if db_acquire_timeout is not None else config .db_acquire_timeout
311321 self ._run_migrations = run_migrations
312322
313323 # Initialize entity resolver (will be created in initialize())
@@ -386,7 +396,11 @@ def __init__(
386396 self ._cross_encoder_reranker = CrossEncoderReranker (cross_encoder = cross_encoder )
387397
388398 # Initialize task backend
389- self ._task_backend = task_backend or AsyncIOQueueBackend (batch_size = 100 , batch_interval = 1.0 )
399+ _task_batch_size = task_batch_size if task_batch_size is not None else config .task_batch_size
400+ _task_batch_interval = task_batch_interval if task_batch_interval is not None else config .task_batch_interval
401+ self ._task_backend = task_backend or AsyncIOQueueBackend (
402+ batch_size = _task_batch_size , batch_interval = _task_batch_interval
403+ )
390404
391405 # Backpressure mechanism: limit concurrent searches to prevent overwhelming the database
392406 # Limit concurrent searches to prevent connection pool exhaustion
@@ -731,9 +745,9 @@ async def verify_llm():
731745 self .db_url ,
732746 min_size = self ._pool_min_size ,
733747 max_size = self ._pool_max_size ,
734- command_timeout = 60 ,
748+ command_timeout = self . _db_command_timeout ,
735749 statement_cache_size = 0 , # Disable prepared statement cache
736- timeout = 30 , # Connection acquisition timeout (seconds)
750+ timeout = self . _db_acquire_timeout , # Connection acquisition timeout (seconds)
737751 )
738752
739753 # Initialize entity resolver with pool
0 commit comments