Skip to content

Commit

Permalink
search should render sparse vector
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Apr 19, 2024
1 parent 0062242 commit eca7b92
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
11 changes: 11 additions & 0 deletions client/src/pages/search/SearchParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ const SearchParams: FC<SearchParamsProps> = ({
handleInputChange('search_list', value);
},
},
drop_ratio_search: {
label: 'drop_ratio_search',
key: 'drop_ratio_search',
value: searchParamsForm['drop_ratio_search'] || '',
min: 0,
max: 1,
isInt: false,
handleChange: value => {
handleInputChange('drop_ratio_search', value);
},
},
};

const param = configParamMap[paramKey];
Expand Down
36 changes: 29 additions & 7 deletions client/src/pages/search/VectorSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import {
generateVector,
formatNumber,
} from '@/utils';
import { LOADING_STATE, DYNAMIC_FIELD, DataTypeEnum } from '@/consts';
import {
LOADING_STATE,
DYNAMIC_FIELD,
DataTypeEnum,
DataTypeStringEnum,
} from '@/consts';
import { getLabelDisplayedRows } from './Utils';
import SearchParams from './SearchParams';
import { getVectorSearchStyles } from './Styles';
Expand Down Expand Up @@ -95,7 +100,7 @@ const VectorSearch = () => {
const fields = (s.schema && s.schema.fields) || [];

// vector field can't be output fields
const invalidTypes = ['BinaryVector', 'FloatVector'];
const invalidTypes = ['BinaryVector', 'FloatVector', 'SparseFloatVector'];
const nonVectorFields = fields.filter(
field => !invalidTypes.includes(field.data_type)
);
Expand Down Expand Up @@ -180,7 +185,11 @@ const VectorSearch = () => {
*/
const vectorValueValid = useMemo(() => {
// if user hasn't input value or not select field, don't trigger validation check
if (vectors === '' || selectedFieldDimension === 0) {
if (
vectors === '' ||
selectedFieldDimension === 0 ||
fieldType === DataTypeEnum.SparseFloatVector
) {
return true;
}
const dim =
Expand Down Expand Up @@ -360,9 +369,19 @@ const VectorSearch = () => {
setVectors(value);
};

const fillWithExampleVector = (selectedFieldDimension: number) => {
const v = generateVector(selectedFieldDimension);
setVectors(`[${v}]`);
const fillWithExampleVector = (
selectedFieldDimension: number,
field: FieldObject
) => {
const isSparse = field.data_type === DataTypeStringEnum.SparseFloatVector;
if (isSparse) {
setVectors(
JSON.stringify({ [Math.floor(Math.random() * 10)]: Math.random() })
);
} else {
const v = generateVector(selectedFieldDimension);
setVectors(`[${v}]`);
}
};

return (
Expand Down Expand Up @@ -434,7 +453,10 @@ const VectorSearch = () => {
fieldType === DataTypeEnum.BinaryVector
? selectedFieldDimension / 8
: selectedFieldDimension;
fillWithExampleVector(dim);
fillWithExampleVector(
dim,
fieldOptions.find(f => f.value === selectedField)!.field
);
}}
>
{btnTrans('example')}
Expand Down
1 change: 1 addition & 0 deletions server/src/collections/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
enum VectorTypes {
Binary = DataType.BinaryVector,
Float = DataType.FloatVector,
SparseFloatVector = DataType.SparseFloatVector,
}

export class CreateCollectionDto {
Expand Down
2 changes: 1 addition & 1 deletion server/src/utils/Const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const DYNAMIC_FIELD = `$meta`;
export const VectorTypes = [
'BinaryVector',
'FloatVector',
'SpaseFloatVector',
'SparseFloatVector',
'Float16Vector',
'BFloat16Vector',
];

0 comments on commit eca7b92

Please sign in to comment.