mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-30 11:39:03 +00:00
feat: acquire advisory lock before creating extension in pgvector (#12935)
- **Description:** Acquire advisory lock before attempting to create extension on postgres server, preventing errors in concurrent executions. - **Issue:** #12933 - **Dependencies:** None --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
b376854b26
commit
59d0bd2150
@ -159,7 +159,17 @@ class PGVector(VectorStore):
|
||||
def create_vector_extension(self) -> None:
|
||||
try:
|
||||
with Session(self._conn) as session:
|
||||
statement = sqlalchemy.text("CREATE EXTENSION IF NOT EXISTS vector")
|
||||
# The advisor lock fixes issue arising from concurrent
|
||||
# creation of the vector extension.
|
||||
# https://github.com/langchain-ai/langchain/issues/12933
|
||||
# For more information see:
|
||||
# https://www.postgresql.org/docs/16/explicit-locking.html#ADVISORY-LOCKS
|
||||
statement = sqlalchemy.text(
|
||||
"BEGIN;"
|
||||
"SELECT pg_advisory_xact_lock(1573678846307946496);"
|
||||
"CREATE EXTENSION IF NOT EXISTS vector;"
|
||||
"COMMIT;"
|
||||
)
|
||||
session.execute(statement)
|
||||
session.commit()
|
||||
except Exception as e:
|
||||
|
Loading…
Reference in New Issue
Block a user