Skip to content

Commit

Permalink
finish partial load
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Sep 2, 2024
1 parent 707007a commit fec1924
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 62 deletions.
109 changes: 50 additions & 59 deletions milvus/utils/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,71 +693,62 @@ 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, 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;
}
}
const { name } = field;

// 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),
});
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 field is not vector, add it to output fields
default_output_fields.push(name);
// 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),
});
}

/**
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.6",
"milvusVersion": "v2.4.8",
"milvusVersion": "v2.4.10",
"main": "dist/milvus",
"files": [
"dist"
Expand Down
6 changes: 4 additions & 2 deletions test/grpc/PartialLoad.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MilvusClient, ErrorCode, DataType } from '../../milvus';
import { IP, GENERATE_NAME, generateInsertData } from '../tools';

const milvusClient = new MilvusClient({ address: IP, logLevel: 'debug' });
const milvusClient = new MilvusClient({ address: IP, logLevel: 'info' });
const COLLECTION_NAME = GENERATE_NAME();
const schema = [
{
Expand Down Expand Up @@ -90,7 +90,9 @@ describe(`Partial load API `, () => {
console.dir(query, { depth: null });
expect(query.status.error_code).toEqual(ErrorCode.SUCCESS);
// result should not contain 'array' field
expect(Object.keys(query.data[0]).length).toEqual(3);
const keys = Object.keys(query.data[0]);
expect(keys.length).toEqual(3);
expect(keys.includes('array')).toBeFalsy();
});

it(`search should be successful`, async () => {
Expand Down

0 comments on commit fec1924

Please sign in to comment.