@zilliz/milvus2-sdk-node 2.2.9 → 2.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +76 -12
  2. package/dist/milvus/MilvusClient.d.ts +21 -2
  3. package/dist/milvus/MilvusClient.js +35 -29
  4. package/dist/milvus/MilvusClient.js.map +1 -1
  5. package/dist/milvus/OrmClient.d.ts +19 -0
  6. package/dist/milvus/OrmClient.js +77 -0
  7. package/dist/milvus/OrmClient.js.map +1 -0
  8. package/dist/milvus/const/ErrorReason.d.ts +36 -31
  9. package/dist/milvus/const/ErrorReason.js +39 -32
  10. package/dist/milvus/const/ErrorReason.js.map +1 -1
  11. package/dist/milvus/const/Milvus.d.ts +2 -9
  12. package/dist/milvus/const/Milvus.js +16 -33
  13. package/dist/milvus/const/Milvus.js.map +1 -1
  14. package/dist/milvus/const/client.d.ts +5 -0
  15. package/dist/milvus/const/client.js +10 -0
  16. package/dist/milvus/const/client.js.map +1 -0
  17. package/dist/milvus/const/defaults.d.ts +11 -0
  18. package/dist/milvus/const/defaults.js +16 -0
  19. package/dist/milvus/const/defaults.js.map +1 -0
  20. package/dist/milvus/const/highLevel.d.ts +23 -0
  21. package/dist/milvus/const/highLevel.js +26 -0
  22. package/dist/milvus/const/highLevel.js.map +1 -0
  23. package/dist/milvus/const/index.d.ts +5 -0
  24. package/dist/milvus/{types.js → const/index.js} +7 -10
  25. package/dist/milvus/const/index.js.map +1 -0
  26. package/dist/milvus/const/limits.d.ts +2 -0
  27. package/dist/milvus/const/limits.js +7 -0
  28. package/dist/milvus/const/limits.js.map +1 -0
  29. package/dist/milvus/{BaseClient.d.ts → grpc/BaseClient.d.ts} +20 -8
  30. package/dist/milvus/grpc/BaseClient.js +83 -0
  31. package/dist/milvus/grpc/BaseClient.js.map +1 -0
  32. package/dist/milvus/{Collection.d.ts → grpc/Collection.d.ts} +32 -3
  33. package/dist/milvus/grpc/Collection.js +786 -0
  34. package/dist/milvus/grpc/Collection.js.map +1 -0
  35. package/dist/milvus/{Data.d.ts → grpc/Data.d.ts} +68 -10
  36. package/dist/milvus/grpc/Data.js +880 -0
  37. package/dist/milvus/grpc/Data.js.map +1 -0
  38. package/dist/milvus/grpc/Database.d.ts +69 -0
  39. package/dist/milvus/grpc/Database.js +98 -0
  40. package/dist/milvus/grpc/Database.js.map +1 -0
  41. package/dist/milvus/grpc/GrpcClient.d.ts +46 -0
  42. package/dist/milvus/grpc/GrpcClient.js +150 -0
  43. package/dist/milvus/grpc/GrpcClient.js.map +1 -0
  44. package/dist/milvus/{MilvusIndex.d.ts → grpc/MilvusIndex.d.ts} +1 -1
  45. package/dist/milvus/grpc/MilvusIndex.js +203 -0
  46. package/dist/milvus/grpc/MilvusIndex.js.map +1 -0
  47. package/dist/milvus/{Partition.d.ts → grpc/Partition.d.ts} +1 -1
  48. package/dist/milvus/grpc/Partition.js +265 -0
  49. package/dist/milvus/grpc/Partition.js.map +1 -0
  50. package/dist/milvus/{Resource.d.ts → grpc/Resource.d.ts} +2 -2
  51. package/dist/milvus/grpc/Resource.js +250 -0
  52. package/dist/milvus/grpc/Resource.js.map +1 -0
  53. package/dist/milvus/{User.d.ts → grpc/User.d.ts} +1 -1
  54. package/dist/milvus/grpc/User.js +619 -0
  55. package/dist/milvus/grpc/User.js.map +1 -0
  56. package/dist/milvus/index.d.ts +4 -13
  57. package/dist/milvus/index.js +6 -14
  58. package/dist/milvus/index.js.map +1 -1
  59. package/dist/milvus/orm/Collection.d.ts +45 -0
  60. package/dist/milvus/orm/Collection.js +172 -0
  61. package/dist/milvus/orm/Collection.js.map +1 -0
  62. package/dist/milvus/orm/index.d.ts +2 -0
  63. package/dist/milvus/orm/index.js +19 -0
  64. package/dist/milvus/orm/index.js.map +1 -0
  65. package/dist/milvus/orm/utils.d.ts +27 -0
  66. package/dist/milvus/orm/utils.js +27 -0
  67. package/dist/milvus/orm/utils.js.map +1 -0
  68. package/dist/milvus/types/Client.d.ts +12 -1
  69. package/dist/milvus/types/Collection.d.ts +18 -4
  70. package/dist/milvus/types/Common.d.ts +1 -1
  71. package/dist/milvus/types/Data.d.ts +41 -5
  72. package/dist/milvus/types/Database.d.ts +12 -0
  73. package/dist/milvus/types/{Index.js → Database.js} +1 -1
  74. package/dist/milvus/types/Database.js.map +1 -0
  75. package/dist/milvus/types/HighLevel.d.ts +13 -0
  76. package/dist/milvus/types/HighLevel.js +3 -0
  77. package/dist/milvus/types/HighLevel.js.map +1 -0
  78. package/dist/milvus/types/{Index.d.ts → MilvusIndex.d.ts} +3 -2
  79. package/dist/milvus/types/MilvusIndex.js +3 -0
  80. package/dist/milvus/types/MilvusIndex.js.map +1 -0
  81. package/dist/milvus/types/Resource.d.ts +1 -1
  82. package/dist/milvus/types/User.d.ts +1 -1
  83. package/dist/milvus/types/index.d.ts +12 -0
  84. package/dist/milvus/types/index.js +30 -0
  85. package/dist/milvus/types/index.js.map +1 -0
  86. package/dist/{utils → milvus/utils}/Blob.js +4 -4
  87. package/dist/milvus/utils/Blob.js.map +1 -0
  88. package/dist/{utils → milvus/utils}/Format.d.ts +66 -2
  89. package/dist/milvus/utils/Format.js +416 -0
  90. package/dist/milvus/utils/Format.js.map +1 -0
  91. package/dist/{utils → milvus/utils}/Function.d.ts +1 -1
  92. package/dist/{utils → milvus/utils}/Function.js +7 -7
  93. package/dist/milvus/utils/Function.js.map +1 -0
  94. package/dist/{utils → milvus/utils}/Grpc.d.ts +9 -8
  95. package/dist/milvus/utils/Grpc.js +190 -0
  96. package/dist/milvus/utils/Grpc.js.map +1 -0
  97. package/dist/{utils → milvus/utils}/Validate.d.ts +7 -1
  98. package/dist/milvus/utils/Validate.js +140 -0
  99. package/dist/milvus/utils/Validate.js.map +1 -0
  100. package/dist/{utils → milvus/utils}/index.d.ts +2 -0
  101. package/dist/{utils → milvus/utils}/index.js +2 -0
  102. package/dist/milvus/utils/index.js.map +1 -0
  103. package/dist/milvus/utils/logger.d.ts +1 -0
  104. package/dist/milvus/utils/logger.js +18 -0
  105. package/dist/milvus/utils/logger.js.map +1 -0
  106. package/dist/proto/proto/common.proto +38 -14
  107. package/dist/proto/proto/google/protobuf/descriptor.proto +8 -4
  108. package/dist/proto/proto/milvus.proto +86 -83
  109. package/dist/proto/proto/schema.proto +5 -0
  110. package/dist/sdk.json +1 -1
  111. package/package.json +14 -11
  112. package/dist/milvus/BaseClient.js +0 -62
  113. package/dist/milvus/BaseClient.js.map +0 -1
  114. package/dist/milvus/Collection.js +0 -960
  115. package/dist/milvus/Collection.js.map +0 -1
  116. package/dist/milvus/Data.js +0 -909
  117. package/dist/milvus/Data.js.map +0 -1
  118. package/dist/milvus/GrpcClient.d.ts +0 -32
  119. package/dist/milvus/GrpcClient.js +0 -236
  120. package/dist/milvus/GrpcClient.js.map +0 -1
  121. package/dist/milvus/MilvusIndex.js +0 -299
  122. package/dist/milvus/MilvusIndex.js.map +0 -1
  123. package/dist/milvus/Partition.js +0 -369
  124. package/dist/milvus/Partition.js.map +0 -1
  125. package/dist/milvus/Resource.js +0 -356
  126. package/dist/milvus/Resource.js.map +0 -1
  127. package/dist/milvus/User.js +0 -806
  128. package/dist/milvus/User.js.map +0 -1
  129. package/dist/milvus/Utils.d.ts +0 -1
  130. package/dist/milvus/Utils.js +0 -8
  131. package/dist/milvus/Utils.js.map +0 -1
  132. package/dist/milvus/types/Index.js.map +0 -1
  133. package/dist/milvus/types.d.ts +0 -9
  134. package/dist/milvus/types.js.map +0 -1
  135. package/dist/proto/proto/feder.proto +0 -40
  136. package/dist/proto/proto/msg.proto +0 -107
  137. package/dist/utils/Blob.js.map +0 -1
  138. package/dist/utils/Format.js +0 -252
  139. package/dist/utils/Format.js.map +0 -1
  140. package/dist/utils/Function.js.map +0 -1
  141. package/dist/utils/Grpc.js +0 -170
  142. package/dist/utils/Grpc.js.map +0 -1
  143. package/dist/utils/Validate.js +0 -124
  144. package/dist/utils/Validate.js.map +0 -1
  145. package/dist/utils/index.js.map +0 -1
  146. package/dist/utils/test.d.ts +0 -15
  147. package/dist/utils/test.js +0 -98
  148. package/dist/utils/test.js.map +0 -1
  149. /package/dist/{utils → milvus/utils}/Blob.d.ts +0 -0
@@ -1,909 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
- if (ar || !(i in from)) {
67
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
- ar[i] = from[i];
69
- }
70
- }
71
- return to.concat(ar || Array.prototype.slice.call(from));
72
- };
73
- Object.defineProperty(exports, "__esModule", { value: true });
74
- exports.Data = void 0;
75
- var utils_1 = require("../utils");
76
- var _1 = require(".");
77
- var Collection_1 = require("./Collection");
78
- var Data = /** @class */ (function (_super) {
79
- __extends(Data, _super);
80
- function Data() {
81
- var _this = _super !== null && _super.apply(this, arguments) || this;
82
- _this.vectorTypes = [_1.DataType.BinaryVector, _1.DataType.FloatVector];
83
- return _this;
84
- }
85
- /**
86
- * Insert data into Milvus.
87
- *
88
- * @param data
89
- * | Property | Type | Description |
90
- * | :--- | :-- | :-- |
91
- * | collection_name | String | Collection name |
92
- * | partition_name(optional)| String | Partition name |
93
- * | fields_data | { [x: string]: any }[] | If the field type is binary, the vector data length needs to be dimension / 8 |
94
- * | hash_keys(optional) | Number[] | The hash value depends on the primarykey value |
95
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
96
-
97
- *
98
- * @returns
99
- * | Property | Description |
100
- * | :-- | :-- |
101
- * | status | { error_code: number, reason: string } |
102
- * | succ_index | Index array of the successfully inserted data |
103
- * | err_index | Index array of the unsuccessfully inserted data |
104
- * | IDs | ID array of the successfully inserted data |
105
- *
106
- *
107
- * #### Example
108
- *
109
- * ```
110
- * new milvusClient(MILUVS_ADDRESS).insert({
111
- * collection_name: COLLECTION_NAME,
112
- * fields_data: [{
113
- * vector_field: [1,2,2,4],
114
- * scalar_field: 1
115
- * }]
116
- * });
117
- * ```
118
- */
119
- Data.prototype.insert = function (data) {
120
- return __awaiter(this, void 0, void 0, function () {
121
- var collection_name, collectionInfo, fieldsData, params, promise;
122
- var _this = this;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0:
126
- (0, utils_1.checkCollectionName)(data);
127
- if (!data.fields_data ||
128
- !Array.isArray(data.fields_data) ||
129
- !data.fields_data.length) {
130
- throw new Error(_1.ERROR_REASONS.INSERT_CHECK_FILEDS_DATA_IS_REQUIRED);
131
- }
132
- collection_name = data.collection_name;
133
- return [4 /*yield*/, this.describeCollection({
134
- collection_name: collection_name,
135
- })];
136
- case 1:
137
- collectionInfo = _a.sent();
138
- if (collectionInfo.status.error_code !== _1.ErrorCode.SUCCESS) {
139
- throw new Error(collectionInfo.status.reason);
140
- }
141
- fieldsData = collectionInfo.schema.fields
142
- .filter(function (v) { return !v.is_primary_key || !v.autoID; })
143
- .map(function (v) { return ({
144
- name: v.name,
145
- type: v.data_type,
146
- dim: Number((0, utils_1.findKeyValue)(v.type_params, 'dim')),
147
- value: [],
148
- }); });
149
- params = __assign(__assign({}, data), { num_rows: data.fields_data.length });
150
- // You need to parse the original row data to column data for Milvus.
151
- data.fields_data.forEach(function (v, i) {
152
- // Set the key as the field name to get all names in a row.
153
- var fieldNames = Object.keys(v);
154
- fieldNames.forEach(function (name) {
155
- var target = fieldsData.find(function (item) { return item.name === name; });
156
- if (!target) {
157
- throw new Error("".concat(_1.ERROR_REASONS.INSERT_CHECK_WRONG_FIELD, " ").concat(i));
158
- }
159
- var isVector = _this.vectorTypes.includes(_1.DataTypeMap[target.type.toLowerCase()]);
160
- // Check if the dimension is matched when the data type is BinaryVector.
161
- if (_1.DataTypeMap[target.type.toLowerCase()] === _1.DataType.BinaryVector &&
162
- v[name].length !== target.dim / 8) {
163
- throw new Error(_1.ERROR_REASONS.INSERT_CHECK_WRONG_DIM);
164
- }
165
- // Value in vector field should be array. Therefore you need concat it.
166
- // but array.concat is slow, we need for loop to push the value one by one
167
- if (isVector) {
168
- for (var _i = 0, _a = v[name]; _i < _a.length; _i++) {
169
- var val = _a[_i];
170
- target.value.push(val);
171
- }
172
- }
173
- else {
174
- target.value[i] = v[name];
175
- }
176
- });
177
- });
178
- params.fields_data = fieldsData.map(function (v) {
179
- var _a, _b, _c, _d;
180
- // milvus return string for field type, so we define the DataTypeMap to the value we need.
181
- // but if milvus change the string, may casue we cant find value.
182
- var type = _1.DataTypeMap[v.type.toLowerCase()];
183
- var key = _this.vectorTypes.includes(type) ? 'vectors' : 'scalars';
184
- var dataKey = 'float_vector';
185
- switch (type) {
186
- case _1.DataType.FloatVector:
187
- dataKey = 'float_vector';
188
- break;
189
- case _1.DataType.BinaryVector:
190
- dataKey = 'binary_vector';
191
- break;
192
- case _1.DataType.Double:
193
- dataKey = 'double_data';
194
- break;
195
- case _1.DataType.Float:
196
- dataKey = 'float_data';
197
- break;
198
- case _1.DataType.Int64:
199
- dataKey = 'long_data';
200
- break;
201
- case _1.DataType.Int32:
202
- case _1.DataType.Int16:
203
- case _1.DataType.Int8:
204
- dataKey = 'int_data';
205
- break;
206
- case _1.DataType.Bool:
207
- dataKey = 'bool_data';
208
- break;
209
- case _1.DataType.VarChar:
210
- dataKey = 'string_data';
211
- break;
212
- default:
213
- throw new Error("".concat(_1.ERROR_REASONS.INSERT_CHECK_WRONG_DATA_TYPE, " \"").concat(v.type, ".\""));
214
- }
215
- return _a = {
216
- type: type,
217
- field_name: v.name
218
- },
219
- _a[key] = type === _1.DataType.FloatVector
220
- ? (_b = {
221
- dim: v.dim
222
- },
223
- _b[dataKey] = {
224
- data: v.value,
225
- },
226
- _b) : type === _1.DataType.BinaryVector
227
- ? (_c = {
228
- dim: v.dim
229
- },
230
- _c[dataKey] = (0, utils_1.parseBinaryVectorToBytes)(v.value),
231
- _c) : (_d = {},
232
- _d[dataKey] = {
233
- data: v.value,
234
- },
235
- _d),
236
- _a;
237
- });
238
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Insert', params, data.timeout || this.timeout)];
239
- case 2:
240
- promise = _a.sent();
241
- return [2 /*return*/, promise];
242
- }
243
- });
244
- });
245
- };
246
- /**
247
- * Delete entities in Milvus
248
- *
249
- * @param data
250
- * | Property | Type | Description |
251
- * | :--- | :-- | :-- |
252
- * | collection_name | String | Collection name |
253
- * | partition_name(optional)| String | Partition name |
254
- * | expr | String | Boolean expression used to filter attribute. |
255
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
256
-
257
- *
258
- * @returns
259
- * | Property | Description |
260
- * | :-- | :-- |
261
- * | status | { error_code: number, reason: string } |
262
- * | IDs | ID array of the successfully deleted data |
263
- *
264
- *
265
- * #### Example
266
- *
267
- * ```
268
- * new milvusClient(MILUVS_ADDRESS).deleteEntities({
269
- * collection_name: COLLECTION_NAME,
270
- * expr: 'id in [1,2,3,4]'
271
- * });
272
- * ```
273
- */
274
- Data.prototype.deleteEntities = function (data) {
275
- return __awaiter(this, void 0, void 0, function () {
276
- var promise;
277
- return __generator(this, function (_a) {
278
- switch (_a.label) {
279
- case 0:
280
- if (!data || !data.collection_name || !data.expr) {
281
- throw new Error(_1.ERROR_REASONS.DELETE_PARAMS_CHECK);
282
- }
283
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Delete', data, data.timeout || this.timeout)];
284
- case 1:
285
- promise = _a.sent();
286
- return [2 /*return*/, promise];
287
- }
288
- });
289
- });
290
- };
291
- /**
292
- * Perform vector similarity search.
293
- *
294
- * @param data
295
- * | Property | Type | Description |
296
- * | :--- | :-- | :-- |
297
- * | collection_name | String | Collection name |
298
- * | vectors or vector | Number[][] or Number[] | Original vector to search with |
299
- * | partition_names(optional)| String[] | Array of partition names |
300
- * | limit(optional) | number | topk alias |
301
- * | topk(optional) | number | topk |
302
- * | offset(optional) | number | offset |
303
- * | filter(optional) | String | Scalar field filter expression |
304
- * | expr(optional) | String | filter alias |
305
- * | output_fields(optional) | String[] | Support scalar field |
306
- * | metric_type(optional) | String | similarity metric |
307
- * | params(optional) | key value object | search params |
308
- *
309
- * @returns
310
- * | Property | Description |
311
- * | :-- | :-- |
312
- * | status | { error_code: number, reason: string } |
313
- * | results | {score:number,id:string}[]; |
314
- *
315
- * #### Example
316
- *
317
- * ```
318
- * new milvusClient(MILUVS_ADDRESS).search({
319
- * collection_name: COLLECTION_NAME,
320
- * vector: [1, 2, 3, 4],
321
- * });
322
- * ```
323
- */
324
- Data.prototype.search = function (data) {
325
- var _a, _b, _c, _d;
326
- return __awaiter(this, void 0, void 0, function () {
327
- var collectionInfo, vectorType_1, defaultOutputFields, dim, anns_field, i, f, type, search_params, searchVectors, round_decimal_1, PlaceholderGroup, placeholderGroupBytes, promise, results_1, _e, topks, scores_1, fields_data, ids, fieldsData_1, idData_1, err_1;
328
- return __generator(this, function (_f) {
329
- switch (_f.label) {
330
- case 0:
331
- // params check
332
- (0, utils_1.checkSearchParams)(data);
333
- _f.label = 1;
334
- case 1:
335
- _f.trys.push([1, 4, , 5]);
336
- return [4 /*yield*/, this.describeCollection({
337
- collection_name: data.collection_name,
338
- })];
339
- case 2:
340
- collectionInfo = _f.sent();
341
- defaultOutputFields = [];
342
- dim = 0;
343
- anns_field = void 0;
344
- for (i = 0; i < collectionInfo.schema.fields.length; i++) {
345
- f = collectionInfo.schema.fields[i];
346
- type = _1.DataTypeMap[f.data_type.toLowerCase()];
347
- // filter vector field
348
- if (type === _1.DataType.FloatVector || type === _1.DataType.BinaryVector) {
349
- // get dimension
350
- dim = Number((0, utils_1.findKeyValue)(f.type_params, 'dim'));
351
- // correcting dimension if necessary for binary vectors
352
- dim = type === _1.DataType.BinaryVector ? dim / 8 : dim;
353
- // anns field
354
- anns_field = f.name;
355
- // vector type
356
- vectorType_1 = type;
357
- }
358
- else {
359
- // save field name
360
- defaultOutputFields.push(f.name);
361
- }
362
- }
363
- search_params = data.search_params || {
364
- anns_field: anns_field,
365
- topk: data.limit ||
366
- data.topk ||
367
- _1.DEFAULT_TOPK,
368
- offset: data.offset || 0,
369
- metric_type: data.metric_type || _1.DEFAULT_METRIC_TYPE,
370
- params: JSON.stringify(data.params || {}),
371
- };
372
- searchVectors = data.vectors || [
373
- data.vector,
374
- ];
375
- round_decimal_1 = (_b = (_a = data.search_params) === null || _a === void 0 ? void 0 : _a.round_decimal) !== null && _b !== void 0 ? _b : (_c = data.params) === null || _c === void 0 ? void 0 : _c.round_decimal;
376
- PlaceholderGroup = this.milvusProto.lookupType('milvus.proto.common.PlaceholderGroup');
377
- placeholderGroupBytes = PlaceholderGroup.encode(PlaceholderGroup.create({
378
- placeholders: [
379
- {
380
- tag: '$0',
381
- type: vectorType_1,
382
- values: searchVectors.map(function (v) {
383
- return vectorType_1 === _1.DataType.BinaryVector
384
- ? (0, utils_1.parseBinaryVectorToBytes)(v)
385
- : (0, utils_1.parseFloatVectorToBytes)(v);
386
- }),
387
- },
388
- ],
389
- })).finish();
390
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Search', {
391
- collection_name: data.collection_name,
392
- partition_names: data.partition_names,
393
- output_fields: data.output_fields || defaultOutputFields,
394
- nq: data.nq || searchVectors.length,
395
- dsl: data.expr || data.filter || '',
396
- dsl_type: _1.DslType.BoolExprV1,
397
- placeholder_group: placeholderGroupBytes,
398
- search_params: (0, utils_1.parseToKeyValue)(search_params),
399
- }, data.timeout || this.timeout)];
400
- case 3:
401
- promise = _f.sent();
402
- results_1 = [];
403
- if (promise.results) {
404
- _e = promise.results, topks = _e.topks, scores_1 = _e.scores, fields_data = _e.fields_data, ids = _e.ids;
405
- fieldsData_1 = fields_data.map(function (item, i) {
406
- // if search result is empty, will cause value is undefined.
407
- var value = item.field ? item[item.field] : undefined;
408
- return {
409
- type: item.type,
410
- field_name: item.field_name,
411
- data: value ? value[value === null || value === void 0 ? void 0 : value.data].data : '',
412
- };
413
- });
414
- idData_1 = ids ? (_d = ids[ids.id_field]) === null || _d === void 0 ? void 0 : _d.data : undefined;
415
- /**
416
- * This code block formats the search results returned by Milvus into row data for easier use.
417
- * Milvus supports multiple queries to search and returns all columns data, so we need to splice the data for each search result using the `topk` variable.
418
- * The `topk` variable is the key we use to splice data for every search result.
419
- * The `scores` array is spliced using the `topk` value, and the resulting scores are formatted to the specified precision using the `formatNumberPrecision` function. The resulting row data is then pushed to the `results` array.
420
- */
421
- topks.forEach(function (v, index) {
422
- var topk = Number(v);
423
- scores_1.splice(0, topk).forEach(function (score, scoreIndex) {
424
- var i = index === 0 ? scoreIndex : scoreIndex + topk;
425
- var fixedScore = typeof round_decimal_1 === 'undefined' || round_decimal_1 === -1
426
- ? score
427
- : (0, utils_1.formatNumberPrecision)(score, round_decimal_1);
428
- var result = {
429
- score: fixedScore,
430
- id: idData_1 ? idData_1[i] : '',
431
- };
432
- fieldsData_1.forEach(function (field) {
433
- result[field.field_name] = field.data[i];
434
- });
435
- results_1.push(result);
436
- });
437
- });
438
- }
439
- return [2 /*return*/, {
440
- status: promise.status,
441
- results: results_1,
442
- }];
443
- case 4:
444
- err_1 = _f.sent();
445
- /* istanbul ignore next */
446
- throw new Error(err_1);
447
- case 5: return [2 /*return*/];
448
- }
449
- });
450
- });
451
- };
452
- /**
453
- * Milvus temporarily buffers the newly inserted vectors in the cache. Call `flush()` to persist them to the object storage.
454
- * It's async function, so it's will take some times to excute.
455
- * @param data
456
- * | Property | Type | Description |
457
- * | :--- | :-- | :-- |
458
- * | collection_names | String[] | Array of collection names |
459
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
460
-
461
- *
462
- * @returns
463
- * | Property | Description |
464
- * | :-- | :-- |
465
- * | status | { error_code: number, reason: string } |
466
- *
467
- * #### Example
468
- *
469
- * ```
470
- * new milvusClient(MILUVS_ADDRESS).flush({
471
- * collection_names: ['my_collection'],
472
- * });
473
- * ```
474
- */
475
- Data.prototype.flush = function (data) {
476
- return __awaiter(this, void 0, void 0, function () {
477
- var res;
478
- return __generator(this, function (_a) {
479
- switch (_a.label) {
480
- case 0:
481
- if (!data ||
482
- !Array.isArray(data.collection_names) ||
483
- !data.collection_names.length) {
484
- throw new Error(_1.ERROR_REASONS.COLLECTION_NAME_IS_REQUIRED);
485
- }
486
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Flush', data, data.timeout || this.timeout)];
487
- case 1:
488
- res = _a.sent();
489
- return [2 /*return*/, res];
490
- }
491
- });
492
- });
493
- };
494
- /**
495
- * It's same function as flush. But flushSync is sync function.
496
- * So you can ensure it's flushed after function return the result.
497
- *
498
- * @param data
499
- * | Property | Type | Description |
500
- * | :--- | :-- | :-- |
501
- * | collection_names | String[] | Array of collection names |
502
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
503
-
504
- *
505
- * @returns
506
- * | Property | Description |
507
- * | :-- | :-- |
508
- * | status | { error_code: number, reason: string } |
509
- *
510
- * #### Example
511
- *
512
- * ```
513
- * new milvusClient(MILUVS_ADDRESS).flushSync({
514
- * collection_names: ['my_collection'],
515
- * });
516
- * ```
517
- */
518
- Data.prototype.flushSync = function (data) {
519
- return __awaiter(this, void 0, void 0, function () {
520
- var res, segIDs, isFlushed, flushRes;
521
- return __generator(this, function (_a) {
522
- switch (_a.label) {
523
- case 0:
524
- if (!data ||
525
- !Array.isArray(data.collection_names) ||
526
- !data.collection_names.length) {
527
- throw new Error(_1.ERROR_REASONS.COLLECTION_NAME_IS_REQUIRED);
528
- }
529
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Flush', data, data.timeout || this.timeout)];
530
- case 1:
531
- res = _a.sent();
532
- segIDs = Object.keys(res.coll_segIDs)
533
- .map(function (v) { return res.coll_segIDs[v].data; })
534
- .reduce(function (pre, cur) { return __spreadArray(__spreadArray([], pre, true), cur, true); }, []);
535
- isFlushed = false;
536
- flushRes = null;
537
- _a.label = 2;
538
- case 2:
539
- if (!!isFlushed) return [3 /*break*/, 5];
540
- return [4 /*yield*/, this.getFlushState({ segmentIDs: segIDs })];
541
- case 3:
542
- flushRes = _a.sent();
543
- return [4 /*yield*/, (0, utils_1.sleep)(100)];
544
- case 4:
545
- _a.sent();
546
- isFlushed = flushRes.flushed;
547
- return [3 /*break*/, 2];
548
- case 5:
549
- // Before Milvus pre-GA will throw error
550
- return [2 /*return*/, flushRes];
551
- }
552
- });
553
- });
554
- };
555
- /**
556
- * Query vector data in Milvus. Current release of Milvus only supports expression as fieldname in [id1,id2,id3]
557
- *
558
- * @param data
559
- * | Property | Type | Description |
560
- * | :--- | :-- | :-- |
561
- * | collection_name | String | Collection name |
562
- * | expr | String | Scalar field filter expression |
563
- * | partitions_names(optional) | String[] | Array of partition names |
564
- * | output_fields | String[] | Vector or scalar field to be returned |
565
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
566
-
567
- * | params | {key: value}[] | An optional key pair json array
568
- *
569
- * @returns
570
- * | Property | Description |
571
- * | :-- | :-- |
572
- * | status | { error_code: number,reason:string } |
573
- * | data | Data of all fields that you defined in `output_fields`, {field_name: value}[] |
574
- *
575
- *
576
- * #### Example
577
- *
578
- * ```
579
- * new milvusClient(MILUVS_ADDRESS).query({
580
- * collection_name: 'my_collection',
581
- * expr: "age in [1,2,3,4,5,6,7,8]",
582
- * output_fields: ["age"],
583
- * });
584
- * ```
585
- */
586
- Data.prototype.query = function (data) {
587
- return __awaiter(this, void 0, void 0, function () {
588
- var limits, offset, promise, results, fieldsData;
589
- return __generator(this, function (_a) {
590
- switch (_a.label) {
591
- case 0:
592
- (0, utils_1.checkCollectionName)(data);
593
- if (typeof data.limit === 'number') {
594
- limits = { limit: data.limit };
595
- }
596
- if (typeof data.offset === 'number') {
597
- offset = { offset: data.offset };
598
- }
599
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Query', __assign(__assign({}, data), { query_params: (0, utils_1.parseToKeyValue)(__assign(__assign({}, limits), offset)) }), data.timeout || this.timeout)];
600
- case 1:
601
- promise = _a.sent();
602
- results = [];
603
- fieldsData = promise.fields_data.map(function (item, i) {
604
- var _a;
605
- if (item.field === 'vectors') {
606
- var key_1 = item.vectors.data;
607
- var vectorValue = key_1 === 'float_vector'
608
- ? item.vectors[key_1].data
609
- : item.vectors[key_1].toJSON().data;
610
- // if binary vector , need use dim / 8 to split vector data
611
- var dim_1 = ((_a = item.vectors) === null || _a === void 0 ? void 0 : _a.data) === 'float_vector'
612
- ? Number(item.vectors.dim)
613
- : Number(item.vectors.dim) / 8;
614
- var data_1 = [];
615
- // parse number[] to number[][] by dim
616
- vectorValue.forEach(function (v, i) {
617
- var index = Math.floor(i / dim_1);
618
- if (!data_1[index]) {
619
- data_1[index] = [];
620
- }
621
- data_1[index].push(v);
622
- });
623
- return {
624
- field_name: item.field_name,
625
- data: data_1,
626
- };
627
- }
628
- var key = item.scalars.data;
629
- var scalarValue = item.scalars[key].data;
630
- return {
631
- field_name: item.field_name,
632
- data: scalarValue,
633
- };
634
- });
635
- // parse column data to [{fieldname:value}]
636
- fieldsData.forEach(function (v) {
637
- v.data.forEach(function (d, i) {
638
- var _a, _b;
639
- if (!results[i]) {
640
- results[i] = (_a = {},
641
- _a[v.field_name] = d,
642
- _a);
643
- }
644
- else {
645
- results[i] = __assign(__assign({}, results[i]), (_b = {}, _b[v.field_name] = d, _b));
646
- }
647
- });
648
- });
649
- return [2 /*return*/, {
650
- status: promise.status,
651
- data: results,
652
- }];
653
- }
654
- });
655
- });
656
- };
657
- /**
658
- * @ignore
659
- * @param data
660
- * | Property | Type | Description |
661
- * | :--- | :-- | :-- |
662
- * | request | object | Only allow "system_info" for now |
663
- */
664
- Data.prototype.getMetric = function (data) {
665
- return __awaiter(this, void 0, void 0, function () {
666
- var res;
667
- return __generator(this, function (_a) {
668
- switch (_a.label) {
669
- case 0:
670
- if (!data || !data.request || !data.request.metric_type) {
671
- throw new Error(_1.ERROR_REASONS.GET_METRIC_CHECK_PARAMS);
672
- }
673
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'GetMetrics', {
674
- request: JSON.stringify(data.request),
675
- }, data.timeout || this.timeout)];
676
- case 1:
677
- res = _a.sent();
678
- return [2 /*return*/, __assign(__assign({}, res), { response: JSON.parse(res.response) })];
679
- }
680
- });
681
- });
682
- };
683
- /**
684
- * Get flush state by segment ids
685
- *
686
- * @param data
687
- * | Property | Type | Description |
688
- * | :--- | :-- | :-- |
689
- * | segmentIDs | Array | The segment ids |
690
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
691
-
692
- *
693
- *
694
- * @returns
695
- * | Property | Description |
696
- * | :--- | :-- |
697
- * | status | { error_code: number,reason:string } |
698
- * | flushed | segments flushed or not |
699
- *
700
- *
701
- * #### Example
702
- *
703
- * ```
704
- * const res = await milvusClient.getFlushState({
705
- * segmentIDs: segIds,
706
- * });
707
- * ```
708
- */
709
- Data.prototype.getFlushState = function (data) {
710
- return __awaiter(this, void 0, void 0, function () {
711
- var res;
712
- return __generator(this, function (_a) {
713
- switch (_a.label) {
714
- case 0:
715
- if (!data || !data.segmentIDs) {
716
- throw new Error(_1.ERROR_REASONS.GET_FLUSH_STATE_CHECK_PARAMS);
717
- }
718
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'GetFlushState', data, data.timeout || this.timeout)];
719
- case 1:
720
- res = _a.sent();
721
- return [2 /*return*/, res];
722
- }
723
- });
724
- });
725
- };
726
- /**
727
- * Do load balancing operation from source query node to destination query node.
728
- * Only work in cluster milvus.
729
- *
730
- * @param data
731
- * | Property | Type | Description |
732
- * | :--- | :-- | :-- |
733
- * | src_nodeID | number | The source query node id to balance. |
734
- * | dst_nodeIDs | number[] | The destination query node ids to balance.(optional) |
735
- * | sealed_segmentIDs | number[] | Sealed segment ids to balance.(optional) |
736
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
737
- *
738
- * @returns
739
- * | Property | Description |
740
- * | :--- | :-- |
741
- * | status | { error_code: number,reason:string } |
742
- * | infos | segments infomations |
743
- *
744
- *
745
- * #### Example
746
- *
747
- * ```
748
- * const res = await loadBalance({
749
- * src_nodeID: 31,
750
- * });
751
- * ```
752
- */
753
- Data.prototype.loadBalance = function (data) {
754
- return __awaiter(this, void 0, void 0, function () {
755
- var res;
756
- return __generator(this, function (_a) {
757
- switch (_a.label) {
758
- case 0:
759
- if (!data || !data.src_nodeID) {
760
- throw new Error(_1.ERROR_REASONS.LOAD_BALANCE_CHECK_PARAMS);
761
- }
762
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'LoadBalance', data, data.timeout || this.timeout)];
763
- case 1:
764
- res = _a.sent();
765
- return [2 /*return*/, res];
766
- }
767
- });
768
- });
769
- };
770
- /**
771
- * Notifies Proxy to return segments information from query nodes.
772
- *
773
- * @param data
774
- * | Property | Type | Description |
775
- * | :--- | :-- | :-- |
776
- * | collectionName | String | The name of the collection to get segments info. |
777
- * | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
778
- *
779
- *
780
- * @returns
781
- * | Property | Description |
782
- * | :--- | :-- |
783
- * | status | { error_code: number,reason:string } |
784
- * | infos | QuerySegmentInfo is the growing segments's information in query cluster. |
785
- *
786
- *
787
- * #### Example
788
- *
789
- * ```
790
- * const res = await getQuerySegmentInfo({
791
- * collectionName: COLLECTION,
792
- * });
793
- * ```
794
- */
795
- Data.prototype.getQuerySegmentInfo = function (data) {
796
- return __awaiter(this, void 0, void 0, function () {
797
- var res;
798
- return __generator(this, function (_a) {
799
- switch (_a.label) {
800
- case 0:
801
- if (!data || !data.collectionName) {
802
- throw new Error(_1.ERROR_REASONS.COLLECTION_NAME_IS_REQUIRED);
803
- }
804
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'GetQuerySegmentInfo', data, data.timeout || this.timeout)];
805
- case 1:
806
- res = _a.sent();
807
- return [2 /*return*/, res];
808
- }
809
- });
810
- });
811
- };
812
- /**
813
- * Import data from files
814
- *
815
- * @param data
816
- * | Property | Type | Description |
817
- * | :--- | :-- | :-- |
818
- * | collection_name | String | The name of the collection |
819
- * | files | string[] | File path array |
820
- *
821
- *
822
- * @returns
823
- * | Property | Description |
824
- * | :--- | :-- |
825
- * | status | { error_code: number,reason:string } |
826
- * | tasks | taskId array |
827
- *
828
- *
829
- * #### Example
830
- *
831
- * ```
832
- * const res = await bulkInsert({
833
- * collection_name: COLLECTION,
834
- * files: [`path-to-data-file.json`]
835
- * });
836
- * ```
837
- */
838
- /* istanbul ignore next */
839
- Data.prototype.bulkInsert = function (data) {
840
- return __awaiter(this, void 0, void 0, function () {
841
- var res;
842
- return __generator(this, function (_a) {
843
- switch (_a.label) {
844
- case 0:
845
- if (!data || !data.collection_name) {
846
- throw new Error(_1.ERROR_REASONS.COLLECTION_NAME_IS_REQUIRED);
847
- }
848
- if (!data || !data.files) {
849
- throw new Error(_1.ERROR_REASONS.IMPORT_FILE_CHECK);
850
- }
851
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'Import', __assign(__assign({}, data), { options: data.options || [] }), data.timeout || this.timeout)];
852
- case 1:
853
- res = _a.sent();
854
- return [2 /*return*/, res];
855
- }
856
- });
857
- });
858
- };
859
- /**
860
- * List import tasks
861
- *
862
- * @param data
863
- * | Property | Type | Description |
864
- * | :--- | :-- | :-- |
865
- * | collection_name | String | The name of the collection |
866
- * | limit | number | optional, maximum number of tasks returned, list all tasks if the value is 0 |
867
- *
868
- *
869
- * @returns
870
- * | Property | Description |
871
- * | :--- | :-- |
872
- * | status | { error_code: number,reason:string } |
873
- * | state | import state |
874
- * | row_count | how many rows to import|
875
- * | id_list| id lists |
876
- * | collection_id | collection to be imported to |
877
- * | tasks | taskId array |
878
- *
879
- *
880
- * #### Example
881
- *
882
- * ```
883
- * const res = await listImportTasks({
884
- * collection_name: COLLECTION
885
- * });
886
- * ```
887
- */
888
- /* istanbul ignore next */
889
- Data.prototype.listImportTasks = function (data) {
890
- return __awaiter(this, void 0, void 0, function () {
891
- var res;
892
- return __generator(this, function (_a) {
893
- switch (_a.label) {
894
- case 0:
895
- if (!data || !data.collection_name) {
896
- throw new Error(_1.ERROR_REASONS.COLLECTION_NAME_IS_REQUIRED);
897
- }
898
- return [4 /*yield*/, (0, utils_1.promisify)(this.client, 'ListImportTasks', __assign(__assign({}, data), { limit: data.limit || 0 }), data.timeout || this.timeout)];
899
- case 1:
900
- res = _a.sent();
901
- return [2 /*return*/, res];
902
- }
903
- });
904
- });
905
- };
906
- return Data;
907
- }(Collection_1.Collection));
908
- exports.Data = Data;
909
- //# sourceMappingURL=Data.js.map