Skip to content

Commit

Permalink
support partial load fields
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Aug 28, 2024
1 parent f9e2835 commit 707007a
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export interface LoadCollectionReq extends collectionNameReq {
replica_number?: number; // optional, replica number, default is 1
resource_groups?: string[]; // optional, resource groups
refresh?: boolean; // optional, refresh, default is false
load_fields?: string[]; // optional, load fields
skip_load_dynamic_field?: boolean; // optional, skip load dynamic field, default is false
}
export interface ReleaseLoadCollectionReq extends collectionNameReq {}

Expand Down
132 changes: 132 additions & 0 deletions test/grpc/PartialLoad.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { MilvusClient, ErrorCode, DataType } from '../../milvus';
import { IP, GENERATE_NAME, generateInsertData } from '../tools';

const milvusClient = new MilvusClient({ address: IP, logLevel: 'debug' });
const COLLECTION_NAME = GENERATE_NAME();
const schema = [
{
name: 'vector',
description: 'Vector field',
data_type: DataType.FloatVector,
dim: Number(4),
},
{
name: 'id',
description: 'ID field',
data_type: DataType.Int64,
is_primary_key: true,
autoID: true,
},
{
name: 'varChar',
description: 'VarChar field',
data_type: DataType.VarChar,
max_length: 128,
is_partition_key: false,
},
{
name: 'array',
description: 'array field',
data_type: DataType.Array,
element_type: DataType.VarChar,
max_capacity: 128,
max_length: 128,
is_partition_key: false,
},
];

describe(`Partial load API `, () => {
it(`Create collection should be successful`, async () => {
const res = await milvusClient.createCollection({
collection_name: COLLECTION_NAME,
fields: schema,
});
expect(res.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`Describe collection should be successful`, async () => {
const desc = await milvusClient.describeCollection({
collection_name: COLLECTION_NAME,
});
expect(desc.schema.fields.length).toEqual(schema.length);
});

it(`Create index should be successful`, async () => {
const index = await milvusClient.createIndex({
collection_name: COLLECTION_NAME,
field_name: 'vector',
extra_params: {
index_type: 'IVF_FLAT',
metric_type: 'L2',
params: JSON.stringify({ nlist: 1024 }),
},
});
expect(index.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`load collection should be successful`, async () => {
const load = await milvusClient.loadCollectionSync({
collection_name: COLLECTION_NAME,
load_fields: ['vector', 'id', 'varChar'],
});
expect(load.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`insert data should be successful`, async () => {
const data = generateInsertData(schema);
const insert = await milvusClient.insert({
collection_name: COLLECTION_NAME,
data,
});
expect(insert.status.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`query should be successful`, async () => {
const query = await milvusClient.query({
collection_name: COLLECTION_NAME,
expr: `id > 0`,
output_fields: ['*'],
});
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);
});

it(`search should be successful`, async () => {
const search = await milvusClient.search({
collection_name: COLLECTION_NAME,
data: [1, 2, 3, 4],
});
expect(search.status.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`search nq > 1 should be successful`, async () => {
const search = await milvusClient.search({
collection_name: COLLECTION_NAME,
data: [
[1, 2, 3, 4],
[5, 6, 7, 8],
],
});
expect(search.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(search.results.length).toEqual(2);
expect(search.results[0].length).toEqual(10);
expect(search.results[1].length).toEqual(10);
});

it(`release and drop should be successful`, async () => {
// releases
const release = await milvusClient.releaseCollection({
collection_name: COLLECTION_NAME,
timeout: 15000,
});
expect(release.error_code).toEqual(ErrorCode.SUCCESS);

// drop
const drop = await milvusClient.dropCollection({
collection_name: COLLECTION_NAME,
});
expect(drop.error_code).toEqual(ErrorCode.SUCCESS);
});
});

0 comments on commit 707007a

Please sign in to comment.