@ejfdelgado/ejflab-back 1.20.3 → 1.21.0

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 (2) hide show
  1. package/package.json +2 -2
  2. package/srv/MilvusSrv.mjs +32 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.20.3",
3
+ "version": "1.21.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -18,7 +18,7 @@
18
18
  "license": "ISC",
19
19
  "private": false,
20
20
  "dependencies": {
21
- "@ejfdelgado/ejflab-common": "1.12.3",
21
+ "@ejfdelgado/ejflab-common": "1.13.0",
22
22
  "@google-cloud/compute": "^4.7.0",
23
23
  "@google-cloud/firestore": "^7.9.0",
24
24
  "@google-cloud/storage": "^7.11.3",
package/srv/MilvusSrv.mjs CHANGED
@@ -4,6 +4,7 @@ import { encode, decode } from "@msgpack/msgpack";
4
4
  import { General } from "./common/General.mjs";
5
5
  import { CommandMilvus } from "@ejfdelgado/ejflab-common/src/flowchart/steps/CommandMilvus.js";
6
6
  import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
7
+ import { MyError } from "./MyError.mjs";
7
8
 
8
9
  export class MilvusSrv {
9
10
  // MilvusSrv.checkErrors(res);
@@ -282,35 +283,51 @@ export class MilvusSrv {
282
283
  const buffer = req.body;
283
284
  const decoded = decode(buffer);
284
285
  // Connect to database
285
- const {
286
+ let {
286
287
  db_name,
287
288
  collection_name,
288
289
  embeed,
289
- paging
290
+ paging,
291
+ search_params,
292
+ output_fields,
293
+ consistency_level,
290
294
  } = decoded;
291
295
  console.log(`Using database ${db_name}`);
292
296
  await MilvusSrv.useDatabase(client, db_name, false);
293
- const search_params = {
294
- "metric_type": "IP",
295
- "topk": paging['limit'],
296
- "params": JSON.stringify({ nprobe: 1024 }),
297
- };
298
- const results = await client.search({
297
+ if (!search_params) {
298
+ search_params = {
299
+ "metric_type": "IP",
300
+ "topk": paging['limit'],// here is redundant!
301
+ "params": JSON.stringify({ nprobe: 1024 }),
302
+ };
303
+ }
304
+ if (!output_fields) {
305
+ output_fields = ['id', 'document_id', 'face_path', 'millis', 'x1', 'y1', 'x2', 'y2', 'ref_id'];
306
+ }
307
+ if (!consistency_level) {
308
+ consistency_level = "Strong";
309
+ }
310
+ const searchPayload = {
299
311
  collection_name: collection_name,
300
- data: [embeed],
312
+ data: [embeed],//??
301
313
  limit: paging['limit'],
302
314
  offset: paging['offset'],
303
- consistency_level: "Strong",
315
+ consistency_level: consistency_level,
304
316
  search_params: search_params,
305
- output_fields: ['id', 'document_id', 'face_path', 'millis', 'x1', 'y1', 'x2', 'y2', 'ref_id']
306
- });
307
- response.results = results.results.map((entity) => {
317
+ output_fields: output_fields
318
+ };
319
+ const results = await client.search(searchPayload);
320
+ if (results.status.code != 0) {
321
+ throw new MyError(results.status.error_code + ". " + results.status.reason)
322
+ }
323
+ //console.log(JSON.stringify(results, null, 4));
324
+ response.results = [results.results.map((entity) => {
308
325
  return {
309
326
  id: entity.id,
310
- distance: 0,
327
+ distance: entity.score,//is it the same?
311
328
  entity
312
329
  };
313
- });
330
+ })];
314
331
  } catch (err) {
315
332
  console.log(err);
316
333
  code = 500;