mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 13:54:48 +00:00
optional reusable connection (#12051)
My postgres out of connections after continuous PGVector usage, and the reason because it constantly creates new connections, so adding a reusable pre established connection seems like solves an issue --------- Co-authored-by: Roman Vasilyev <rvasilyev@mozilla.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
48fde2004f
commit
2c58dca5f0
@ -116,6 +116,7 @@ class PGVector(VectorStore):
|
||||
logger: Optional[logging.Logger] = None,
|
||||
relevance_score_fn: Optional[Callable[[float], float]] = None,
|
||||
*,
|
||||
connection: Optional[sqlalchemy.engine.Connection] = None,
|
||||
engine_args: Optional[dict[str, Any]] = None,
|
||||
) -> None:
|
||||
self.connection_string = connection_string
|
||||
@ -127,15 +128,13 @@ class PGVector(VectorStore):
|
||||
self.logger = logger or logging.getLogger(__name__)
|
||||
self.override_relevance_score_fn = relevance_score_fn
|
||||
self.engine_args = engine_args or {}
|
||||
self.__post_init__()
|
||||
# Create a connection if not provided, otherwise use the provided connection
|
||||
self._conn = connection if connection else self.connect()
|
||||
|
||||
def __post_init__(
|
||||
self,
|
||||
) -> None:
|
||||
"""
|
||||
Initialize the store.
|
||||
"""
|
||||
self._conn = self.connect()
|
||||
"""Initialize the store."""
|
||||
self.create_vector_extension()
|
||||
from langchain.vectorstores._pgvector_data_models import (
|
||||
CollectionStore,
|
||||
|
Loading…
Reference in New Issue
Block a user