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 group by for milvus 2.4 #557

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/i18n/cn/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const searchTrans = {
noVectorToSearch: '没有用于搜索的向量数据.',
noSelectedVectorField: '至少选择一个向量字段进行搜索.',
rerank: '排序器',
groupBy: '分组',
};

export default searchTrans;
1 change: 1 addition & 0 deletions client/src/i18n/en/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const searchTrans = {
noVectorToSearch: 'No vector data to search.',
noSelectedVectorField: 'At least select one vector field to search.',
rerank: 'Reranker',
groupBy: 'Group By',
};

export default searchTrans;
1 change: 1 addition & 0 deletions client/src/pages/databases/collections/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ const Search = (props: CollectionDataProps) => {
onSlideChangeCommitted={() => {
setHighlightField('');
}}
fields={searchParams.collection.schema.scalarFields}
searchParams={searchParams}
searchGlobalParams={searchParams.globalParams}
handleFormChange={(params: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@ import {
CONSISTENCY_LEVEL_OPTIONS,
TOP_K_OPTIONS,
RERANKER_OPTIONS,
DataTypeStringEnum,
} from '@/consts';
import { SearchParams, GlobalParams } from '../../types';
import { FieldObject } from '@server/types';

export interface CollectionDataProps {
export interface SearchGlobalProps {
searchGlobalParams: GlobalParams;
searchParams: SearchParams;
handleFormChange: (form: GlobalParams) => void;
onSlideChange: (field: string) => void;
onSlideChangeCommitted: () => void;
fields: FieldObject[];
}

const SearchGlobalParams = (props: CollectionDataProps) => {
const UNSPORTED_GROUPBY_TYPES = [
DataTypeStringEnum.Double,
DataTypeStringEnum.Float,
DataTypeStringEnum.JSON,
];

const SearchGlobalParams = (props: SearchGlobalProps) => {
// props
const {
searchParams,
searchGlobalParams,
handleFormChange,
onSlideChange,
onSlideChangeCommitted,
fields,
} = props;
const selectedCount = searchParams.searchParams.filter(
sp => sp.selected
Expand All @@ -52,14 +62,14 @@ const SearchGlobalParams = (props: CollectionDataProps) => {
[handleFormChange, searchGlobalParams]
);

const onRerankChanged = useCallback(
(e: { target: { value: unknown } }) => {
const rerankerStr = e.target.value as 'rrf' | 'weighted';

handleInputChange('rerank', rerankerStr);
},
[selectedCount, handleInputChange]
);
const groupByOptions = fields
.filter(f => !UNSPORTED_GROUPBY_TYPES.includes(f.data_type as any))
.map(f => {
return {
value: f.name,
label: f.name,
};
});

return (
<>
Expand All @@ -86,6 +96,20 @@ const SearchGlobalParams = (props: CollectionDataProps) => {
}}
/>

{!showReranker && (
<CustomSelector
options={[{ label: '--', value: '' }, ...groupByOptions]}
value={searchGlobalParams.group_by_field || ''}
label={searchTrans('groupBy')}
wrapperClass="selector"
variant="filled"
onChange={(e: { target: { value: unknown } }) => {
const groupBy = e.target.value as string;
handleInputChange('group_by_field', groupBy);
}}
/>
)}

{showReranker && (
<>
<CustomSelector
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/databases/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type GlobalParams = {
rrfParams: { k: number };
weightedParams: { weights: number[] };
round_decimal?: number;
group_by_field?: string;
};

export type SearchResultView = {
Expand Down
5 changes: 5 additions & 0 deletions client/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export const buildSearchParams = (
consistency_level: searchParams.globalParams.consistency_level,
};

// group_by_field if exists
if (searchParams.globalParams.group_by_field) {
params.group_by_field = searchParams.globalParams.group_by_field;
}

// reranker if exists
if (data.length > 1) {
if (searchParams.globalParams.rerank === 'rrf') {
Expand Down
3 changes: 2 additions & 1 deletion server/src/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class CollectionsService {
const searchParams = data as HybridSearchReq;
const isHybrid =
Array.isArray(searchParams.data) && searchParams.data.length > 1;
const singleSearchParams = cloneObj(data) as SearchSimpleReq;
let singleSearchParams = cloneObj(data) as SearchSimpleReq;

// for 2.3.x milvus
if (searchParams.data && searchParams.data.length === 1) {
Expand All @@ -273,6 +273,7 @@ export class CollectionsService {
}
singleSearchParams.data = searchParams.data[0].data;
singleSearchParams.anns_field = searchParams.data[0].anns_field;
singleSearchParams.group_by_field = searchParams.group_by_field;
}

const res = await milvusClient.search(
Expand Down
Loading