From 2b8276f71a8aba00549fc0fb545567306af2f3ec Mon Sep 17 00:00:00 2001 From: Felipe Gutierrez Date: Thu, 19 Nov 2026 13:53:37 -0500 Subject: [PATCH] fix(ai): run SET CLUSTER SETTING outside the ensure_table transaction ensure_table() issued `SET CLUSTER SETTING feature.vector_index.enabled` on the same connection as CREATE TABLE / CREATE VECTOR INDEX. psycopg3 wraps those statements in one transaction, and CockroachDB rejects `SET CLUSTER SETTING cannot be used inside a multi-statement transaction`, so ensure_table() failed before the table was ever created. Enable the feature on its own autocommit connection first, then run the table + index DDL in the normal transaction. Behaviour is otherwise unchanged; the mocked vector_store tests still pass. Also make the semantic example IT deterministic: default CRDB_VECTOR_IMAGE to a vector-index-capable image (latest-v26.2) so CREATE VECTOR INDEX actually runs, and broaden the skip guard to also treat "unimplemented" feature errors as a graceful skip. Bump cockroachdb-ai to 0.1.2. --- examples/ideas-board/test_semantic_it.py | 13 ++++++++----- packages/cockroachdb-ai/pyproject.toml | 2 +- .../src/cockroachdb/ai/vector_store.py | 8 ++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/ideas-board/test_semantic_it.py b/examples/ideas-board/test_semantic_it.py index e3116be..1090e43 100644 --- a/examples/ideas-board/test_semantic_it.py +++ b/examples/ideas-board/test_semantic_it.py @@ -2,9 +2,9 @@ The native ``VECTOR`` type requires v25.2+; ``ensure_table()`` also issues ``CREATE VECTOR INDEX`` (v26.2+). Boots the image named by ``CRDB_VECTOR_IMAGE`` -(default ``cockroachdb/cockroach:latest-v25.2``). Skips cleanly when Docker is +(default ``cockroachdb/cockroach:latest-v26.2``). Skips cleanly when Docker is unavailable, and skips honestly (rather than faking a pass) if the chosen image -lacks VECTOR support. Mirrors the Java ``SemanticSearchIT``. +lacks VECTOR/vector-index support. Mirrors the Java ``SemanticSearchIT``. """ from __future__ import annotations @@ -17,7 +17,7 @@ from cockroachdb.ai import Document -IMAGE = os.environ.get("CRDB_VECTOR_IMAGE", "cockroachdb/cockroach:latest-v25.2") +IMAGE = os.environ.get("CRDB_VECTOR_IMAGE", "cockroachdb/cockroach:latest-v26.2") # Four deterministic 3-dim vectors pointing in distinct directions. DOCS = { @@ -44,8 +44,11 @@ def dsn() -> str: def _skip_if_no_vector(exc: Exception) -> None: - if "vector" in str(exc).lower(): - pytest.skip(f"VECTOR unsupported on {IMAGE}: {exc}") + msg = str(exc).lower() + # VECTOR type / CREATE VECTOR INDEX absent on this image surfaces as a + # message mentioning "vector", or a generic "unimplemented" feature error. + if "vector" in msg or "unimplemented" in msg: + pytest.skip(f"VECTOR/vector-index unsupported on {IMAGE}: {exc}") raise exc diff --git a/packages/cockroachdb-ai/pyproject.toml b/packages/cockroachdb-ai/pyproject.toml index ef4a935..929942c 100644 --- a/packages/cockroachdb-ai/pyproject.toml +++ b/packages/cockroachdb-ai/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "cockroachdb-ai" -version = "0.1.1" +version = "0.1.2" description = "CockroachDB AI — vector search, RAG pipelines, and embedding providers for pgvector" readme = "README.md" requires-python = ">=3.11" diff --git a/packages/cockroachdb-ai/src/cockroachdb/ai/vector_store.py b/packages/cockroachdb-ai/src/cockroachdb/ai/vector_store.py index b20df85..c8c949d 100644 --- a/packages/cockroachdb-ai/src/cockroachdb/ai/vector_store.py +++ b/packages/cockroachdb-ai/src/cockroachdb/ai/vector_store.py @@ -274,10 +274,14 @@ def ensure_table(self) -> None: the session-level ``vector_search_beam_size``. """ dimensions = self._config.embedding_dimensions - with psycopg.connect(self._conninfo) as conn: - # Enable vector index feature (required for CREATE VECTOR INDEX) + + # SET CLUSTER SETTING cannot run inside a multi-statement transaction, + # so enable the vector-index feature on its own autocommit connection + # before the CREATE TABLE / CREATE VECTOR INDEX transaction below. + with psycopg.connect(self._conninfo, autocommit=True) as conn: conn.execute("SET CLUSTER SETTING feature.vector_index.enabled = true") + with psycopg.connect(self._conninfo) as conn: conn.execute( f""" CREATE TABLE IF NOT EXISTS {self._table} (