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..fd5f1a627a 100644 --- a/src/containers/Tenant/utils/newSQLQueryActions.ts +++ b/src/containers/Tenant/utils/newSQLQueryActions.ts @@ -1,5 +1,6 @@ import { addTableIndex, + addVectorIndex, 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(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 0be1df5af5..77faa5ccf5 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, + addVectorIndex, alterAsyncReplicationTemplate, alterStreamingQuerySettingsTemplate, alterStreamingQueryText, @@ -152,6 +153,7 @@ const bindActions = ( alterStreamingQueryText: inputQuery(alterStreamingQueryText), dropStreamingQuery: inputQuery(dropStreamingQueryTemplate), dropIndex: inputQuery(dropTableIndex), + addVectorIndex: inputQuery(addVectorIndex), 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..c34a204a50 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 addVectorIndex = (params?: SchemaQueryParams) => { + const path = params?.relativePath + ? `\`${normalizeParameter(params.relativePath)}\`` + : '${1:}'; + + return `-- docs: https://ydb.tech/docs/en/dev/vector-indexes?version=main#types +ALTER TABLE ${path} +ADD INDEX \${2: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('/');