Skip to content

Commit

Permalink
fix wrong search requests (#359)
Browse files Browse the repository at this point in the history
* fix wrong search requests

Signed-off-by: shanghaikid <[email protected]>

* remove console

Signed-off-by: shanghaikid <[email protected]>

* update test milvus version

Signed-off-by: shanghaikid <[email protected]>

* add more tests

Signed-off-by: shanghaikid <[email protected]>

---------

Signed-off-by: shanghaikid <[email protected]>
  • Loading branch information
shanghaikid authored Sep 15, 2024
1 parent 62c4fd4 commit 6758b65
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 123 deletions.
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

0 comments on commit 6758b65

Please sign in to comment.