Package com.cockroachlabs.data.ddl
Class VectorIndexHelper
java.lang.Object
com.cockroachlabs.data.ddl.VectorIndexHelper
Generates CockroachDB v26.2+
CREATE VECTOR INDEX DDL.
In CockroachDB v26.2, the legacy CREATE INDEX ... USING cspann syntax
is replaced by the dedicated CREATE VECTOR INDEX statement, which
supports prefix columns for pre-filtered vector searches.
Migration from v24.x / v25.x:
-- Old (v24.x/v25.x): CREATE INDEX idx ON docs USING cspann (embedding vector_cosine_ops); -- New (v26.2+): CREATE VECTOR INDEX idx ON docs (embedding vector_cosine_ops); -- With prefix columns (v26.2+): CREATE VECTOR INDEX idx ON docs (tenant_id, embedding vector_cosine_ops);
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringGenerate the cluster setting statement to enable vector indexes (v26.2+).static StringgenerateCreateCspannIndex(String indexName, String tableName, String vectorColumn, DistanceMetric metric) Generate the legacy v24.x/v25.xCREATE INDEX ... USING cspannstatement.static StringgenerateCreateVectorIndex(String indexName, String tableName, String vectorColumn, DistanceMetric metric, String... prefixColumns) Generate a v26.2-compatibleCREATE VECTOR INDEXstatement.static StringgenerateDropIndex(String indexName) Generate aDROP INDEX IF EXISTSstatement for a vector index.static StringsetBeamSize(int beamSize) Generate the session-level beam size setting.
-
Method Details
-
generateCreateVectorIndex
public static String generateCreateVectorIndex(String indexName, String tableName, String vectorColumn, DistanceMetric metric, String... prefixColumns) Generate a v26.2-compatibleCREATE VECTOR INDEXstatement.- Parameters:
indexName- the index nametableName- the table containing the vector columnvectorColumn- the column holding VECTOR datametric- the distance metric (determines the opclass)prefixColumns- optional prefix columns for pre-filtering (may be empty)- Returns:
- the DDL statement
-
generateCreateCspannIndex
public static String generateCreateCspannIndex(String indexName, String tableName, String vectorColumn, DistanceMetric metric) Generate the legacy v24.x/v25.xCREATE INDEX ... USING cspannstatement. Provided for backward compatibility.- Parameters:
indexName- the index nametableName- the table containing the vector columnvectorColumn- the column holding VECTOR datametric- the distance metric- Returns:
- the DDL statement
-
generateDropIndex
Generate aDROP INDEX IF EXISTSstatement for a vector index.- Parameters:
indexName- the index to drop- Returns:
- the DDL statement
-
enableVectorIndexSetting
Generate the cluster setting statement to enable vector indexes (v26.2+).- Returns:
- the
SET CLUSTER SETTINGstatement
-
setBeamSize
Generate the session-level beam size setting.- Parameters:
beamSize- the desired beam size (must be > 0)- Returns:
- the
SETstatement - Throws:
IllegalArgumentException- if beamSize is not positive
-