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:
Souhail Hanfi
2024-03-26 02:25:01 +01:00
committed by GitHub
parent 903541f439
commit cbec43afa9

View File

@@ -235,6 +235,8 @@ class PGVector(VectorStore):
for querying.
It's provided here for backwards compatibility with older versions,
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:
.. code-block:: python
@@ -269,6 +271,7 @@ class PGVector(VectorStore):
connection: Optional[sqlalchemy.engine.Connection] = None,
engine_args: Optional[dict[str, Any]] = None,
use_jsonb: bool = False,
create_extension: bool = True,
) -> None:
"""Initialize the PGVector store."""
self.connection_string = connection_string
@@ -283,6 +286,7 @@ class PGVector(VectorStore):
self.engine_args = engine_args or {}
self._bind = connection if connection else self._create_engine()
self.use_jsonb = use_jsonb
self.create_extension = create_extension
if not use_jsonb:
# Replace with a deprecation warning.
@@ -311,6 +315,7 @@ class PGVector(VectorStore):
self,
) -> None:
"""Initialize the store."""
if self.create_extension:
self.create_vector_extension()
EmbeddingStore, CollectionStore = _get_embedding_collection_store(