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

fix wrong search requests #359

Merged
merged 4 commits into from
Sep 15, 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
108 changes: 57 additions & 51 deletions milvus/utils/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,62 +693,68 @@ export const buildSearchRequest = (
searchHybridReq.data[0].anns_field
);

// output fields(reference fields)
const default_output_fields: string[] = ['*'];

// Iterate through collection fields, create search request
for (let i = 0; i < collectionInfo.schema.fields.length; i++) {
const field = collectionInfo.schema.fields[i];
const { name } = field;

let req: SearchSimpleReq | (HybridSearchReq & HybridSearchSingleReq) =
data as SearchSimpleReq;

if (isHybridSearch) {
const singleReq = searchHybridReq.data.find(d => d.anns_field === name);
// if it is hybrid search and no request target is not found, skip
if (!singleReq) {
continue;
}
// merge single request with hybrid request
req = Object.assign(cloneObj(data), singleReq);
} else {
// if it is not hybrid search, and we have built one request, skip
const skip =
requests.length === 1 ||
(typeof req.anns_field !== 'undefined' && req.anns_field !== name);
if (skip) {
continue;
const { name, dataType } = field;

// if field type is vector, build the request
if (isVectorType(dataType)) {
let req: SearchSimpleReq | (HybridSearchReq & HybridSearchSingleReq) =
data as SearchSimpleReq;

if (isHybridSearch) {
const singleReq = searchHybridReq.data.find(d => d.anns_field === name);
// if it is hybrid search and no request target is not found, skip
if (!singleReq) {
continue;
}
// merge single request with hybrid request
req = Object.assign(cloneObj(data), singleReq);
} else {
// if it is not hybrid search, and we have built one request, skip
const skip =
requests.length === 1 ||
(typeof req.anns_field !== 'undefined' && req.anns_field !== name);
if (skip) {
continue;
}
}
}

// get search vectors
let searchingVector: VectorTypes | VectorTypes[] = isHybridSearch
? req.data!
: searchReq.vectors ||
searchSimpleReq.vectors ||
searchSimpleReq.vector ||
searchSimpleReq.data;

// format searching vector
searchingVector = formatSearchVector(searchingVector, field.dataType!);

// create search request
requests.push({
collection_name: req.collection_name,
partition_names: req.partition_names || [],
output_fields: req.output_fields || ['*'],
nq: searchReq.nq || searchingVector.length,
dsl: searchReq.expr || searchSimpleReq.filter || '',
dsl_type: DslType.BoolExprV1,
placeholder_group: buildPlaceholderGroupBytes(
milvusProto,
searchingVector as VectorTypes[],
field.dataType!
),
search_params: parseToKeyValue(
searchReq.search_params || buildSearchParams(req, name)
),
consistency_level:
req.consistency_level || (collectionInfo.consistency_level as any),
});
// get search vectors
let searchingVector: VectorTypes | VectorTypes[] = isHybridSearch
? req.data!
: searchReq.vectors ||
searchSimpleReq.vectors ||
searchSimpleReq.vector ||
searchSimpleReq.data;

// format searching vector
searchingVector = formatSearchVector(searchingVector, field.dataType!);

// create search request
requests.push({
collection_name: req.collection_name,
partition_names: req.partition_names || [],
output_fields: req.output_fields || default_output_fields,
nq: searchReq.nq || searchingVector.length,
dsl: searchReq.expr || searchSimpleReq.filter || '',
dsl_type: DslType.BoolExprV1,
placeholder_group: buildPlaceholderGroupBytes(
milvusProto,
searchingVector as VectorTypes[],
field.dataType!
),
search_params: parseToKeyValue(
searchReq.search_params || buildSearchParams(req, name)
),
consistency_level:
req.consistency_level || (collectionInfo.consistency_level as any),
});
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zilliz/milvus2-sdk-node",
"author": "[email protected]",
"version": "2.4.8",
"milvusVersion": "v2.4.10",
"milvusVersion": "v2.4.11",
"main": "dist/milvus",
"files": [
"dist"
Expand Down
Loading
Loading