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

update test cases #243

Merged
merged 1 commit into from
Sep 20, 2023
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
10 changes: 5 additions & 5 deletions test/Collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe(`Collection API`, () => {
const res = await milvusClient.getPkFieldName({
collection_name: COLLECTION_NAME,
});
expect(res).toEqual('age');
expect(res).toEqual('id');
});

it(`Create Collection with number dim Successful`, async () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe(`Collection API`, () => {
collection_name: 'zxc',
fields: [
{
name: 'age',
name: 'id',
description: '',
data_type: DataType.Int64,
is_primary_key: true,
Expand All @@ -126,7 +126,7 @@ describe(`Collection API`, () => {
data_type: DataType.FloatVector,
},
{
name: 'age',
name: 'id',
description: '',
data_type: DataType.Int64,
is_primary_key: true,
Expand Down Expand Up @@ -164,7 +164,7 @@ describe(`Collection API`, () => {
},
},
{
name: 'age',
name: 'id',
description: '',
data_type: DataType.Int64,
is_primary_key: true,
Expand Down Expand Up @@ -334,7 +334,7 @@ describe(`Collection API`, () => {
expect(typeof f.data_type).toEqual('string');
});
expect(res.schema.fields[0].name).toEqual(VECTOR_FIELD_NAME);
expect(res.schema.fields[1].name).toEqual('age');
expect(res.schema.fields[1].name).toEqual('id');
});

it(`Load Collection Sync throw COLLECTION_NAME_IS_REQUIRED`, async () => {
Expand Down
72 changes: 39 additions & 33 deletions test/Data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,79 +251,85 @@ describe(`Data.API`, () => {
const limit = 8;
const res = await milvusClient.search({
collection_name: COLLECTION_NAME,
filter: 'height < 10000',
filter: 'int64 < 10000',
vector: [1, 2, 3, 4],
limit: limit,
params: { nprobe: 1024 },
});

expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
res.results.forEach(r => {
expect(Number(r.height)).toBeLessThan(10000);
expect(Number(r.int64)).toBeLessThan(10000);
});

const res2 = await milvusClient.search({
collection_name: COLLECTION_NAME,
expr: 'height < 10000',
expr: 'int64 < 10000',
vector: [1, 2, 3, 4],
limit: limit,
params: { nprobe: 1024 },
});
expect(res2.status.error_code).toEqual(ErrorCode.SUCCESS);
res2.results.forEach(r => {
expect(Number(r.height)).toBeLessThan(10000);
expect(Number(r.int64)).toBeLessThan(10000);
});
});

it(`Exec simple search with range filter should success`, async () => {
const limit = 8;
const res = await milvusClient.search({
collection_name: COLLECTION_NAME,
filter: 'height < 10000',
filter: 'int64 < 10000',
vector: [1, 2, 3, 4],
limit: limit,
params: { nprobe: 1024, radius: 20, range_filter: 15 },
});

expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
res.results.forEach(r => {
expect(Number(r.height)).toBeLessThan(10000);
expect(Number(r.int64)).toBeLessThan(10000);
});
});

it(`Exec simple search with outputFields should success`, async () => {
const res = await milvusClient.search({
const searchParams = {
collection_name: COLLECTION_NAME,
// partition_names: [],
filter: '',
vector: [1, 2, 3, 4],
limit: 4,
output_fields: ['age', 'meta', VECTOR_FIELD_NAME],
});
output_fields: ['id', 'json', VECTOR_FIELD_NAME],
};
const res = await milvusClient.search(searchParams);

expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(
res.results.forEach(r => {
expect(typeof r[VECTOR_FIELD_NAME] !== 'undefined').toEqual(true);
expect(Object.keys(r).length).toEqual(5); // id, score, age, meta, vector
expect(Object.keys(r).length).toEqual(
searchParams.output_fields.length + 1
); // plus score
})
);
});

it(`Exec simple search with JSON filter should success`, async () => {
const res = await milvusClient.search({
const searchParams = {
collection_name: COLLECTION_NAME,
// partition_names: [],
filter: 'meta["number"] >= 0',
filter: 'json["number"] >= 0',
vector: [1, 2, 3, 4],
limit: 4,
output_fields: ['age', 'meta'],
});
output_fields: ['id', 'json'],
};
const res = await milvusClient.search(searchParams);

expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(
res.results.forEach(r => {
expect(Object.keys(r).length).toEqual(4); // id, score, age, meta
expect(Object.keys(r).length).toEqual(
searchParams.output_fields.length + 1
);
})
);
});
Expand All @@ -341,7 +347,7 @@ describe(`Data.API`, () => {
params: JSON.stringify({ nprobe: 1024 }),
round_decimal: 2,
},
output_fields: ['age'],
output_fields: ['id'],
vector_type: DataType.FloatVector,
});

Expand All @@ -361,7 +367,7 @@ describe(`Data.API`, () => {
params: JSON.stringify({ nprobe: 1024 }),
round_decimal: -1,
},
output_fields: ['age'],
output_fields: ['id'],
vector_type: DataType.FloatVector,
});

Expand Down Expand Up @@ -393,7 +399,7 @@ describe(`Data.API`, () => {
try {
await milvusClient.query({
collection_name: COLLECTION_NAME,
output_fields: ['age', VECTOR_FIELD_NAME],
output_fields: ['id', VECTOR_FIELD_NAME],
offset: 0,
limit: 3,
});
Expand All @@ -406,7 +412,7 @@ describe(`Data.API`, () => {
try {
await milvusClient.get({
collection_name: COLLECTION_NAME,
output_fields: ['age', VECTOR_FIELD_NAME],
output_fields: ['id', VECTOR_FIELD_NAME],
} as any);
} catch (error) {
expect(error.message).toEqual(ERROR_REASONS.IDS_REQUIRED);
Expand All @@ -416,7 +422,7 @@ describe(`Data.API`, () => {
it(`Get should success`, async () => {
const get = await milvusClient.get({
collection_name: COLLECTION_NAME,
output_fields: ['age', VECTOR_FIELD_NAME],
output_fields: ['id', VECTOR_FIELD_NAME],
ids: ['1', '2', '3'],
});
expect(get.status.error_code).toEqual(ErrorCode.SUCCESS);
Expand All @@ -425,8 +431,8 @@ describe(`Data.API`, () => {
it(`Query with data limit and offset`, async () => {
const res = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: 'age > 0',
output_fields: ['age', VECTOR_FIELD_NAME, 'default_value'],
expr: 'id > 0',
output_fields: ['id', VECTOR_FIELD_NAME, 'default_value'],
offset: 0,
limit: 3,
});
Expand All @@ -448,35 +454,35 @@ describe(`Data.API`, () => {
});

it(`Query with data limit only`, async () => {
const expr = 'age > 0';
const expr = 'id > 0';
const res = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: expr,
output_fields: ['age', 'meta', VECTOR_FIELD_NAME],
output_fields: ['id', 'json', VECTOR_FIELD_NAME],
limit: 3,
});

expect(res.data.length).toBe(3);
});

it(`Query JSON data with float filter`, async () => {
const expr = 'meta["float"] >= 1.0';
const expr = 'json["float"] >= 1.0';
const res = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: expr,
output_fields: ['age', 'meta', VECTOR_FIELD_NAME],
output_fields: ['id', 'json', VECTOR_FIELD_NAME],
offset: 0,
limit: 3,
});
expect(res.data.length).toBe(3);
});

it(`Query JSON data with number filter`, async () => {
const expr = 'meta["number"] >= 1.0';
const expr = 'json["number"] >= 1.0';
const res = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: expr,
output_fields: ['age', 'meta', VECTOR_FIELD_NAME],
output_fields: ['id', 'json', VECTOR_FIELD_NAME],
offset: 0,
limit: 3,
});
Expand All @@ -486,22 +492,22 @@ describe(`Data.API`, () => {
it(`Query with data without limit and offset`, async () => {
const res3 = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: 'age > 0',
output_fields: ['age', VECTOR_FIELD_NAME],
expr: 'id > 0',
output_fields: ['id', VECTOR_FIELD_NAME],
});
expect(res3.status.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`Query with empty data`, async () => {
await milvusClient.deleteEntities({
collection_name: COLLECTION_NAME,
expr: 'age in [2,6]',
expr: 'id in [2,6]',
});

const res = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: 'age in [2,4,6,8]',
output_fields: ['age', VECTOR_FIELD_NAME],
expr: 'id in [2,4,6,8]',
output_fields: ['id', VECTOR_FIELD_NAME],
limit: 3,
offset: 0,
});
Expand Down
12 changes: 6 additions & 6 deletions test/DynamicSchema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ describe(`Dynamic schema API`, () => {
const query = await milvusClient.query({
collection_name: COLLECTION,
limit: 10,
expr: 'age > 0',
expr: 'id > 0',
output_fields: [
'meta',
'json',
'vector',
'age',
'id',
'dynamic_int64',
'dynamic_varChar',
],
Expand All @@ -119,7 +119,7 @@ describe(`Dynamic schema API`, () => {
[1, 2, 3, 4],
[1, 2, 3, 4],
],
expr: 'age > 0',
expr: 'id > 0',
output_fields: ['*'],
consistency_level: ConsistencyLevelEnum.Session,
});
Expand All @@ -133,8 +133,8 @@ describe(`Dynamic schema API`, () => {
collection_name: COLLECTION,
limit: 10,
vector: [1, 2, 3, 4],
expr: 'age > 0',
output_fields: ['meta', 'age', 'dynamic_int64', 'dynamic_varChar'],
expr: 'id > 0',
output_fields: ['json', 'id', 'dynamic_int64', 'dynamic_varChar'],
});
expect(search2.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(search2.results.length).toEqual(10);
Expand Down
Loading