mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 08:03:39 +00:00
community[patch]: avoid creating extension PGvector while using readOnly Databases (#19268)
- **Description:** PgVector class always runs "create extension" on init and this statement crashes on ReadOnly databases (read only replicas). but wierdly the next create collection etc work even in readOnly databases - **Dependencies:** no new dependencies - **Twitter handle:** @VenOmaX666 Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
parent
903541f439
commit
cbec43afa9
@ -235,6 +235,8 @@ class PGVector(VectorStore):
|
|||||||
for querying.
|
for querying.
|
||||||
It's provided here for backwards compatibility with older versions,
|
It's provided here for backwards compatibility with older versions,
|
||||||
and will be removed in the future.
|
and will be removed in the future.
|
||||||
|
create_extension: If True, will create the vector extension if it doesn't exist.
|
||||||
|
disabling creation is useful when using ReadOnly Databases.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
@ -269,6 +271,7 @@ class PGVector(VectorStore):
|
|||||||
connection: Optional[sqlalchemy.engine.Connection] = None,
|
connection: Optional[sqlalchemy.engine.Connection] = None,
|
||||||
engine_args: Optional[dict[str, Any]] = None,
|
engine_args: Optional[dict[str, Any]] = None,
|
||||||
use_jsonb: bool = False,
|
use_jsonb: bool = False,
|
||||||
|
create_extension: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the PGVector store."""
|
"""Initialize the PGVector store."""
|
||||||
self.connection_string = connection_string
|
self.connection_string = connection_string
|
||||||
@ -283,6 +286,7 @@ class PGVector(VectorStore):
|
|||||||
self.engine_args = engine_args or {}
|
self.engine_args = engine_args or {}
|
||||||
self._bind = connection if connection else self._create_engine()
|
self._bind = connection if connection else self._create_engine()
|
||||||
self.use_jsonb = use_jsonb
|
self.use_jsonb = use_jsonb
|
||||||
|
self.create_extension = create_extension
|
||||||
|
|
||||||
if not use_jsonb:
|
if not use_jsonb:
|
||||||
# Replace with a deprecation warning.
|
# Replace with a deprecation warning.
|
||||||
@ -311,7 +315,8 @@ class PGVector(VectorStore):
|
|||||||
self,
|
self,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the store."""
|
"""Initialize the store."""
|
||||||
self.create_vector_extension()
|
if self.create_extension:
|
||||||
|
self.create_vector_extension()
|
||||||
|
|
||||||
EmbeddingStore, CollectionStore = _get_embedding_collection_store(
|
EmbeddingStore, CollectionStore = _get_embedding_collection_store(
|
||||||
self._embedding_length, use_jsonb=self.use_jsonb
|
self._embedding_length, use_jsonb=self.use_jsonb
|
||||||
|
Loading…
Reference in New Issue
Block a user