Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support functions #714

Merged
merged 13 commits into from
Dec 17, 2024
1 change: 1 addition & 0 deletions client/src/components/status/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type StatusActionType = {
action?: Function;
onIndexCreate?: Function;
showExtraAction?: boolean;
showLoadButton?: boolean;
collection: CollectionObject;
createIndexElement?: React.ReactNode;
};
34 changes: 28 additions & 6 deletions client/src/consts/Milvus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@ export const MILVUS_DATABASE =
export const DYNAMIC_FIELD = `$meta`;

export enum DataTypeEnum {
None = 0,
Bool = 1,
Int8 = 2,
Int16 = 3,
Int32 = 4,
Int64 = 5,

Float = 10,
Double = 11,
String = 20,
VarChar = 21,

// String = 20,
VarChar = 21, // variable-length strings with a specified maximum length
Array = 22,
JSON = 23,

BinaryVector = 100,
FloatVector = 101,
Float16Vector = 102,
SparseFloatVector = 104,
BFloat16Vector = 103,
Array = 22,
SparseFloatVector = 104,
VarCharBM25 = 1000,
}

export const VectorTypes = [
DataTypeEnum.BinaryVector,
DataTypeEnum.FloatVector,
DataTypeEnum.BFloat16Vector,
DataTypeEnum.BinaryVector,
DataTypeEnum.Float16Vector,
DataTypeEnum.BFloat16Vector,
DataTypeEnum.SparseFloatVector,
];

Expand Down Expand Up @@ -64,6 +69,7 @@ export enum METRIC_TYPES_VALUES {
TANIMOTO = 'TANIMOTO',
SUBSTRUCTURE = 'SUBSTRUCTURE',
SUPERSTRUCTURE = 'SUPERSTRUCTURE',
BM25 = 'BM25',
}

export const METRIC_TYPES = [
Expand Down Expand Up @@ -99,6 +105,10 @@ export const METRIC_TYPES = [
value: METRIC_TYPES_VALUES.TANIMOTO,
label: 'TANIMOTO',
},
{
value: METRIC_TYPES_VALUES.BM25,
label: 'BM25',
},
];

export type MetricType =
Expand Down Expand Up @@ -392,6 +402,13 @@ export enum DataTypeStringEnum {
Array = 'Array',
None = 'None',
}
export const VectorTypesString: DataTypeStringEnum[] = [
DataTypeStringEnum.BinaryVector,
DataTypeStringEnum.FloatVector,
DataTypeStringEnum.BFloat16Vector,
DataTypeStringEnum.Float16Vector,
DataTypeStringEnum.SparseFloatVector,
];

export const NONE_INDEXABLE_DATA_TYPES = [DataTypeStringEnum.JSON];

Expand Down Expand Up @@ -454,3 +471,8 @@ export const databaseDefaults: Property[] = [
{ key: 'database.max.collections', value: '', desc: '', type: 'number' },
{ key: 'database.force.deny.writing', value: '', desc: '', type: 'boolean' },
];

export enum FunctionType {
Unknown = 0,
BM25 = 1,
}
4 changes: 3 additions & 1 deletion client/src/i18n/cn/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const btnTrans = {
importSampleData: '插入样本数据',
loading: '加载中...',
importing: '导入中...',
example: '生成随机向量',
example: '生成随机数据',
rename: '重命名',
duplicate: '复制',
export: '导出',
Expand All @@ -36,6 +36,8 @@ const btnTrans = {
star: '给我一颗小星星',
applyFilter: '应用过滤器',
createIndex: '创建索引',
createVectorIndex: '创建向量索引',
createScalarIndex: '创建标量索引',
edit: '编辑',
explore: '探索',
close: '关闭',
Expand Down
6 changes: 5 additions & 1 deletion client/src/i18n/cn/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const collectionTrans = {
createdTime: '创建时间',
maxLength: '最大长度',
dynamicSchema: '动态schema',
function: 'Function',
functionInput: 'Function输入',
functionOutput: 'Function输出',

// table tooltip
aliasInfo: '别名可以在向量搜索中用作Collection名称。',
Expand All @@ -34,7 +37,8 @@ const collectionTrans = {

// create dialog
createTitle: '创建Collection',
general: '一般信息',
idAndVectorFields: 'ID、向量或可用 BM25 算法处理的文本字段',
scalarFields: '标量字段',
schema: 'schema',
consistency: '一致性',
consistencyLevel: '一致性级别',
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/cn/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const dialogTrans = {
loadTitle: `加载 {{type}}`,
editEntityTitle: `编辑 Entity`,
modifyReplicaTitle: `修改 {{type}} 的副本`,
editAnalyzerTitle: `编辑 {{type}} 分析器`,
editAnalyzerTitle: `编辑分析器`,

loadContent: `您正在尝试加载带有数据的 {{type}}。只有已加载的 {{type}} 可以被搜索。`,
releaseContent: `您正在尝试发布带有数据的 {{type}}。请注意,数据将不再可用于搜索。`,
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/cn/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const searchTrans = {
firstTip: '2. 输入搜索向量 {{dimensionTip}}',
secondTip: '1. 选择Collection和字段',
thirdTip: '搜索参数 {{metricType}}',
vectorPlaceholder: '请在此输入您的向量值,例如 [1, 2, 3, 4]',
collection: '已加载的Collection',
noCollection: '没有已加载的Collection',
field: '向量字段',
Expand All @@ -29,6 +28,7 @@ const searchTrans = {
consistency: '一致性',
graphNodeHoverTip: '双击以查看更多',
inputVectorPlaceHolder: '向量或实体ID',
textPlaceHolder: '请在此输入您的文本',
partitionFilter: '分区过滤',
loading: '加载中...',
};
Expand Down
4 changes: 3 additions & 1 deletion client/src/i18n/en/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const btnTrans = {
importSampleData: 'Insert Sample Data',
loading: 'Loading...',
importing: 'Importing...',
example: 'Generate Random Vector',
example: 'Generate Random Data',
rename: 'Rename',
duplicate: 'Duplicate',
export: 'Export',
Expand All @@ -36,6 +36,8 @@ const btnTrans = {
star: 'Give me a Star',
applyFilter: 'Apply Filters',
createIndex: 'Create Index',
createVectorIndex: 'Vector Index',
createScalarIndex: 'Scalar Index',
edit: 'Edit',
explore: 'Explore',
close: 'Close',
Expand Down
6 changes: 5 additions & 1 deletion client/src/i18n/en/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const collectionTrans = {
createdTime: 'Created Time',
maxLength: 'Max Length',
dynamicSchema: 'Dynamic Schema',
function: 'Function',
functionInput: 'Input',
functionOutput: 'Output',

// table tooltip
aliasInfo: 'Alias can be used as collection name in vector search.',
Expand All @@ -35,7 +38,8 @@ const collectionTrans = {

// create dialog
createTitle: 'Create Collection',
general: 'General information',
idAndVectorFields: 'ID, Vector, or VarChar Fields for BM25 Processing',
scalarFields: 'Scalar Fields',
schema: 'Schema',
consistency: 'Consistency',
consistencyLevel: 'Consistency Level',
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/en/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const dialogTrans = {
flush: `Flush data for {{type}}`,
loadTitle: `Load {{type}}`,
editEntityTitle: `Edit Entity(JSON)`,
editAnalyzerTitle: `Edit analyzer for {{type}}`,
editAnalyzerTitle: `Edit Analyzer`,
modifyReplicaTitle: `Modify replica for {{type}}`,

loadContent: `You are trying to load a {{type}} with data. Only loaded {{type}} can be searched.`,
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/en/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const searchTrans = {
firstTip: '2. Enter search vector {{dimensionTip}}',
secondTip: '1. Choose collection and field',
thirdTip: 'Search Parameters {{metricType}}',
vectorPlaceholder: 'Please input your vector value here, e.g. [1, 2, 3, 4]',
collection: 'loaded collection',
noCollection: 'No loaded collection',
field: 'Vector field',
Expand All @@ -29,6 +28,7 @@ const searchTrans = {
consistency: 'Consistency',
graphNodeHoverTip: 'Double click to explore more',
inputVectorPlaceHolder: 'Vector or entity id',
textPlaceHolder: 'Please input your text here',
partitionFilter: 'Partition Filter',
loading: 'Loading...',
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/databases/Databases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const useStyles = makeStyles((theme: Theme) => ({
// Databases page(tree and tabs)
const Databases = () => {
// context
const { database, collections, loading, fetchCollection, ui, setUIPref } =
const { database, collections, loading, ui, setUIPref } =
useContext(dataContext);

// UI state
Expand Down
30 changes: 30 additions & 0 deletions client/src/pages/databases/collections/StatusAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const useStyles = makeStyles((theme: Theme) => ({
},
extraBtn: {
height: 24,
padding: '0 8px',
},
}));

Expand All @@ -55,6 +56,7 @@ const StatusAction: FC<StatusActionType> = props => {
collection,
action = () => {},
showExtraAction,
showLoadButton,
createIndexElement,
} = props;

Expand Down Expand Up @@ -134,6 +136,33 @@ const StatusAction: FC<StatusActionType> = props => {
});
};

if (
collection.schema &&
status === LOADING_STATE.UNLOADED &&
collection.schema.hasVectorIndex &&
showLoadButton
) {
return (
<CustomButton
startIcon={<Icons.load />}
className={classes.extraBtn}
variant="contained"
tooltip={collectionTrans('clickToLoad')}
onClick={() => {
setDialog({
open: true,
type: 'custom',
params: {
component: <LoadCollectionDialog collection={collection} />,
},
});
}}
>
{collectionTrans('loadTitle')}
</CustomButton>
);
}

return (
<div className={classes.root}>
<CustomToolTip title={noIndex ? noIndexTooltip : tooltip} placement="top">
Expand Down Expand Up @@ -166,6 +195,7 @@ const StatusAction: FC<StatusActionType> = props => {
{btnTrans('vectorSearch')}
</CustomButton>
)}

{!collection.schema.hasVectorIndex && createIndexElement}
</>
)}
Expand Down
12 changes: 11 additions & 1 deletion client/src/pages/databases/collections/Types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { Dispatch, SetStateAction } from 'react';
import { DataTypeEnum } from '@/consts';
import { DataTypeEnum, FunctionType } from '@/consts';

export interface CollectionCreateProps {
onCreate?: () => void;
}

export type FunctionConfig = {
name: string;
description: string;
type: FunctionType;
input_field_names: string[];
output_field_names: string[];
params: Record<string, unknown>;
};

export interface CollectionCreateParam {
collection_name: string;
description: string;
autoID: boolean;
fields: CreateField[];
consistency_level: string;
functions: FunctionConfig[];
}

export type AnalyzerType = 'standard' | 'english' | 'chinese';
Expand Down
22 changes: 12 additions & 10 deletions client/src/pages/databases/collections/data/CollectionData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const CollectionData = (props: CollectionDataProps) => {
} = useQuery({
collection,
consistencyLevel,
fields,
fields: fields.filter(f => !f.is_function_output),
onQueryStart: (expr: string = '') => {
setTableLoading(true);
if (expr === '') {
Expand Down Expand Up @@ -422,15 +422,17 @@ const CollectionData = (props: CollectionDataProps) => {
<div className="right">
<CustomMultiSelector
className={classes.outputs}
options={fields.map(f => {
return {
label:
f.name === DYNAMIC_FIELD
? searchTrans('dynamicFields')
: f.name,
value: f.name,
};
})}
options={fields
.filter(f => !f.is_function_output)
.map(f => {
return {
label:
f.name === DYNAMIC_FIELD
? searchTrans('dynamicFields')
: f.name,
value: f.name,
};
})}
values={outputFields}
renderValue={selected => (
<span>{`${(selected as string[]).length} ${
Expand Down
Loading
Loading