@zilliz/milvus2-sdk-node 2.6.0 → 2.6.2
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.
- package/dist/milvus/MilvusClient.js +7 -1
- package/dist/milvus/MilvusClient.js.map +1 -1
- package/dist/milvus/const/milvus.d.ts +38 -4
- package/dist/milvus/const/milvus.js +41 -2
- package/dist/milvus/const/milvus.js.map +1 -1
- package/dist/milvus/grpc/BaseClient.d.ts +1 -0
- package/dist/milvus/grpc/BaseClient.js +1 -0
- package/dist/milvus/grpc/BaseClient.js.map +1 -1
- package/dist/milvus/grpc/Collection.d.ts +2 -2
- package/dist/milvus/grpc/Collection.js +23 -4
- package/dist/milvus/grpc/Collection.js.map +1 -1
- package/dist/milvus/grpc/Data.d.ts +58 -21
- package/dist/milvus/grpc/Data.js +153 -61
- package/dist/milvus/grpc/Data.js.map +1 -1
- package/dist/milvus/proto-json/milvus.base.d.ts +769 -8
- package/dist/milvus/proto-json/milvus.base.js +793 -11
- package/dist/milvus/proto-json/milvus.base.js.map +1 -1
- package/dist/milvus/proto-json/milvus.d.ts +769 -8
- package/dist/milvus/proto-json/milvus.js +793 -11
- package/dist/milvus/proto-json/milvus.js.map +1 -1
- package/dist/milvus/proto-json/schema.base.d.ts +212 -0
- package/dist/milvus/proto-json/schema.base.js +220 -5
- package/dist/milvus/proto-json/schema.base.js.map +1 -1
- package/dist/milvus/types/Collection.d.ts +8 -2
- package/dist/milvus/types/Common.d.ts +3 -0
- package/dist/milvus/types/Data.d.ts +1 -300
- package/dist/milvus/types/Data.js +0 -1
- package/dist/milvus/types/Data.js.map +1 -1
- package/dist/milvus/types/DataTypes.d.ts +35 -0
- package/dist/milvus/types/DataTypes.js +3 -0
- package/dist/milvus/types/DataTypes.js.map +1 -0
- package/dist/milvus/types/HighLevel.d.ts +1 -1
- package/dist/milvus/types/Insert.d.ts +66 -0
- package/dist/milvus/types/Insert.js +4 -0
- package/dist/milvus/types/Insert.js.map +1 -0
- package/dist/milvus/types/Search.d.ts +147 -0
- package/dist/milvus/types/Search.js +4 -0
- package/dist/milvus/types/Search.js.map +1 -0
- package/dist/milvus/types/Segments.d.ts +68 -0
- package/dist/milvus/types/Segments.js +3 -0
- package/dist/milvus/types/Segments.js.map +1 -0
- package/dist/milvus/types/index.d.ts +4 -0
- package/dist/milvus/types/index.js +4 -0
- package/dist/milvus/types/index.js.map +1 -1
- package/dist/milvus/types.d.ts +4 -0
- package/dist/milvus/types.js +4 -1
- package/dist/milvus/types.js.map +1 -1
- package/dist/milvus/utils/Bytes.d.ts +5 -5
- package/dist/milvus/utils/Bytes.js +11 -10
- package/dist/milvus/utils/Bytes.js.map +1 -1
- package/dist/milvus/utils/Connection.d.ts +14 -0
- package/dist/milvus/utils/Connection.js +24 -0
- package/dist/milvus/utils/Connection.js.map +1 -0
- package/dist/milvus/utils/Data.d.ts +43 -0
- package/dist/milvus/utils/Data.js +297 -0
- package/dist/milvus/utils/Data.js.map +1 -0
- package/dist/milvus/utils/Format.d.ts +1 -233
- package/dist/milvus/utils/Format.js +108 -728
- package/dist/milvus/utils/Format.js.map +1 -1
- package/dist/milvus/utils/Function.d.ts +1 -21
- package/dist/milvus/utils/Function.js +1 -79
- package/dist/milvus/utils/Function.js.map +1 -1
- package/dist/milvus/utils/Schema.d.ts +59 -0
- package/dist/milvus/utils/Schema.js +256 -0
- package/dist/milvus/utils/Schema.js.map +1 -0
- package/dist/milvus/utils/Search.d.ts +193 -0
- package/dist/milvus/utils/Search.js +419 -0
- package/dist/milvus/utils/Search.js.map +1 -0
- package/dist/milvus/utils/index.d.ts +4 -0
- package/dist/milvus/utils/index.js +4 -0
- package/dist/milvus/utils/index.js.map +1 -1
- package/dist/sdk.json +1 -1
- package/package.json +2 -2
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.
|
|
3
|
+
exports.formatDescribedCol = exports.cloneObj = exports.extractMethodName = exports.parseTimeToken = exports.formatAddress = exports.stringToBase64 = exports.datetimeToHybrids = exports.unixtimeToHybridts = exports.hybridtsToUnixtime = exports.checkTimeParam = exports.formatNumberPrecision = exports.parseToKeyValue = exports.formatKeyValueData = void 0;
|
|
15
4
|
const __1 = require("../");
|
|
16
5
|
/**
|
|
17
6
|
* Formats key-value data based on the provided keys.
|
|
@@ -35,10 +24,19 @@ exports.formatKeyValueData = formatKeyValueData;
|
|
|
35
24
|
*/
|
|
36
25
|
const parseToKeyValue = (data, valueToString) => {
|
|
37
26
|
return data
|
|
38
|
-
? Object.keys(data).reduce((pre, cur) =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
? Object.keys(data).reduce((pre, cur) => {
|
|
28
|
+
let value = data[cur];
|
|
29
|
+
if (valueToString) {
|
|
30
|
+
// Handle complex data types like objects and arrays
|
|
31
|
+
if (value && typeof value === 'object') {
|
|
32
|
+
value = JSON.stringify(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
value = String(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...pre, { key: cur, value }];
|
|
39
|
+
}, [])
|
|
42
40
|
: [];
|
|
43
41
|
};
|
|
44
42
|
exports.parseToKeyValue = parseToKeyValue;
|
|
@@ -140,44 +138,6 @@ const formatAddress = (address) => {
|
|
|
140
138
|
return address.replace(/(http|https)*:\/\//, '');
|
|
141
139
|
};
|
|
142
140
|
exports.formatAddress = formatAddress;
|
|
143
|
-
/**
|
|
144
|
-
* Assigns specified properties from the `field` object to `type_params` within the `FieldType` object.
|
|
145
|
-
* Converts properties to strings, serializing objects as JSON strings if needed, then removes them from `field`.
|
|
146
|
-
*
|
|
147
|
-
* @param field - The `FieldType` object to modify.
|
|
148
|
-
* @param typeParamKeys - Keys to assign to `type_params` if present in `field`.
|
|
149
|
-
* @returns The modified `FieldType` object.
|
|
150
|
-
*/
|
|
151
|
-
const assignTypeParams = (field, typeParamKeys = [
|
|
152
|
-
'dim',
|
|
153
|
-
'max_length',
|
|
154
|
-
'max_capacity',
|
|
155
|
-
'enable_match',
|
|
156
|
-
'enable_analyzer',
|
|
157
|
-
'analyzer_params',
|
|
158
|
-
'multi_analyzer_params',
|
|
159
|
-
'mmap.enabled',
|
|
160
|
-
]) => {
|
|
161
|
-
var _a;
|
|
162
|
-
const newField = (0, exports.cloneObj)(field);
|
|
163
|
-
// Initialize `type_params` if undefined
|
|
164
|
-
(_a = newField.type_params) !== null && _a !== void 0 ? _a : (newField.type_params = {});
|
|
165
|
-
typeParamKeys.forEach(key => {
|
|
166
|
-
if (key in newField) {
|
|
167
|
-
const value = newField[key];
|
|
168
|
-
// Convert the value to a string, JSON-stringify if it's an object
|
|
169
|
-
newField.type_params[key] =
|
|
170
|
-
typeof value === 'object' ? JSON.stringify(value) : String(value !== null && value !== void 0 ? value : '');
|
|
171
|
-
delete newField[key];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
// delete type_params if it's empty
|
|
175
|
-
if (!Object.keys(newField.type_params).length) {
|
|
176
|
-
delete newField.type_params;
|
|
177
|
-
}
|
|
178
|
-
return newField;
|
|
179
|
-
};
|
|
180
|
-
exports.assignTypeParams = assignTypeParams;
|
|
181
141
|
/**
|
|
182
142
|
* Parses a time token and returns the corresponding number of milliseconds.
|
|
183
143
|
*
|
|
@@ -219,22 +179,6 @@ const extractMethodName = (query) => {
|
|
|
219
179
|
return parts[parts.length - 1];
|
|
220
180
|
};
|
|
221
181
|
exports.extractMethodName = extractMethodName;
|
|
222
|
-
/**
|
|
223
|
-
* Converts a `key` of type `keyof typeof DataTypeMap | DataType` to a `DataType`.
|
|
224
|
-
*
|
|
225
|
-
* @param {keyof typeof DataTypeMap | DataType} key - The key to convert.
|
|
226
|
-
* @returns {DataType} The converted `DataType`.
|
|
227
|
-
*/
|
|
228
|
-
const convertToDataType = (key) => {
|
|
229
|
-
if (typeof key === 'string' && key in __1.DataTypeMap) {
|
|
230
|
-
return __1.DataType[key];
|
|
231
|
-
}
|
|
232
|
-
else if (typeof key === 'number' && Object.values(__1.DataType).includes(key)) {
|
|
233
|
-
return key;
|
|
234
|
-
}
|
|
235
|
-
throw new Error(__1.ERROR_REASONS.FIELD_TYPE_IS_NOT_SUPPORT);
|
|
236
|
-
};
|
|
237
|
-
exports.convertToDataType = convertToDataType;
|
|
238
182
|
/**dd
|
|
239
183
|
* Creates a deep copy of the provided object using JSON.parse and JSON.stringify.
|
|
240
184
|
* Note that this function is not efficient and may cause performance issues if used with large or complex objects. It also does not handle cases where the object being cloned contains functions or prototype methods.
|
|
@@ -247,66 +191,6 @@ const cloneObj = (obj) => {
|
|
|
247
191
|
return JSON.parse(JSON.stringify(obj));
|
|
248
192
|
};
|
|
249
193
|
exports.cloneObj = cloneObj;
|
|
250
|
-
/**
|
|
251
|
-
* Formats the input data into a request payload for creating a collection.
|
|
252
|
-
*
|
|
253
|
-
* @param {CreateCollectionReq} data - The input data for creating a collection.
|
|
254
|
-
* @param {Type} schemaType - The schema type for the collection.
|
|
255
|
-
* @returns {Object} The formatted request payload.
|
|
256
|
-
*/
|
|
257
|
-
const formatCollectionSchema = (data, schemaTypes) => {
|
|
258
|
-
const { collection_name, description, enable_dynamic_field, enableDynamicField, partition_key_field, functions, clustring_key_field, } = data;
|
|
259
|
-
let fields = data.fields;
|
|
260
|
-
if (data.schema) {
|
|
261
|
-
fields = data.schema;
|
|
262
|
-
}
|
|
263
|
-
let payload = {};
|
|
264
|
-
const functionOutputFields = [];
|
|
265
|
-
// if functions is set, parse its params to key-value pairs, and delete inputs and outputs
|
|
266
|
-
if (functions) {
|
|
267
|
-
payload.functions = functions.map((func) => {
|
|
268
|
-
const { input_field_names, output_field_names } = func, rest = __rest(func, ["input_field_names", "output_field_names"]);
|
|
269
|
-
functionOutputFields.push(...(output_field_names || []));
|
|
270
|
-
return schemaTypes.functionSchemaType.create(Object.assign(Object.assign({}, rest), { inputFieldNames: input_field_names || [], outputFieldNames: output_field_names || [], params: (0, exports.parseToKeyValue)(func.params, true) }));
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
payload = Object.assign({ name: collection_name, description: description || '', enableDynamicField: !!enableDynamicField || !!enable_dynamic_field, fields: fields.map(field => (0, exports.formatFieldSchema)(field, schemaTypes, {
|
|
274
|
-
partition_key_field,
|
|
275
|
-
functionOutputFields,
|
|
276
|
-
clustring_key_field,
|
|
277
|
-
})) }, payload);
|
|
278
|
-
return payload;
|
|
279
|
-
};
|
|
280
|
-
exports.formatCollectionSchema = formatCollectionSchema;
|
|
281
|
-
/**
|
|
282
|
-
* Formats a field schema by converting its properties to the appropriate types and adding additional properties.
|
|
283
|
-
*
|
|
284
|
-
* @param {FieldType} field - The field to format.
|
|
285
|
-
* @param {Record<string, Type>} schemaTypes - The schema types to use for formatting.
|
|
286
|
-
* @param {Object} [override] - Optional override object for additional properties.
|
|
287
|
-
* @returns {Object} The formatted field schema.
|
|
288
|
-
*/
|
|
289
|
-
const formatFieldSchema = (field, schemaTypes, override) => {
|
|
290
|
-
const { partition_key_field, functionOutputFields = [], clustring_key_field, } = override || {};
|
|
291
|
-
// Assign the typeParams property to the result of parseToKeyValue(type_params).
|
|
292
|
-
const _a = (0, exports.assignTypeParams)(field), { type_params, data_type, element_type, is_function_output, is_partition_key, is_primary_key } = _a, rest = __rest(_a, ["type_params", "data_type", "element_type", "is_function_output", "is_partition_key", "is_primary_key"]);
|
|
293
|
-
const dataType = (0, exports.convertToDataType)(field.data_type);
|
|
294
|
-
const createObj = Object.assign(Object.assign({}, rest), { typeParams: (0, exports.parseToKeyValue)(type_params), data_type,
|
|
295
|
-
dataType, isPrimaryKey: !!is_primary_key, isPartitionKey: !!is_partition_key || field.name === partition_key_field, isFunctionOutput: !!is_function_output || functionOutputFields.includes(field.name), isClusteringKey: !!field.is_clustering_key || field.name === clustring_key_field });
|
|
296
|
-
// if element type exist and
|
|
297
|
-
if (dataType === __1.DataType.Array && typeof element_type !== 'undefined') {
|
|
298
|
-
createObj.elementType = (0, exports.convertToDataType)(element_type);
|
|
299
|
-
createObj.element_type = element_type; // compatibility with old version
|
|
300
|
-
}
|
|
301
|
-
if (typeof field.default_value !== 'undefined') {
|
|
302
|
-
const dataKey = (0, __1.getDataKey)(createObj.dataType, true);
|
|
303
|
-
createObj.defaultValue = {
|
|
304
|
-
[dataKey]: field.default_value,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
return schemaTypes.fieldSchemaType.create(createObj);
|
|
308
|
-
};
|
|
309
|
-
exports.formatFieldSchema = formatFieldSchema;
|
|
310
194
|
/**
|
|
311
195
|
* Formats a `DescribeCollectionResponse` object by adding a `dataType` property to each field object in its `schema` array.
|
|
312
196
|
* The `dataType` property represents the numerical value of the `data_type` property.
|
|
@@ -318,616 +202,112 @@ const formatDescribedCol = (data) => {
|
|
|
318
202
|
var _a, _b;
|
|
319
203
|
// clone object
|
|
320
204
|
const newData = (0, exports.cloneObj)(data);
|
|
205
|
+
// merge fields and struct_array_fields
|
|
206
|
+
newData.schema.fields = [
|
|
207
|
+
...newData.schema.fields,
|
|
208
|
+
...(newData.schema.struct_array_fields || []),
|
|
209
|
+
];
|
|
321
210
|
// add a dataType property which indicate datatype number
|
|
322
|
-
|
|
323
|
-
|
|
211
|
+
const formatField = (field, isEmbList = false) => {
|
|
212
|
+
field.dataType = __1.DataTypeMap[field.data_type];
|
|
213
|
+
// used for search type
|
|
214
|
+
switch (field.dataType) {
|
|
215
|
+
case __1.DataType.FloatVector:
|
|
216
|
+
field._placeholderType = isEmbList
|
|
217
|
+
? __1.PlaceholderType.EmbListFloatVector
|
|
218
|
+
: __1.PlaceholderType.FloatVector;
|
|
219
|
+
break;
|
|
220
|
+
case __1.DataType.BinaryVector:
|
|
221
|
+
field._placeholderType = isEmbList
|
|
222
|
+
? __1.PlaceholderType.EmbListBinaryVector
|
|
223
|
+
: __1.PlaceholderType.BinaryVector;
|
|
224
|
+
break;
|
|
225
|
+
case __1.DataType.BFloat16Vector:
|
|
226
|
+
field._placeholderType = isEmbList
|
|
227
|
+
? __1.PlaceholderType.EmbListBFloat16Vector
|
|
228
|
+
: __1.PlaceholderType.BFloat16Vector;
|
|
229
|
+
break;
|
|
230
|
+
case __1.DataType.Float16Vector:
|
|
231
|
+
field._placeholderType = isEmbList
|
|
232
|
+
? __1.PlaceholderType.EmbListFloat16Vector
|
|
233
|
+
: __1.PlaceholderType.Float16Vector;
|
|
234
|
+
break;
|
|
235
|
+
case __1.DataType.Int8Vector:
|
|
236
|
+
field._placeholderType = isEmbList
|
|
237
|
+
? __1.PlaceholderType.EmbListInt8Vector
|
|
238
|
+
: __1.PlaceholderType.Int8Vector;
|
|
239
|
+
break;
|
|
240
|
+
case __1.DataType.SparseFloatVector:
|
|
241
|
+
if (field.is_function_output) {
|
|
242
|
+
field._placeholderType = __1.PlaceholderType.VarChar;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
field._placeholderType = isEmbList
|
|
246
|
+
? __1.PlaceholderType.EmbListSparseFloatVector
|
|
247
|
+
: __1.PlaceholderType.SparseFloatVector;
|
|
248
|
+
break;
|
|
249
|
+
default:
|
|
250
|
+
field._placeholderType = field.dataType;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
324
253
|
// if default_value is set, parse it to the correct format
|
|
325
|
-
if (
|
|
326
|
-
const defaultValue =
|
|
327
|
-
|
|
254
|
+
if (field.default_value) {
|
|
255
|
+
const defaultValue = field.default_value;
|
|
256
|
+
field.default_value = defaultValue[defaultValue.data];
|
|
328
257
|
}
|
|
329
258
|
// extract type params(key value pair = {key: 'xxx', value: any}), and assign it to the field object(key)
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
259
|
+
if (field.type_params && field.type_params.length > 0) {
|
|
260
|
+
field.type_params.forEach((keyValuePair) => {
|
|
261
|
+
field[keyValuePair.key] = keyValuePair.value;
|
|
333
262
|
});
|
|
334
263
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const originRow = (0, exports.cloneObj)(rowData);
|
|
349
|
-
const row = {};
|
|
350
|
-
// iterate through each key in the input data object
|
|
351
|
-
for (let key in originRow) {
|
|
352
|
-
row[dynamicFieldName] = row[dynamicFieldName] || {}; // initialize the dynamic field object
|
|
353
|
-
if (fieldMap.has(key)) {
|
|
354
|
-
// if the key is in the fieldMap, add it to the non-dynamic fields
|
|
355
|
-
row[key] = originRow[key];
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
if (!functionOutputFields.includes(key)) {
|
|
359
|
-
const obj = row[dynamicFieldName];
|
|
360
|
-
// otherwise, add it to the dynamic field
|
|
361
|
-
obj[key] = originRow[key];
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return row; // return the generated dynamic row object
|
|
366
|
-
};
|
|
367
|
-
exports.buildDynamicRow = buildDynamicRow;
|
|
368
|
-
/**
|
|
369
|
-
* create a data map for each fields, resolve grpc data format
|
|
370
|
-
* If the field is a vector, split the data into chunks of the appropriate size.
|
|
371
|
-
* If the field is a scalar, decode the JSON/array data if necessary.
|
|
372
|
-
*/
|
|
373
|
-
const buildFieldDataMap = (fields_data, transformers) => {
|
|
374
|
-
const fieldsDataMap = new Map();
|
|
375
|
-
fields_data.forEach((item, i) => {
|
|
376
|
-
var _a;
|
|
377
|
-
// field data
|
|
378
|
-
let field_data;
|
|
379
|
-
// parse vector data
|
|
380
|
-
if (item.field === 'vectors') {
|
|
381
|
-
const dataKey = item.vectors.data;
|
|
382
|
-
switch (dataKey) {
|
|
383
|
-
case 'float_vector':
|
|
384
|
-
case 'binary_vector':
|
|
385
|
-
const vectorValue = dataKey === 'float_vector'
|
|
386
|
-
? item.vectors[dataKey].data
|
|
387
|
-
: item.vectors[dataKey].toJSON().data;
|
|
388
|
-
// if binary vector , need use dim / 8 to split vector data
|
|
389
|
-
const dim = ((_a = item.vectors) === null || _a === void 0 ? void 0 : _a.data) === 'float_vector'
|
|
390
|
-
? Number(item.vectors.dim)
|
|
391
|
-
: Number(item.vectors.dim) / 8;
|
|
392
|
-
field_data = [];
|
|
393
|
-
// parse number[] to number[][] by dim
|
|
394
|
-
vectorValue.forEach((v, i) => {
|
|
395
|
-
const index = Math.floor(i / dim);
|
|
396
|
-
if (!field_data[index]) {
|
|
397
|
-
field_data[index] = [];
|
|
398
|
-
}
|
|
399
|
-
field_data[index].push(v);
|
|
400
|
-
});
|
|
401
|
-
break;
|
|
402
|
-
case 'int8_vector':
|
|
403
|
-
field_data = [];
|
|
404
|
-
const int8Dim = Number(item.vectors.dim);
|
|
405
|
-
const int8Bytes = item.vectors[dataKey];
|
|
406
|
-
const localTransformers = Object.assign({ [__1.DataType.Int8Vector]: Array.from }, transformers);
|
|
407
|
-
// split buffer data to int8 vector
|
|
408
|
-
for (let i = 0; i < int8Bytes.byteLength; i += int8Dim) {
|
|
409
|
-
const slice = int8Bytes.slice(i, i + int8Dim);
|
|
410
|
-
field_data.push(localTransformers[__1.DataType.Int8Vector](slice));
|
|
411
|
-
}
|
|
412
|
-
break;
|
|
413
|
-
case 'float16_vector':
|
|
414
|
-
case 'bfloat16_vector':
|
|
415
|
-
field_data = [];
|
|
416
|
-
const f16Dim = Number(item.vectors.dim) * 2; // float16 is 2 bytes, so we need to multiply dim with 2 = one element length
|
|
417
|
-
const f16Bytes = item.vectors[dataKey];
|
|
418
|
-
// split buffer data to float16 vector(bytes)
|
|
419
|
-
for (let i = 0; i < f16Bytes.byteLength; i += f16Dim) {
|
|
420
|
-
const slice = f16Bytes.slice(i, i + f16Dim);
|
|
421
|
-
const isFloat16 = dataKey === 'float16_vector';
|
|
422
|
-
let dataType;
|
|
423
|
-
dataType = isFloat16
|
|
424
|
-
? __1.DataType.Float16Vector
|
|
425
|
-
: __1.DataType.BFloat16Vector;
|
|
426
|
-
const localTransformers = Object.assign({ [__1.DataType.BFloat16Vector]: __1.bf16BytesToF32Array, [__1.DataType.Float16Vector]: __1.f16BytesToF32Array }, transformers);
|
|
427
|
-
field_data.push(localTransformers[dataType](slice));
|
|
428
|
-
}
|
|
429
|
-
break;
|
|
430
|
-
case 'sparse_float_vector':
|
|
431
|
-
const sparseVectorValue = item.vectors[dataKey].contents;
|
|
432
|
-
field_data = [];
|
|
433
|
-
sparseVectorValue.forEach((buffer, i) => {
|
|
434
|
-
field_data[i] = (0, __1.bytesToSparseRow)(buffer);
|
|
435
|
-
});
|
|
436
|
-
break;
|
|
437
|
-
default:
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
// parse scalar data
|
|
443
|
-
const dataKey = item.scalars.data;
|
|
444
|
-
field_data = item.scalars[dataKey].data;
|
|
445
|
-
// we need to handle array element specifically here
|
|
446
|
-
if (dataKey === 'array_data') {
|
|
447
|
-
field_data = field_data.map((f) => {
|
|
448
|
-
const dataKey = f.data;
|
|
449
|
-
return dataKey ? f[dataKey].data : [];
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
switch (dataKey) {
|
|
453
|
-
// decode json
|
|
454
|
-
case 'json_data':
|
|
455
|
-
field_data.forEach((buffer, i) => {
|
|
456
|
-
field_data[i] = buffer.length
|
|
457
|
-
? JSON.parse(buffer.toString())
|
|
458
|
-
: null;
|
|
459
|
-
});
|
|
460
|
-
break;
|
|
461
|
-
default:
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
// set the field data with null if item.valid_data is not empty array, it the item in valid_data is false, set the field data with null
|
|
465
|
-
if (item.valid_data && item.valid_data.length) {
|
|
466
|
-
item.valid_data.forEach((v, i) => {
|
|
467
|
-
if (!v) {
|
|
468
|
-
field_data[i] = null;
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
}
|
|
264
|
+
// recursively format nested fields for struct types
|
|
265
|
+
if (field.fields && field.fields.length > 0) {
|
|
266
|
+
field.dataType = __1.DataType.Array;
|
|
267
|
+
field.data_type = 'Array';
|
|
268
|
+
field.elementType = __1.DataType.Struct;
|
|
269
|
+
field.element_type = 'Struct';
|
|
270
|
+
field.fields.forEach((childField) => {
|
|
271
|
+
childField.data_type = childField.element_type;
|
|
272
|
+
delete childField.element_type;
|
|
273
|
+
// delete max_capacity in type_params array
|
|
274
|
+
childField.type_params = childField.type_params.filter((keyValuePair) => keyValuePair.key !== 'max_capacity');
|
|
275
|
+
formatField(childField, true);
|
|
276
|
+
});
|
|
472
277
|
}
|
|
473
|
-
// Add the parsed data to the fieldsDataMap
|
|
474
|
-
fieldsDataMap.set(item.field_name, field_data);
|
|
475
|
-
});
|
|
476
|
-
return fieldsDataMap;
|
|
477
|
-
};
|
|
478
|
-
exports.buildFieldDataMap = buildFieldDataMap;
|
|
479
|
-
/**
|
|
480
|
-
* Generates an authentication string based on the provided credentials.
|
|
481
|
-
*
|
|
482
|
-
* @param {Object} data - An object containing the authentication credentials.
|
|
483
|
-
* @param {string} [data.username] - The username to use for authentication.
|
|
484
|
-
* @param {string} [data.password] - The password to use for authentication.
|
|
485
|
-
* @param {string} [data.token] - The token to use for authentication.
|
|
486
|
-
* @returns {string} The authentication string.
|
|
487
|
-
*/
|
|
488
|
-
const getAuthString = (data) => {
|
|
489
|
-
const { username, password, token } = data;
|
|
490
|
-
// build auth string
|
|
491
|
-
const authString = token ? token : `${username}:${password}`;
|
|
492
|
-
// Encode the username and password as a base64 string.
|
|
493
|
-
let auth = Buffer.from(authString, 'utf-8').toString('base64');
|
|
494
|
-
// if we need to create auth interceptors
|
|
495
|
-
const needAuth = (!!username && !!password) || !!token;
|
|
496
|
-
return needAuth ? auth : '';
|
|
497
|
-
};
|
|
498
|
-
exports.getAuthString = getAuthString;
|
|
499
|
-
/**
|
|
500
|
-
* Builds the field data for a given row and column.
|
|
501
|
-
*
|
|
502
|
-
* @param {RowData} rowData - The data for the row.
|
|
503
|
-
* @param {Field} column - The column information.
|
|
504
|
-
* @returns {FieldData} The field data for the row and column.
|
|
505
|
-
*/
|
|
506
|
-
const buildFieldData = (rowData, field, transformers) => {
|
|
507
|
-
const { type, elementType, name } = field;
|
|
508
|
-
const isFloat32 = Array.isArray(rowData[name]);
|
|
509
|
-
switch (__1.DataTypeMap[type]) {
|
|
510
|
-
case __1.DataType.BinaryVector:
|
|
511
|
-
case __1.DataType.FloatVector:
|
|
512
|
-
case __1.DataType.Int8Vector:
|
|
513
|
-
return rowData[name];
|
|
514
|
-
case __1.DataType.BFloat16Vector:
|
|
515
|
-
const bf16Transformer = (transformers === null || transformers === void 0 ? void 0 : transformers[__1.DataType.BFloat16Vector]) || __1.f32ArrayToBf16Bytes;
|
|
516
|
-
return isFloat32
|
|
517
|
-
? bf16Transformer(rowData[name])
|
|
518
|
-
: rowData[name];
|
|
519
|
-
case __1.DataType.Float16Vector:
|
|
520
|
-
const f16Transformer = (transformers === null || transformers === void 0 ? void 0 : transformers[__1.DataType.Float16Vector]) || __1.f32ArrayToF16Bytes;
|
|
521
|
-
return isFloat32
|
|
522
|
-
? f16Transformer(rowData[name])
|
|
523
|
-
: rowData[name];
|
|
524
|
-
case __1.DataType.JSON:
|
|
525
|
-
return rowData[name]
|
|
526
|
-
? Buffer.from(JSON.stringify(rowData[name] || {}))
|
|
527
|
-
: Buffer.alloc(0);
|
|
528
|
-
case __1.DataType.Array:
|
|
529
|
-
const elementField = Object.assign(Object.assign({}, field), { type: elementType });
|
|
530
|
-
return rowData[name] === null
|
|
531
|
-
? undefined
|
|
532
|
-
: (0, exports.buildFieldData)(rowData, elementField, transformers);
|
|
533
|
-
default:
|
|
534
|
-
return rowData[name] === null ? undefined : rowData[name];
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
exports.buildFieldData = buildFieldData;
|
|
538
|
-
/**
|
|
539
|
-
* Builds search parameters based on the provided data.
|
|
540
|
-
* @param data - The data object containing search parameters.
|
|
541
|
-
* @returns The search parameters in key-value format.
|
|
542
|
-
*/
|
|
543
|
-
const buildSearchParams = (data, anns_field) => {
|
|
544
|
-
var _a, _b, _c, _d, _e, _f;
|
|
545
|
-
// create search params
|
|
546
|
-
const search_params = {
|
|
547
|
-
anns_field: data.anns_field || anns_field,
|
|
548
|
-
params: JSON.stringify((_a = data.params) !== null && _a !== void 0 ? _a : {}),
|
|
549
|
-
topk: (_c = (_b = data.limit) !== null && _b !== void 0 ? _b : data.topk) !== null && _c !== void 0 ? _c : __1.DEFAULT_TOPK,
|
|
550
|
-
offset: (_d = data.offset) !== null && _d !== void 0 ? _d : 0,
|
|
551
|
-
metric_type: (_e = data.metric_type) !== null && _e !== void 0 ? _e : '',
|
|
552
|
-
ignore_growing: (_f = data.ignore_growing) !== null && _f !== void 0 ? _f : false,
|
|
553
278
|
};
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
for (let key in data.params) {
|
|
570
|
-
search_params[key] = data.params[key];
|
|
571
|
-
}
|
|
572
|
-
return search_params;
|
|
573
|
-
};
|
|
574
|
-
exports.buildSearchParams = buildSearchParams;
|
|
575
|
-
/**
|
|
576
|
-
* Creates a RRFRanker object with the specified value of k.
|
|
577
|
-
* @param k - The value of k used in the RRFRanker strategy.
|
|
578
|
-
* @returns An object representing the RRFRanker strategy with the specified value of k.
|
|
579
|
-
*/
|
|
580
|
-
const RRFRanker = (k = 60) => {
|
|
581
|
-
return {
|
|
582
|
-
strategy: __1.RANKER_TYPE.RRF,
|
|
583
|
-
params: {
|
|
584
|
-
k,
|
|
585
|
-
},
|
|
586
|
-
};
|
|
587
|
-
};
|
|
588
|
-
exports.RRFRanker = RRFRanker;
|
|
589
|
-
/**
|
|
590
|
-
* Creates a weighted ranker object.
|
|
591
|
-
* @param weights - An array of numbers representing the weights.
|
|
592
|
-
* @returns The weighted ranker object.
|
|
593
|
-
*/
|
|
594
|
-
const WeightedRanker = (weights) => {
|
|
595
|
-
return {
|
|
596
|
-
strategy: __1.RANKER_TYPE.WEIGHTED,
|
|
597
|
-
params: {
|
|
598
|
-
weights,
|
|
599
|
-
},
|
|
600
|
-
};
|
|
601
|
-
};
|
|
602
|
-
exports.WeightedRanker = WeightedRanker;
|
|
603
|
-
/**
|
|
604
|
-
* Converts the rerank parameters object to a format suitable for API requests.
|
|
605
|
-
* @param rerank - The rerank parameters object.
|
|
606
|
-
* @returns The converted rerank parameters object.
|
|
607
|
-
*/
|
|
608
|
-
const convertRerankParams = (rerank) => {
|
|
609
|
-
const r = (0, exports.cloneObj)(rerank);
|
|
610
|
-
r.params = JSON.stringify(r.params);
|
|
611
|
-
return r;
|
|
612
|
-
};
|
|
613
|
-
exports.convertRerankParams = convertRerankParams;
|
|
614
|
-
/**
|
|
615
|
-
* Creates function_score object for search requests
|
|
616
|
-
* @param isRerankFunction - Whether the rerank is a function object
|
|
617
|
-
* @param searchHybridReq - The hybrid search request
|
|
618
|
-
* @param schemaTypes - Schema types for creating function objects
|
|
619
|
-
* @returns Function score object or empty object
|
|
620
|
-
*/
|
|
621
|
-
const createFunctionScore = (hasRerankFunction, searchHybridReq) => {
|
|
622
|
-
if (!hasRerankFunction) {
|
|
623
|
-
return {};
|
|
624
|
-
}
|
|
625
|
-
return {
|
|
626
|
-
function_score: {
|
|
627
|
-
functions: [searchHybridReq.rerank].map((func) => {
|
|
628
|
-
const { input_field_names, output_field_names } = func, rest = __rest(func, ["input_field_names", "output_field_names"]);
|
|
629
|
-
const result = Object.assign(Object.assign({}, rest), { input_field_names: input_field_names || [], output_field_names: output_field_names || [], params: (0, exports.parseToKeyValue)(func.params, true) });
|
|
630
|
-
return result;
|
|
631
|
-
}),
|
|
632
|
-
params: [],
|
|
633
|
-
},
|
|
634
|
-
};
|
|
635
|
-
};
|
|
636
|
-
/**
|
|
637
|
-
* This method is used to build search request for a given data.
|
|
638
|
-
* It first fetches the collection info and then constructs the search request based on the data type.
|
|
639
|
-
* It also creates search vectors and a placeholder group for the search.
|
|
640
|
-
*
|
|
641
|
-
* @param {SearchReq | SearchSimpleReq | HybridSearchReq} data - The data for which to build the search request.
|
|
642
|
-
* @param {DescribeCollectionResponse} collectionInfo - The collection information.
|
|
643
|
-
* @param {Root} milvusProto - The milvus protocol object.
|
|
644
|
-
* @returns {Object} An object containing the search requests and search vectors.
|
|
645
|
-
* @returns {Object} return.params - The search requests used in the operation.
|
|
646
|
-
* @returns {string} return.params.collection_name - The name of the collection.
|
|
647
|
-
* @returns {string[]} return.params.partition_names - The partition names.
|
|
648
|
-
* @returns {string[]} return.params.output_fields - The output fields.
|
|
649
|
-
* @returns {number} return.params.nq - The number of query vectors.
|
|
650
|
-
* @returns {string} return.params.dsl - The domain specific language.
|
|
651
|
-
* @returns {string} return.params.dsl_type - The type of the domain specific language.
|
|
652
|
-
* @returns {Uint8Array} return.params.placeholder_group - The placeholder group.
|
|
653
|
-
* @returns {Object} return.params.search_params - The search parameters.
|
|
654
|
-
* @returns {string} return.params.consistency_level - The consistency level.
|
|
655
|
-
* @returns {Number[][]} return.searchVectors - The search vectors used in the operation.
|
|
656
|
-
* @returns {number} return.round_decimal - The score precision.
|
|
657
|
-
*/
|
|
658
|
-
const buildSearchRequest = (params, collectionInfo, milvusProto) => {
|
|
659
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
660
|
-
// type cast
|
|
661
|
-
const searchReq = params;
|
|
662
|
-
const searchHybridReq = params;
|
|
663
|
-
const searchSimpleReq = params;
|
|
664
|
-
const searchSimpleOrHybridReq = params;
|
|
665
|
-
const hasRerankFunction = !!(searchSimpleOrHybridReq.rerank &&
|
|
666
|
-
typeof searchSimpleOrHybridReq.rerank === 'object' &&
|
|
667
|
-
'type' in searchSimpleOrHybridReq.rerank);
|
|
668
|
-
// Initialize requests array
|
|
669
|
-
const requests = [];
|
|
670
|
-
// detect if the request is hybrid search request
|
|
671
|
-
const isHybridSearch = !!(searchHybridReq.data &&
|
|
672
|
-
searchHybridReq.data.length &&
|
|
673
|
-
typeof searchHybridReq.data[0] === 'object' &&
|
|
674
|
-
searchHybridReq.data[0].anns_field);
|
|
675
|
-
// output fields(reference fields)
|
|
676
|
-
const default_output_fields = ['*'];
|
|
677
|
-
// Iterate through collection fields, create search request
|
|
678
|
-
for (let i = 0; i < collectionInfo.schema.fields.length; i++) {
|
|
679
|
-
const field = collectionInfo.schema.fields[i];
|
|
680
|
-
const { name, dataType } = field;
|
|
681
|
-
// if field type is vector, build the request
|
|
682
|
-
if ((0, __1.isVectorType)(dataType)) {
|
|
683
|
-
let req = params;
|
|
684
|
-
if (isHybridSearch) {
|
|
685
|
-
const singleReq = searchHybridReq.data.find(d => d.anns_field === name);
|
|
686
|
-
// if it is hybrid search and no request target is not found, skip
|
|
687
|
-
if (!singleReq) {
|
|
688
|
-
continue;
|
|
279
|
+
const anns_fields = {};
|
|
280
|
+
const scalar_fields = {};
|
|
281
|
+
const function_fields = {};
|
|
282
|
+
(_b = (_a = newData.schema) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.forEach((f) => {
|
|
283
|
+
formatField(f);
|
|
284
|
+
// loop through every fields and struct fields
|
|
285
|
+
// check if the field is the vector field
|
|
286
|
+
if ((0, __1.isVectorType)(f.dataType)) {
|
|
287
|
+
anns_fields[f.name] = f;
|
|
288
|
+
}
|
|
289
|
+
else if (f.dataType === __1.DataType.Array &&
|
|
290
|
+
f.elementType === __1.DataType.Struct) {
|
|
291
|
+
f.fields.forEach((childField) => {
|
|
292
|
+
if ((0, __1.isVectorType)(childField.dataType)) {
|
|
293
|
+
anns_fields[`${f.name}[${childField.name}]`] = childField;
|
|
689
294
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
// if it is not hybrid search, and we have built one request
|
|
695
|
-
// or user has specified an anns_field to search and is not matching
|
|
696
|
-
// skip
|
|
697
|
-
const skip = requests.length === 1 ||
|
|
698
|
-
(typeof req.anns_field !== 'undefined' && req.anns_field !== name);
|
|
699
|
-
if (skip) {
|
|
700
|
-
continue;
|
|
295
|
+
else {
|
|
296
|
+
scalar_fields[`${f.name}[${childField.name}]`] = childField;
|
|
701
297
|
}
|
|
702
|
-
}
|
|
703
|
-
// get search data
|
|
704
|
-
let searchData = isHybridSearch
|
|
705
|
-
? req.data
|
|
706
|
-
: searchReq.vectors ||
|
|
707
|
-
searchSimpleReq.vectors ||
|
|
708
|
-
searchSimpleReq.vector ||
|
|
709
|
-
searchSimpleReq.data;
|
|
710
|
-
// format searching data
|
|
711
|
-
searchData = (0, exports.formatSearchData)(searchData, field);
|
|
712
|
-
// create search request
|
|
713
|
-
const request = {
|
|
714
|
-
collection_name: req.collection_name,
|
|
715
|
-
partition_names: req.partition_names || [],
|
|
716
|
-
output_fields: req.output_fields || default_output_fields,
|
|
717
|
-
nq: searchReq.nq || searchData.length,
|
|
718
|
-
dsl: req.expr || searchReq.expr || searchSimpleReq.filter || '',
|
|
719
|
-
dsl_type: __1.DslType.BoolExprV1,
|
|
720
|
-
placeholder_group: (0, __1.buildPlaceholderGroupBytes)(milvusProto, searchData, field),
|
|
721
|
-
search_params: (0, exports.parseToKeyValue)(searchReq.search_params || (0, exports.buildSearchParams)(req, name)),
|
|
722
|
-
consistency_level: req.consistency_level || collectionInfo.consistency_level,
|
|
723
|
-
};
|
|
724
|
-
// if exprValues is set, add it to the request(inner)
|
|
725
|
-
if (req.exprValues) {
|
|
726
|
-
request.expr_template_values = (0, exports.formatExprValues)(req.exprValues);
|
|
727
|
-
}
|
|
728
|
-
requests.push(request);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* It will decide the score precision.
|
|
733
|
-
* If round_decimal is 3, need return like 3.142
|
|
734
|
-
* And if Milvus return like 3.142, Node will add more number after this like 3.142000047683716.
|
|
735
|
-
* So the score need to slice by round_decimal
|
|
736
|
-
*/
|
|
737
|
-
const round_decimal = (_d = (_b = (_a = searchReq.search_params) === null || _a === void 0 ? void 0 : _a.round_decimal) !== null && _b !== void 0 ? _b : (_c = searchSimpleReq.params) === null || _c === void 0 ? void 0 : _c.round_decimal) !== null && _d !== void 0 ? _d : -1;
|
|
738
|
-
// if no anns_field found in search request, throw error
|
|
739
|
-
if (requests.length === 0) {
|
|
740
|
-
throw new Error(__1.ERROR_REASONS.NO_ANNS_FEILD_FOUND_IN_SEARCH);
|
|
741
|
-
}
|
|
742
|
-
return Object.assign(Object.assign({ isHybridSearch: isHybridSearch, request: isHybridSearch
|
|
743
|
-
? Object.assign(Object.assign({ collection_name: params.collection_name, partition_names: params.partition_names, requests: requests, output_fields: (_e = requests[0]) === null || _e === void 0 ? void 0 : _e.output_fields, consistency_level: (_f = requests[0]) === null || _f === void 0 ? void 0 : _f.consistency_level }, createFunctionScore(hasRerankFunction, searchHybridReq)), {
|
|
744
|
-
rank_params: [
|
|
745
|
-
...(!hasRerankFunction
|
|
746
|
-
? (0, exports.parseToKeyValue)((0, exports.convertRerankParams)((0, exports.RRFRanker)()))
|
|
747
|
-
: []),
|
|
748
|
-
{ key: 'round_decimal', value: round_decimal },
|
|
749
|
-
{
|
|
750
|
-
key: 'limit',
|
|
751
|
-
value: (_h = (_g = searchSimpleReq.limit) !== null && _g !== void 0 ? _g : searchSimpleReq.topk) !== null && _h !== void 0 ? _h : __1.DEFAULT_TOPK,
|
|
752
|
-
},
|
|
753
|
-
],
|
|
754
|
-
}) : Object.assign(Object.assign({}, requests[0]), createFunctionScore(hasRerankFunction, searchHybridReq)) }, (round_decimal !== -1 ? { round_decimal } : {})), { nq: requests[0].nq });
|
|
755
|
-
};
|
|
756
|
-
exports.buildSearchRequest = buildSearchRequest;
|
|
757
|
-
/**
|
|
758
|
-
* Formats the search results returned by Milvus into row data for easier use.
|
|
759
|
-
*
|
|
760
|
-
* @param {SearchRes} searchRes - The search results returned by Milvus.
|
|
761
|
-
* @param {Object} options - The options for formatting the search results.
|
|
762
|
-
* @param {number} options.round_decimal - The number of decimal places to which to round the scores.
|
|
763
|
-
*
|
|
764
|
-
* @returns {any[]} The formatted search results.
|
|
765
|
-
*
|
|
766
|
-
*/
|
|
767
|
-
const formatSearchResult = (searchRes, options) => {
|
|
768
|
-
var _a;
|
|
769
|
-
const { round_decimal } = options;
|
|
770
|
-
// build final results array
|
|
771
|
-
const results = [];
|
|
772
|
-
const { topks, scores, fields_data, ids } = searchRes.results;
|
|
773
|
-
// build fields data map
|
|
774
|
-
const fieldsDataMap = (0, exports.buildFieldDataMap)(fields_data, options.transformers);
|
|
775
|
-
// build output name array
|
|
776
|
-
const output_fields = [
|
|
777
|
-
...(!!((_a = searchRes.results.output_fields) === null || _a === void 0 ? void 0 : _a.length)
|
|
778
|
-
? searchRes.results.output_fields
|
|
779
|
-
: fields_data.map(f => f.field_name)),
|
|
780
|
-
];
|
|
781
|
-
// fieldsDataMap.set('score', scores); TODO: fieldDataMap to support formatter
|
|
782
|
-
/**
|
|
783
|
-
* This code block formats the search results returned by Milvus into row data for easier use.
|
|
784
|
-
* 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.
|
|
785
|
-
* The `topk` variable is the key we use to splice data for every search result.
|
|
786
|
-
* 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.
|
|
787
|
-
*/
|
|
788
|
-
let offset = 0;
|
|
789
|
-
topks.forEach((v, queryIndex) => {
|
|
790
|
-
const topk = Number(v);
|
|
791
|
-
const queryResults = [];
|
|
792
|
-
if (topk > 0) {
|
|
793
|
-
for (let hitIndex = 0; hitIndex < topk; hitIndex++) {
|
|
794
|
-
const absoluteIndex = offset + hitIndex; // Correct index for flat arrays
|
|
795
|
-
const score = scores[absoluteIndex]; // Access score without modifying array
|
|
796
|
-
const fixedScore = typeof round_decimal === 'undefined' || round_decimal === -1
|
|
797
|
-
? score
|
|
798
|
-
: (0, exports.formatNumberPrecision)(score, round_decimal);
|
|
799
|
-
const result = { score: fixedScore };
|
|
800
|
-
// Get ID - Assuming ID field name is known or included in output_fields
|
|
801
|
-
// Example: const idFieldName = collectionInfo.schema.primary_field_name;
|
|
802
|
-
// if (fieldsDataMap.has(idFieldName)) {
|
|
803
|
-
// result.id = fieldsDataMap.get(idFieldName)![absoluteIndex];
|
|
804
|
-
// }
|
|
805
|
-
output_fields.forEach(field_name => {
|
|
806
|
-
const isFixedSchema = fieldsDataMap.has(field_name);
|
|
807
|
-
const dataArray = fieldsDataMap.get(isFixedSchema ? field_name : __1.DEFAULT_DYNAMIC_FIELD);
|
|
808
|
-
// Safer read-only access for dynamic fields
|
|
809
|
-
const value = isFixedSchema
|
|
810
|
-
? dataArray[absoluteIndex]
|
|
811
|
-
: dataArray[absoluteIndex]
|
|
812
|
-
? dataArray[absoluteIndex][field_name]
|
|
813
|
-
: undefined;
|
|
814
|
-
result[field_name] = value;
|
|
815
|
-
});
|
|
816
|
-
queryResults.push(result);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
results[queryIndex] = queryResults;
|
|
820
|
-
offset += topk; // Update offset for the next query's results
|
|
821
|
-
});
|
|
822
|
-
return results;
|
|
823
|
-
};
|
|
824
|
-
exports.formatSearchResult = formatSearchResult;
|
|
825
|
-
/**
|
|
826
|
-
* Formats the search vector to match a specific data type.
|
|
827
|
-
* @param {SearchDataType[]} searchVector - The search vector or array of vectors to be formatted.
|
|
828
|
-
* @param {DataType} dataType - The specified data type.
|
|
829
|
-
* @returns {VectorTypes[]} The formatted search vector or array of vectors.
|
|
830
|
-
*/
|
|
831
|
-
const formatSearchData = (searchData, field) => {
|
|
832
|
-
const { dataType, is_function_output } = field;
|
|
833
|
-
if (is_function_output) {
|
|
834
|
-
return (Array.isArray(searchData) ? searchData : [searchData]);
|
|
835
|
-
}
|
|
836
|
-
switch (dataType) {
|
|
837
|
-
case __1.DataType.FloatVector:
|
|
838
|
-
case __1.DataType.BinaryVector:
|
|
839
|
-
case __1.DataType.Float16Vector:
|
|
840
|
-
case __1.DataType.BFloat16Vector:
|
|
841
|
-
case __1.DataType.Int8Vector:
|
|
842
|
-
if (!Array.isArray(searchData)) {
|
|
843
|
-
return [searchData];
|
|
844
|
-
}
|
|
845
|
-
case __1.DataType.SparseFloatVector:
|
|
846
|
-
const type = (0, __1.getSparseFloatVectorType)(searchData);
|
|
847
|
-
if (type !== 'unknown') {
|
|
848
|
-
return [searchData];
|
|
849
|
-
}
|
|
850
|
-
default:
|
|
851
|
-
return searchData;
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
exports.formatSearchData = formatSearchData;
|
|
855
|
-
const formatExprValues = (exprValues) => {
|
|
856
|
-
const result = {};
|
|
857
|
-
for (const [key, value] of Object.entries(exprValues)) {
|
|
858
|
-
if (Array.isArray(value)) {
|
|
859
|
-
// Handle arrays
|
|
860
|
-
result[key] = { array_val: convertArray(value) };
|
|
298
|
+
});
|
|
861
299
|
}
|
|
862
300
|
else {
|
|
863
|
-
|
|
864
|
-
if (typeof value === 'boolean') {
|
|
865
|
-
result[key] = { bool_val: value };
|
|
866
|
-
}
|
|
867
|
-
else if (typeof value === 'number') {
|
|
868
|
-
result[key] = Number.isInteger(value)
|
|
869
|
-
? { int64_val: value }
|
|
870
|
-
: { float_val: value };
|
|
871
|
-
}
|
|
872
|
-
else if (typeof value === 'string') {
|
|
873
|
-
result[key] = { string_val: value };
|
|
874
|
-
}
|
|
301
|
+
scalar_fields[f.name] = f;
|
|
875
302
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
return {
|
|
885
|
-
bool_data: {
|
|
886
|
-
data: arr,
|
|
887
|
-
},
|
|
888
|
-
};
|
|
889
|
-
case 'number':
|
|
890
|
-
if (Number.isInteger(first)) {
|
|
891
|
-
return {
|
|
892
|
-
long_data: {
|
|
893
|
-
data: arr,
|
|
894
|
-
},
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
else {
|
|
898
|
-
return {
|
|
899
|
-
double_data: {
|
|
900
|
-
data: arr,
|
|
901
|
-
},
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
|
-
case 'string':
|
|
905
|
-
return {
|
|
906
|
-
string_data: {
|
|
907
|
-
data: arr,
|
|
908
|
-
},
|
|
909
|
-
};
|
|
910
|
-
case 'object':
|
|
911
|
-
if (Array.isArray(first)) {
|
|
912
|
-
return {
|
|
913
|
-
array_data: {
|
|
914
|
-
data: arr.map(convertArray),
|
|
915
|
-
},
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
919
|
-
return {
|
|
920
|
-
json_data: {
|
|
921
|
-
data: arr,
|
|
922
|
-
},
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
default:
|
|
926
|
-
return {
|
|
927
|
-
string_data: {
|
|
928
|
-
data: arr,
|
|
929
|
-
},
|
|
930
|
-
};
|
|
931
|
-
}
|
|
303
|
+
if (f.isFunctionOutput) {
|
|
304
|
+
function_fields[f.name] = f;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
newData.anns_fields = anns_fields;
|
|
308
|
+
newData.scalar_fields = scalar_fields;
|
|
309
|
+
newData.function_fields = function_fields;
|
|
310
|
+
return newData;
|
|
932
311
|
};
|
|
312
|
+
exports.formatDescribedCol = formatDescribedCol;
|
|
933
313
|
//# sourceMappingURL=Format.js.map
|