@ejfdelgado/ejflab-back 1.20.1 → 1.20.4

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 +65 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.20.1",
3
+ "version": "1.20.4",
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.1",
21
+ "@ejfdelgado/ejflab-common": "1.12.3",
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
@@ -1,7 +1,10 @@
1
+ import fs from "fs";
1
2
  import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
2
3
  import { encode, decode } from "@msgpack/msgpack";
3
4
  import { General } from "./common/General.mjs";
4
5
  import { CommandMilvus } from "@ejfdelgado/ejflab-common/src/flowchart/steps/CommandMilvus.js";
6
+ import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
7
+ import { MyError } from "./MyError.mjs";
5
8
 
6
9
  export class MilvusSrv {
7
10
  // MilvusSrv.checkErrors(res);
@@ -64,7 +67,7 @@ export class MilvusSrv {
64
67
  for (let j = 0; j < data.length; j++) {
65
68
  const collection = data[j];
66
69
  console.log(` - Collection: ${collection.name}`);
67
- myDb.collections.push(collection.name);
70
+ myDb.collections.push({ name: collection.name });
68
71
  }
69
72
  }
70
73
  return response;
@@ -80,6 +83,21 @@ export class MilvusSrv {
80
83
  }
81
84
  }
82
85
  }
86
+
87
+ static async describeCollectionOfDatabase(client, db_name, collection_name) {
88
+ const resUseDatabase1 = await client.useDatabase({ db_name: db_name });
89
+ MilvusSrv.checkErrors(resUseDatabase1);
90
+ const description = await client.describeCollection({ collection_name: collection_name });
91
+ return description;
92
+ }
93
+
94
+ static async dropCollectionOfDatabase(client, db_name, collection_name) {
95
+ const resUseDatabase1 = await client.useDatabase({ db_name: db_name });
96
+ MilvusSrv.checkErrors(resUseDatabase1);
97
+ await MilvusSrv.dropCollection(client, collection_name);
98
+ return true;
99
+ }
100
+
83
101
  static async dropCollection(client, collection_name) {
84
102
  console.log(`Drop collection ${collection_name}...`);
85
103
  const resHasCollection = await client.hasCollection({ collection_name });
@@ -135,6 +153,7 @@ export class MilvusSrv {
135
153
  // Translate data types
136
154
  const myCopy = JSON.parse(JSON.stringify(myJson));
137
155
  const collection_name = myCopy.collection_name;
156
+ console.log(`createCollectionWithSchema... ${collection_name}`);
138
157
  const exists = await this.existsCollection(client, collection_name);
139
158
  if (exists) {
140
159
  if (recreate) {
@@ -159,6 +178,7 @@ export class MilvusSrv {
159
178
  database.create
160
179
  database.recreate
161
180
  collection.create
181
+ collection.destroy
162
182
  introspect
163
183
  database.destroy
164
184
  database.destroy_temp
@@ -172,7 +192,10 @@ export class MilvusSrv {
172
192
  return MilvusSrv;
173
193
  }
174
194
  };
175
- }
195
+ },
196
+ data: {
197
+ configuration: {}
198
+ },
176
199
  };
177
200
  const id = '';
178
201
  const commandName = 'milvus';
@@ -180,7 +203,17 @@ export class MilvusSrv {
180
203
  const command = new CommandMilvus(context, id, commandName, argsTxt);
181
204
  const action = General.readParam(req, "action", null);
182
205
  const db = General.readParam(req, "db", null);
183
- const collection = General.readParam(req, "collection", null);
206
+ let collection = General.readParam(req, "collection", null);
207
+ if (action == "collection.create") {
208
+ // Read configuration file...
209
+ const json = General.readParam(req, "json", null);
210
+ const jsonTxt = fs.readFileSync(json, { encoding: "utf8" });
211
+ const jsonParsed = JSON.parse(jsonTxt);
212
+ const path = General.readParam(req, "path", null);
213
+ const configuration = SimpleObj.getValue(jsonParsed, path, null);
214
+ context.data.configuration = configuration;
215
+ collection = "configuration";
216
+ }
184
217
  command.args = [action, db, collection];
185
218
  const answer = await command.computation();
186
219
  const response = {
@@ -250,35 +283,50 @@ export class MilvusSrv {
250
283
  const buffer = req.body;
251
284
  const decoded = decode(buffer);
252
285
  // Connect to database
253
- const {
286
+ let {
254
287
  db_name,
255
288
  collection_name,
256
289
  embeed,
257
- paging
290
+ paging,
291
+ search_params,
292
+ output_fields,
293
+ consistency_level,
258
294
  } = decoded;
259
295
  console.log(`Using database ${db_name}`);
260
296
  await MilvusSrv.useDatabase(client, db_name, false);
261
- const search_params = {
262
- "metric_type": "IP",
263
- "topk": paging['limit'],
264
- "params": JSON.stringify({ nprobe: 1024 }),
265
- };
266
- 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 = {
267
311
  collection_name: collection_name,
268
- data: [embeed],
312
+ data: [embeed],//??
269
313
  limit: paging['limit'],
270
314
  offset: paging['offset'],
271
- consistency_level: "Strong",
315
+ consistency_level: consistency_level,
272
316
  search_params: search_params,
273
- output_fields: ['id', 'document_id', 'face_path', 'millis', 'x1', 'y1', 'x2', 'y2', 'ref_id']
274
- });
275
- 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
+ response.results = [results.results.map((entity) => {
276
324
  return {
277
325
  id: entity.id,
278
326
  distance: 0,
279
327
  entity
280
328
  };
281
- });
329
+ })];
282
330
  } catch (err) {
283
331
  console.log(err);
284
332
  code = 500;