Pooling¶
deep_db_agents.pooling ¶
Client-side reuse of drivers that are already thread-safe connection pools.
The MongoDB (MongoClient), Neo4j (Driver), and Elasticsearch/OpenSearch drivers
internally manage a connection pool and expose a thread-safe client object: recreating
it on every tool call would pay an unnecessary TCP/TLS/auth handshake. LazyClient
keeps a single instance per dialect (i.e. per agent), initialized lazily and in a
thread-safe way.
DB-API 2.0 SQL drivers (pymysql, psycopg), on the other hand, remain connection-per-call: the connection is not thread-safe and tool calls may run in parallel.
LazyClient ¶
LazyClient()
Thread-safe container for a reusable driver client, initialized on first use.
Initialize an empty, not-yet-built client container.
Source code in src/deep_db_agents/pooling.py
24 25 26 27 | |
close ¶
close() -> None
Close and forget the client, if present (idempotent).
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in src/deep_db_agents/pooling.py
45 46 47 48 49 50 51 52 53 54 | |
get ¶
get(factory: Callable[[], Any]) -> Any
Return the cached client, building it with factory on the first call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factory
|
Callable[[], Any]
|
Zero-argument callable that constructs the client. Only invoked once, on the first call to this method. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The cached (or newly built) client instance. |
Source code in src/deep_db_agents/pooling.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |