Skip to content

Commit f91f5d2

Browse files
authored
feat: context menu to create a vector index (#3155)
1 parent 81e860e commit f91f5d2

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

src/containers/Tenant/Query/NewSQL/NewSQL.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export function NewSQL() {
7575
text: i18n('action.add-index'),
7676
action: actions.addTableIndex,
7777
},
78+
{
79+
text: i18n('action.add-vector-index'),
80+
action: actions.addVectorIndex,
81+
},
7882
{
7983
text: i18n('action.drop-index'),
8084
action: actions.dropTableIndex,

src/containers/Tenant/Query/NewSQL/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"action.delete-rows": "Delete rows",
1111
"action.drop-table": "Drop table",
1212
"action.add-index": "Add index",
13+
"action.add-vector-index": "Add vector index",
1314
"action.drop-index": "Drop index",
1415
"action.drop-external-table": "Drop external table",
1516
"menu.tables": "Tables",

src/containers/Tenant/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"actions.manageColumns": "Manage columns...",
4545
"actions.manageAutoPartitioning": "Manage auto partitioning...",
4646
"actions.addTableIndex": "Add index...",
47+
"actions.addVectorIndex": "Add vector index...",
4748
"actions.createCdcStream": "Create changefeed...",
4849
"actions.showCreateTable": "Show Create SQL...",
4950
"actions.alterTopic": "Alter topic...",

src/containers/Tenant/utils/newSQLQueryActions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
addTableIndex,
3+
addVectorIndex,
34
alterAsyncReplicationTemplate,
45
alterStreamingQuerySettingsTemplate,
56
alterStreamingQueryText,
@@ -72,6 +73,7 @@ export const bindActions = (changeUserInput: (input: string) => void) => {
7273
revokePrivilege: inputQuery(revokePrivilegeTemplate),
7374
dropUser: inputQuery(dropUserTemplate),
7475
dropGroup: inputQuery(dropGroupTemplate),
76+
addVectorIndex: inputQuery(addVectorIndex),
7577
addTableIndex: inputQuery(addTableIndex),
7678
dropTableIndex: inputQuery(dropTableIndex),
7779
showCreateTable: inputQuery(showCreateTableTemplate),

src/containers/Tenant/utils/schemaActions.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import i18n from '../i18n';
2222
import type {TemplateFn} from './schemaQueryTemplates';
2323
import {
2424
addTableIndex,
25+
addVectorIndex,
2526
alterAsyncReplicationTemplate,
2627
alterStreamingQuerySettingsTemplate,
2728
alterStreamingQueryText,
@@ -152,6 +153,7 @@ const bindActions = (
152153
alterStreamingQueryText: inputQuery(alterStreamingQueryText),
153154
dropStreamingQuery: inputQuery(dropStreamingQueryTemplate),
154155
dropIndex: inputQuery(dropTableIndex),
156+
addVectorIndex: inputQuery(addVectorIndex),
155157
addTableIndex: inputQuery(addTableIndex),
156158
createCdcStream: inputQuery(createCdcStreamTemplate),
157159
copyPath: () => {
@@ -299,6 +301,7 @@ export const getActions =
299301
isLoading: additionalEffects.isSchemaDataLoading,
300302
}),
301303
{text: i18n('actions.addTableIndex'), action: actions.addTableIndex},
304+
{text: i18n('actions.addVectorIndex'), action: actions.addVectorIndex},
302305
{text: i18n('actions.createCdcStream'), action: actions.createCdcStream},
303306
],
304307
[showCreateTableItem],

src/containers/Tenant/utils/schemaQueryTemplates.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,25 @@ export const addTableIndex = (params?: SchemaQueryParams) => {
383383
return `ALTER TABLE ${path} ADD INDEX \${2:index_name} GLOBAL ON (\${3:<column_name>});`;
384384
};
385385

386+
export const addVectorIndex = (params?: SchemaQueryParams) => {
387+
const path = params?.relativePath
388+
? `\`${normalizeParameter(params.relativePath)}\``
389+
: '${1:<my_table>}';
390+
391+
return `-- docs: https://ydb.tech/docs/en/dev/vector-indexes?version=main#types
392+
ALTER TABLE ${path}
393+
ADD INDEX \${2:my_vector_index}
394+
GLOBAL USING vector_kmeans_tree
395+
ON (\${3:embedding})
396+
WITH (
397+
distance=cosine,
398+
vector_type="uint8",
399+
vector_dimension=\${4:512},
400+
levels=\${5:2},
401+
clusters=\${6:128}
402+
);`;
403+
};
404+
386405
export const dropTableIndex = (params?: SchemaQueryParams) => {
387406
const indexName = params?.relativePath.split('/').pop();
388407
const path = params?.relativePath.split('/').slice(0, -1).join('/');

0 commit comments

Comments
 (0)