Skip to content

Commit 5e224a3

Browse files
committed
feat: vector index parameters on Info tab
1 parent acbff26 commit 5e224a3

File tree

5 files changed

+111
-8
lines changed

5 files changed

+111
-8
lines changed

src/components/InfoViewer/formatters/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export const formatTableIndexItem = createInfoFormatter<TIndexDescription>({
1313
labels: {
1414
KeyColumnNames: 'Columns',
1515
DataColumnNames: 'Includes',
16+
DataSize: 'Data Size',
1617
},
1718
});
Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import type {InfoViewerItem} from '..';
22
import {InfoViewer} from '..';
33
import {getEntityName} from '../../../containers/Tenant/utils';
4-
import type {TEvDescribeSchemeResult, TIndexDescription} from '../../../types/api/schema';
4+
import type {TEvDescribeSchemeResult} from '../../../types/api/schema';
5+
import {formatNumber} from '../../../utils/dataFormatters/dataFormatters';
56
import {formatTableIndexItem} from '../formatters';
7+
import {createInfoFormatter} from '../utils';
68

7-
const DISPLAYED_FIELDS: Set<keyof TIndexDescription> = new Set([
9+
import i18n from './i18n';
10+
11+
const DISPLAYED_FIELDS_KEYS = [
812
'Type',
913
'State',
1014
'DataSize',
1115
'KeyColumnNames',
1216
'DataColumnNames',
13-
]);
17+
] as const;
18+
type DisplayedIndexField = (typeof DISPLAYED_FIELDS_KEYS)[number];
19+
const DISPLAYED_FIELDS = new Set<DisplayedIndexField>(DISPLAYED_FIELDS_KEYS);
1420

1521
interface TableIndexInfoProps {
1622
data?: TEvDescribeSchemeResult;
@@ -26,12 +32,71 @@ export const TableIndexInfo = ({data}: TableIndexInfoProps) => {
2632
const TableIndex = data.PathDescription?.TableIndex;
2733
const info: Array<InfoViewerItem> = [];
2834

29-
let key: keyof TIndexDescription;
30-
for (key in TableIndex) {
31-
if (DISPLAYED_FIELDS.has(key)) {
32-
info.push(formatTableIndexItem(key, TableIndex?.[key]));
35+
if (TableIndex) {
36+
DISPLAYED_FIELDS.forEach((key: DisplayedIndexField) => {
37+
const value = TableIndex[key];
38+
if (value !== undefined) {
39+
info.push(formatTableIndexItem(key, value));
40+
}
41+
});
42+
}
43+
44+
const vectorSettings = TableIndex?.VectorIndexKmeansTreeDescription?.Settings;
45+
46+
if (!vectorSettings) {
47+
return <InfoViewer title={entityName} info={info} />;
48+
}
49+
50+
const vectorFormatter = createInfoFormatter<{clusters?: number; levels?: number}>({
51+
values: {
52+
clusters: (v) => (typeof v === 'number' ? formatNumber(v) : v),
53+
levels: (v) => (typeof v === 'number' ? formatNumber(v) : v),
54+
},
55+
labels: {
56+
clusters: i18n('field_clusters'),
57+
levels: i18n('field_levels'),
58+
},
59+
});
60+
61+
const vectorSettingsFormatter = createInfoFormatter<{
62+
vector_dimension?: number;
63+
vector_type?: string;
64+
metric?: string;
65+
}>({
66+
values: {
67+
vector_dimension: (v) => (typeof v === 'number' ? formatNumber(v) : v),
68+
},
69+
labels: {
70+
vector_dimension: i18n('field_vector-dimension'),
71+
vector_type: i18n('field_vector-type'),
72+
metric: i18n('field_metric'),
73+
},
74+
});
75+
76+
const vectorInfo: Array<InfoViewerItem> = [];
77+
if ('clusters' in vectorSettings) {
78+
vectorInfo.push(vectorFormatter('clusters', vectorSettings.clusters));
79+
}
80+
if ('levels' in vectorSettings) {
81+
vectorInfo.push(vectorFormatter('levels', vectorSettings.levels));
82+
}
83+
if (vectorSettings.settings) {
84+
const settings = vectorSettings.settings;
85+
if ('vector_dimension' in settings) {
86+
vectorInfo.push(vectorSettingsFormatter('vector_dimension', settings.vector_dimension));
87+
}
88+
if ('vector_type' in settings) {
89+
vectorInfo.push(vectorSettingsFormatter('vector_type', settings.vector_type));
90+
}
91+
if ('metric' in settings) {
92+
vectorInfo.push(vectorSettingsFormatter('metric', settings.metric));
3393
}
3494
}
3595

36-
return <InfoViewer title={entityName} info={info} />;
96+
return (
97+
<>
98+
<InfoViewer title={entityName} info={info} />
99+
<InfoViewer title={i18n('title_vector-index')} info={vectorInfo} />
100+
</>
101+
);
37102
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"title_vector-index": "Vector Index",
3+
"field_clusters": "Clusters",
4+
"field_levels": "Levels",
5+
"field_vector-dimension": "Vector Dimension",
6+
"field_vector-type": "Vector Type",
7+
"field_metric": "Metric"
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {registerKeysets} from '../../../../utils/i18n';
2+
3+
import en from './en.json';
4+
5+
const COMPONENT = 'info-viewer-schema-index-info';
6+
7+
export default registerKeysets(COMPONENT, {en});

src/types/api/schema/tableIndex.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ export interface TIndexDescription {
1919
DataColumnNames?: string[];
2020
/** uint64 */
2121
DataSize?: string;
22+
23+
/**
24+
* Present for vector indexes of type EIndexTypeGlobalVectorKmeansTree
25+
*/
26+
VectorIndexKmeansTreeDescription?: TVectorIndexKmeansTreeDescription;
2227
}
2328

2429
enum EIndexType {
2530
EIndexTypeInvalid = 'EIndexTypeInvalid',
2631
EIndexTypeGlobal = 'EIndexTypeGlobal',
2732
EIndexTypeGlobalAsync = 'EIndexTypeGlobalAsync',
33+
EIndexTypeGlobalVectorKmeansTree = 'EIndexTypeGlobalVectorKmeansTree',
2834
}
2935

3036
enum EIndexState {
@@ -33,3 +39,19 @@ enum EIndexState {
3339
EIndexStateNotReady = 'EIndexStateNotReady',
3440
EIndexStateWriteOnly = 'EIndexStateWriteOnly',
3541
}
42+
43+
export interface TVectorIndexKmeansTreeDescriptionSettingsInner {
44+
vector_dimension?: number;
45+
vector_type?: string;
46+
metric?: string;
47+
}
48+
49+
export interface TVectorIndexKmeansTreeDescriptionSettings {
50+
clusters?: number;
51+
levels?: number;
52+
settings?: TVectorIndexKmeansTreeDescriptionSettingsInner;
53+
}
54+
55+
export interface TVectorIndexKmeansTreeDescription {
56+
Settings?: TVectorIndexKmeansTreeDescriptionSettings;
57+
}

0 commit comments

Comments
 (0)