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

support consistency level #85

Merged
merged 1 commit into from
Mar 9, 2022
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
11 changes: 10 additions & 1 deletion milvus/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CompactReq,
GetCompactionStateReq,
GetCompactionPlansReq,
ConsistencyLevelEnum,
} from "./types/Collection";
import {
BoolResponse,
Expand Down Expand Up @@ -49,6 +50,7 @@ export class Collection extends Client {
* | :---------------------- | :---- | :------------------------------- |
* | collection_name | String | Collection name |
* | description | String | Collection description |
* | consistency_level | String | "Strong" | "Session" (default) | "Bounded"| "Eventually" | "Customized"; |
* | fields | <a href="https://github.com/milvus-io/milvus-sdk-node/blob/main/milvus/types/Collection.ts#L8" target="_blank">FieldType</a> | Field data |
*
* @return
Expand Down Expand Up @@ -83,7 +85,12 @@ export class Collection extends Client {
* ```
*/
async createCollection(data: CreateCollectionReq): Promise<ResStatus> {
const { fields, collection_name, description } = data || {};
const {
fields,
collection_name,
description,
consistency_level = "Session",
} = data || {};
if (!fields || !fields.length || !collection_name) {
throw new Error(ERROR_REASONS.CREATE_COLLECTION_CHECK_PARAMS);
}
Expand Down Expand Up @@ -119,6 +126,8 @@ export class Collection extends Client {
const promise = await promisify(this.client, "CreateCollection", {
...data,
schema: schemaBtyes,
consistency_level:
ConsistencyLevelEnum[consistency_level] || ConsistencyLevelEnum.Session,
});

return promise;
Expand Down
1 change: 0 additions & 1 deletion milvus/Partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ShowPartitionsReq,
} from "./types/Partition";
import { formatKeyValueData } from "./utils/Format";

export class Partition extends Client {
/**
* Create a partition in a collection.
Expand Down
91 changes: 7 additions & 84 deletions milvus/types.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,13 @@
export type {
GetCollectionStatisticsReq,
HasCollectionReq,
DropCollectionReq,
LoadCollectionReq,
CreateCollectionReq,
ReleaseLoadCollectionReq,
DescribeCollectionReq,
FieldType,
ShowCollectionsType,
ShowCollectionsReq,
AlterAliasReq,
CreateAliasReq,
DropAliasReq,
} from "./types/Collection";
export * from "./types/Collection";

export type {
InsertReq,
FieldData,
FlushReq,
CalcDistanceReq,
GetFlushStateReq,
LoadBalanceReq,
GetQuerySegmentInfoReq,
} from "./types/Data";
export * from "./types/Data";

export type {
IndexState,
IndexType,
MetricType,
MsgBase,
MsgType,
DataType,
DslType,
} from "./types/Common";
export * from "./types/Common";

export type {
GetIndexBuildProgressReq,
DropIndexReq,
GetIndexStateReq,
CreateIndexReq,
CreateIndexParam,
DescribeIndexReq,
} from "./types/Index";
export * from "./types/Index";

export type {
GetPartitionStatisticsReq,
ReleasePartitionsReq,
CreatePartitionReq,
ShowPartitionsReq,
LoadPartitionsReq,
DropPartitionReq,
HasPartitionReq,
} from "./types/Partition";
export * from "./types/Partition";

export type {
ResStatus,
ErrorCode,
BoolResponse,
GetIndexBuildProgressResponse,
DescribeCollectionResponse,
ShowCollectionsResponse,
ShowPartitionsResponse,
GetIndexStateResponse,
DescribeIndexResponse,
StatisticsResponse,
MutationResult,
SearchResults,
SearchResultData,
CollectionSchema,
FieldSchema,
IndexDescription,
FlushResult,
QueryResults,
CollectionData,
GetMetricsResponse,
CalcDistanceResponse,
GetFlushStateResponse,
GetQuerySegmentInfoResponse,
GetCompactionStateResponse,
GetCompactionPlansResponse,
CompactionResponse,
} from "./types/Response";
export * from "./types/Response";

export type {
SearchRes,
SearchReq,
SearchParam,
GetMetricsRequest,
} from "./types/Search";
export * from "./types/Search";
14 changes: 14 additions & 0 deletions milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,23 @@ export interface CreateCollectionReq {
collection_name: string;
shards_num?: number; // int
description?: string;
consistency_level?:
| "Strong"
| "Session"
| "Bounded"
| "Eventually"
| "Customized";
fields: FieldType[];
}

export enum ConsistencyLevelEnum {
Strong = 0,
Session = 1, // default in PyMilvus
Bounded = 2,
Eventually = 3,
Customized = 4, // Users pass their own `guarantee_timestamp`.
}

interface CollectionNameReq {
/**
* @param collection_name collection name string
Expand Down
2 changes: 2 additions & 0 deletions milvus/types/Response.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConsistencyLevelEnum } from "./Collection";
import {
DataType,
IndexState,
Expand Down Expand Up @@ -86,6 +87,7 @@ export interface DescribeCollectionResponse extends TimeStamp {
status: ResStatus;
schema: CollectionSchema;
collectionID: string;
consistency_level: ConsistencyLevelEnum;
virtual_channel_names: string[]; // not useful for now
physical_channel_names: string[]; // not useful for now
}
Expand Down
10 changes: 6 additions & 4 deletions test/Collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const LOAD_COLLECTION_NAME = GENERATE_NAME();

describe("Collection Api", () => {
it(`Create Collection Successful`, async () => {
const res = await collectionManager.createCollection(
genCollectionParams(COLLECTION_NAME, "128")
);
const res = await collectionManager.createCollection({
...genCollectionParams(COLLECTION_NAME, "128"),
consistency_level: "Eventually",
});
expect(res.error_code).toEqual(ErrorCode.SUCCESS);
});

Expand Down Expand Up @@ -209,8 +210,9 @@ describe("Collection Api", () => {
const res = await collectionManager.describeCollection({
collection_name: COLLECTION_NAME,
});
console.log(res);
console.log("---- describe collection ---", res);
expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(res.consistency_level).toEqual("Eventually");
expect(res.schema.name).toEqual(COLLECTION_NAME);
expect(res.schema.fields.length).toEqual(2);
expect(res.schema.fields[0].name).toEqual(VECTOR_FIELD_NAME);
Expand Down
3 changes: 2 additions & 1 deletion utils/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConsistencyLevelEnum } from "../milvus/types";
import { DataType } from "../milvus/types/Common";

export const VECTOR_FIELD_NAME = "vector_field";
Expand All @@ -24,7 +25,7 @@ export const genCollectionParams = (
{
name: "age",
data_type: DataType.Int64,
autoID: autoID,
autoID,
is_primary_key: true,
description: "",
},
Expand Down