From ca8ac882d3e33225b8f7481f1f70cba3b353c679 Mon Sep 17 00:00:00 2001 From: Anton Standrik Date: Tue, 2 Dec 2025 13:22:35 +0300 Subject: [PATCH 1/2] feat: context menu to create a vector index --- src/containers/Tenant/Query/NewSQL/NewSQL.tsx | 4 ++++ .../Tenant/Query/NewSQL/i18n/en.json | 1 + src/containers/Tenant/i18n/en.json | 1 + .../Tenant/utils/newSQLQueryActions.ts | 2 ++ src/containers/Tenant/utils/schemaActions.tsx | 3 +++ .../Tenant/utils/schemaQueryTemplates.ts | 19 +++++++++++++++++++ 6 files changed, 30 insertions(+) diff --git a/src/containers/Tenant/Query/NewSQL/NewSQL.tsx b/src/containers/Tenant/Query/NewSQL/NewSQL.tsx index 0c9f8fee24..722f2b7993 100644 --- a/src/containers/Tenant/Query/NewSQL/NewSQL.tsx +++ b/src/containers/Tenant/Query/NewSQL/NewSQL.tsx @@ -75,6 +75,10 @@ export function NewSQL() { text: i18n('action.add-index'), action: actions.addTableIndex, }, + { + text: i18n('action.add-vector-index'), + action: actions.addVectorIndex, + }, { text: i18n('action.drop-index'), action: actions.dropTableIndex, diff --git a/src/containers/Tenant/Query/NewSQL/i18n/en.json b/src/containers/Tenant/Query/NewSQL/i18n/en.json index 36d81f767d..a0407be59c 100644 --- a/src/containers/Tenant/Query/NewSQL/i18n/en.json +++ b/src/containers/Tenant/Query/NewSQL/i18n/en.json @@ -10,6 +10,7 @@ "action.delete-rows": "Delete rows", "action.drop-table": "Drop table", "action.add-index": "Add index", + "action.add-vector-index": "Add vector index", "action.drop-index": "Drop index", "action.drop-external-table": "Drop external table", "menu.tables": "Tables", diff --git a/src/containers/Tenant/i18n/en.json b/src/containers/Tenant/i18n/en.json index 502e0e7228..5241e1f774 100644 --- a/src/containers/Tenant/i18n/en.json +++ b/src/containers/Tenant/i18n/en.json @@ -44,6 +44,7 @@ "actions.manageColumns": "Manage columns...", "actions.manageAutoPartitioning": "Manage auto partitioning...", "actions.addTableIndex": "Add index...", + "actions.addVectorIndex": "Add vector index...", "actions.createCdcStream": "Create changefeed...", "actions.showCreateTable": "Show Create SQL...", "actions.alterTopic": "Alter topic...", diff --git a/src/containers/Tenant/utils/newSQLQueryActions.ts b/src/containers/Tenant/utils/newSQLQueryActions.ts index 06e6540b7d..55fad6591d 100644 --- a/src/containers/Tenant/utils/newSQLQueryActions.ts +++ b/src/containers/Tenant/utils/newSQLQueryActions.ts @@ -1,5 +1,6 @@ import { addTableIndex, + addVectorIndexTemplate, alterAsyncReplicationTemplate, alterStreamingQuerySettingsTemplate, alterStreamingQueryText, @@ -72,6 +73,7 @@ export const bindActions = (changeUserInput: (input: string) => void) => { revokePrivilege: inputQuery(revokePrivilegeTemplate), dropUser: inputQuery(dropUserTemplate), dropGroup: inputQuery(dropGroupTemplate), + addVectorIndex: inputQuery(addVectorIndexTemplate), addTableIndex: inputQuery(addTableIndex), dropTableIndex: inputQuery(dropTableIndex), showCreateTable: inputQuery(showCreateTableTemplate), diff --git a/src/containers/Tenant/utils/schemaActions.tsx b/src/containers/Tenant/utils/schemaActions.tsx index 0be1df5af5..d46a6517be 100644 --- a/src/containers/Tenant/utils/schemaActions.tsx +++ b/src/containers/Tenant/utils/schemaActions.tsx @@ -22,6 +22,7 @@ import i18n from '../i18n'; import type {TemplateFn} from './schemaQueryTemplates'; import { addTableIndex, + addVectorIndexTemplate, alterAsyncReplicationTemplate, alterStreamingQuerySettingsTemplate, alterStreamingQueryText, @@ -152,6 +153,7 @@ const bindActions = ( alterStreamingQueryText: inputQuery(alterStreamingQueryText), dropStreamingQuery: inputQuery(dropStreamingQueryTemplate), dropIndex: inputQuery(dropTableIndex), + addVectorIndex: inputQuery(addVectorIndexTemplate), addTableIndex: inputQuery(addTableIndex), createCdcStream: inputQuery(createCdcStreamTemplate), copyPath: () => { @@ -299,6 +301,7 @@ export const getActions = isLoading: additionalEffects.isSchemaDataLoading, }), {text: i18n('actions.addTableIndex'), action: actions.addTableIndex}, + {text: i18n('actions.addVectorIndex'), action: actions.addVectorIndex}, {text: i18n('actions.createCdcStream'), action: actions.createCdcStream}, ], [showCreateTableItem], diff --git a/src/containers/Tenant/utils/schemaQueryTemplates.ts b/src/containers/Tenant/utils/schemaQueryTemplates.ts index 521d28027d..964da9a21c 100644 --- a/src/containers/Tenant/utils/schemaQueryTemplates.ts +++ b/src/containers/Tenant/utils/schemaQueryTemplates.ts @@ -385,6 +385,25 @@ export const addTableIndex = (params?: SchemaQueryParams) => { return `ALTER TABLE ${path} ADD INDEX \${2:index_name} GLOBAL ON (\${3:});`; }; +export const addVectorIndexTemplate = (params?: SchemaQueryParams) => { + const path = params?.relativePath + ? `\`${normalizeParameter(params.relativePath)}\`` + : '${2:}'; + + return `-- docs: https://ydb.tech/docs/en/dev/vector-indexes?version=main#types +ALTER TABLE ${path} +ADD INDEX \${1:my_vector_index} +GLOBAL USING vector_kmeans_tree +ON (\${3:embedding}) +WITH ( + distance=cosine, + vector_type="uint8", + vector_dimension=\${4:512}, + levels=\${5:2}, + clusters=\${6:128} +);`; +}; + export const dropTableIndex = (params?: SchemaQueryParams) => { const indexName = params?.relativePath.split('/').pop(); const path = params?.relativePath.split('/').slice(0, -1).join('/'); From b8f3ee83c9950d2b9d5aa4e3ec69ed81ff328de3 Mon Sep 17 00:00:00 2001 From: Anton Standrik Date: Tue, 2 Dec 2025 13:29:55 +0300 Subject: [PATCH 2/2] fix: review fixes --- src/containers/Tenant/utils/newSQLQueryActions.ts | 4 ++-- src/containers/Tenant/utils/schemaActions.tsx | 4 ++-- src/containers/Tenant/utils/schemaQueryTemplates.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/containers/Tenant/utils/newSQLQueryActions.ts b/src/containers/Tenant/utils/newSQLQueryActions.ts index 55fad6591d..fd5f1a627a 100644 --- a/src/containers/Tenant/utils/newSQLQueryActions.ts +++ b/src/containers/Tenant/utils/newSQLQueryActions.ts @@ -1,6 +1,6 @@ import { addTableIndex, - addVectorIndexTemplate, + addVectorIndex, alterAsyncReplicationTemplate, alterStreamingQuerySettingsTemplate, alterStreamingQueryText, @@ -73,7 +73,7 @@ export const bindActions = (changeUserInput: (input: string) => void) => { revokePrivilege: inputQuery(revokePrivilegeTemplate), dropUser: inputQuery(dropUserTemplate), dropGroup: inputQuery(dropGroupTemplate), - addVectorIndex: inputQuery(addVectorIndexTemplate), + addVectorIndex: inputQuery(addVectorIndex), addTableIndex: inputQuery(addTableIndex), dropTableIndex: inputQuery(dropTableIndex), showCreateTable: inputQuery(showCreateTableTemplate), diff --git a/src/containers/Tenant/utils/schemaActions.tsx b/src/containers/Tenant/utils/schemaActions.tsx index d46a6517be..77faa5ccf5 100644 --- a/src/containers/Tenant/utils/schemaActions.tsx +++ b/src/containers/Tenant/utils/schemaActions.tsx @@ -22,7 +22,7 @@ import i18n from '../i18n'; import type {TemplateFn} from './schemaQueryTemplates'; import { addTableIndex, - addVectorIndexTemplate, + addVectorIndex, alterAsyncReplicationTemplate, alterStreamingQuerySettingsTemplate, alterStreamingQueryText, @@ -153,7 +153,7 @@ const bindActions = ( alterStreamingQueryText: inputQuery(alterStreamingQueryText), dropStreamingQuery: inputQuery(dropStreamingQueryTemplate), dropIndex: inputQuery(dropTableIndex), - addVectorIndex: inputQuery(addVectorIndexTemplate), + addVectorIndex: inputQuery(addVectorIndex), addTableIndex: inputQuery(addTableIndex), createCdcStream: inputQuery(createCdcStreamTemplate), copyPath: () => { diff --git a/src/containers/Tenant/utils/schemaQueryTemplates.ts b/src/containers/Tenant/utils/schemaQueryTemplates.ts index 964da9a21c..c34a204a50 100644 --- a/src/containers/Tenant/utils/schemaQueryTemplates.ts +++ b/src/containers/Tenant/utils/schemaQueryTemplates.ts @@ -385,14 +385,14 @@ export const addTableIndex = (params?: SchemaQueryParams) => { return `ALTER TABLE ${path} ADD INDEX \${2:index_name} GLOBAL ON (\${3:});`; }; -export const addVectorIndexTemplate = (params?: SchemaQueryParams) => { +export const addVectorIndex = (params?: SchemaQueryParams) => { const path = params?.relativePath ? `\`${normalizeParameter(params.relativePath)}\`` - : '${2:}'; + : '${1:}'; return `-- docs: https://ydb.tech/docs/en/dev/vector-indexes?version=main#types ALTER TABLE ${path} -ADD INDEX \${1:my_vector_index} +ADD INDEX \${2:my_vector_index} GLOBAL USING vector_kmeans_tree ON (\${3:embedding}) WITH (