fix: vectorstore pgvector ensure compatibility #3884 (#4248)

Ensure compatibility with both SQLAlchemy v1/v2 

fix the issue when using SQLAlchemy v1 (reported at #3884)

`
langchain/vectorstores/pgvector.py", line 168, in
create_tables_if_not_exists
    self._conn.commit()
AttributeError: 'Connection' object has no attribute 'commit'
`

Ref Doc :
https://docs.sqlalchemy.org/en/14/changelog/migration_20.html#migration-20-autocommit
parallel_dir_loader
玄猫 1 year ago committed by GitHub
parent ba0057c077
commit deffc65693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -164,12 +164,12 @@ class PGVector(VectorStore):
self.logger.exception(e)
def create_tables_if_not_exists(self) -> None:
Base.metadata.create_all(self._conn)
self._conn.commit()
with self._conn.begin():
Base.metadata.create_all(self._conn)
def drop_tables(self) -> None:
Base.metadata.drop_all(self._conn)
self._conn.commit()
with self._conn.begin():
Base.metadata.drop_all(self._conn)
def create_collection(self) -> None:
if self.pre_delete_collection:

Loading…
Cancel
Save