Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Move create schema calls into their own transaction #831

davidmezzetti0354e2bef390
diff --git a/src/python/txtai/ann/pgvector.py b/src/python/txtai/ann/pgvector.py
index a94ff6e0..24677718 100644
--- a/src/python/txtai/ann/pgvector.py
+++ b/src/python/txtai/ann/pgvector.py
@@ -104,7 +104,9 @@ class PGVector(ANN):
# Set default schema, if necessary
schema = self.setting("schema")
if schema:
- self.sqldialect(CreateSchema(schema, if_not_exists=True))
+ with self.engine.begin():
+ self.sqldialect(CreateSchema(schema, if_not_exists=True))
+
self.sqldialect(text("SET search_path TO :schema,public"), {"schema": schema})
# Table name
diff --git a/src/python/txtai/database/client.py b/src/python/txtai/database/client.py
index da671510..25efe7ad 100644
--- a/src/python/txtai/database/client.py
+++ b/src/python/txtai/database/client.py
@@ -139,7 +139,9 @@ class Client(RDBMS):
# Set default schema, if necessary
schema = self.config.get("schema")
if schema:
- self.sqldialect(database, CreateSchema(schema, if_not_exists=True))
+ with self.engine.begin():
+ self.sqldialect(database, CreateSchema(schema, if_not_exists=True))
+
self.sqldialect(database, textsql("SET search_path TO :schema"), {"schema": schema})
return database
diff --git a/src/python/txtai/graph/rdbms.py b/src/python/txtai/graph/rdbms.py
index 4417afae..564575aa 100644
--- a/src/python/txtai/graph/rdbms.py
+++ b/src/python/txtai/graph/rdbms.py
@@ -95,7 +95,7 @@ class RDBMS(NetworkX):
if schema:
# Check that schema exists
engine = create_engine(url)
- with engine.connect() as connection:
+ with engine.begin() as connection:
connection.execute(CreateSchema(schema, if_not_exists=True) if "postgresql" in url else text("SELECT 1"))
# Set default schema
diff --git a/src/python/txtai/scoring/pgtext.py b/src/python/txtai/scoring/pgtext.py
index 07f82778..4569151a 100644
--- a/src/python/txtai/scoring/pgtext.py
+++ b/src/python/txtai/scoring/pgtext.py
@@ -131,7 +131,9 @@ class PGText(Scoring):
# Set default schema, if necessary
schema = self.config.get("schema")
if schema:
- self.sqldialect(CreateSchema(schema, if_not_exists=True))
+ with self.engine.begin():
+ self.sqldialect(CreateSchema(schema, if_not_exists=True))
+
self.sqldialect(text("SET search_path TO :schema"), {"schema": schema})
# Table name