txtai 6.0.0 → 6.2.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.
@@ -50,29 +50,46 @@ var Embeddings = /*#__PURE__*/function (_API) {
50
50
  *
51
51
  * @param query query text
52
52
  * @param limit maximum results (defaults to 10)
53
+ * @param weights hybrid score weights, if applicable
54
+ * @param index index name, if applicable
53
55
  * @return list of {id: value, score: value}
54
56
  */
55
57
  function () {
56
58
  var _search = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(query) {
57
59
  var limit,
60
+ weights,
61
+ index,
62
+ params,
58
63
  _args = arguments;
59
64
  return _regenerator["default"].wrap(function _callee$(_context) {
60
65
  while (1) {
61
66
  switch (_context.prev = _context.next) {
62
67
  case 0:
63
68
  limit = _args.length > 1 && _args[1] !== undefined ? _args[1] : 10;
64
- _context.next = 3;
65
- return this.get("search", {
69
+ weights = _args.length > 2 && _args[2] !== undefined ? _args[2] : null;
70
+ index = _args.length > 3 && _args[3] !== undefined ? _args[3] : null;
71
+ params = {
66
72
  query: query,
67
73
  limit: limit
68
- })["catch"](function (e) {
74
+ };
75
+
76
+ if (weights != null) {
77
+ params["weights"] = weights;
78
+ }
79
+
80
+ if (index != null) {
81
+ params["index"] = index;
82
+ }
83
+
84
+ _context.next = 8;
85
+ return this.get("search", params)["catch"](function (e) {
69
86
  throw e;
70
87
  });
71
88
 
72
- case 3:
89
+ case 8:
73
90
  return _context.abrupt("return", _context.sent);
74
91
 
75
- case 4:
92
+ case 9:
76
93
  case "end":
77
94
  return _context.stop();
78
95
  }
@@ -93,6 +110,8 @@ var Embeddings = /*#__PURE__*/function (_API) {
93
110
  *
94
111
  * @param queries queries text
95
112
  * @param limit maximum results (defaults to 10)
113
+ * @param weights hybrid score weights, if applicable
114
+ * @param index index name, if applicable
96
115
  * @return list of {id: value, score: value} per query
97
116
  */
98
117
 
@@ -101,24 +120,39 @@ var Embeddings = /*#__PURE__*/function (_API) {
101
120
  value: function () {
102
121
  var _batchsearch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(queries) {
103
122
  var limit,
123
+ weights,
124
+ index,
125
+ params,
104
126
  _args2 = arguments;
105
127
  return _regenerator["default"].wrap(function _callee2$(_context2) {
106
128
  while (1) {
107
129
  switch (_context2.prev = _context2.next) {
108
130
  case 0:
109
131
  limit = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 10;
110
- _context2.next = 3;
111
- return this.post("batchsearch", {
132
+ weights = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : null;
133
+ index = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : null;
134
+ params = {
112
135
  queries: queries,
113
136
  limit: limit
114
- })["catch"](function (e) {
137
+ };
138
+
139
+ if (weights != null) {
140
+ params["weights"] = weights;
141
+ }
142
+
143
+ if (index != null) {
144
+ params["index"] = index;
145
+ }
146
+
147
+ _context2.next = 8;
148
+ return this.post("batchsearch", params)["catch"](function (e) {
115
149
  throw e;
116
150
  });
117
151
 
118
- case 3:
152
+ case 8:
119
153
  return _context2.abrupt("return", _context2.sent);
120
154
 
121
- case 4:
155
+ case 9:
122
156
  case "end":
123
157
  return _context2.stop();
124
158
  }
@@ -264,6 +298,52 @@ var Embeddings = /*#__PURE__*/function (_API) {
264
298
 
265
299
  return _delete;
266
300
  }()
301
+ /**
302
+ * Recreates this embeddings index using config. This method only works if document content storage is enabled.
303
+ *
304
+ * @param config new config
305
+ * @param func optional function to prepare content for indexing
306
+ */
307
+
308
+ }, {
309
+ key: "reindex",
310
+ value: function () {
311
+ var _reindex = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(config) {
312
+ var func,
313
+ params,
314
+ _args7 = arguments;
315
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
316
+ while (1) {
317
+ switch (_context7.prev = _context7.next) {
318
+ case 0:
319
+ func = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : null;
320
+ params = {
321
+ config: config
322
+ };
323
+
324
+ if (func != null) {
325
+ params["function"] = func;
326
+ }
327
+
328
+ _context7.next = 5;
329
+ return this.post("reindex", params)["catch"](function (e) {
330
+ throw e;
331
+ });
332
+
333
+ case 5:
334
+ case "end":
335
+ return _context7.stop();
336
+ }
337
+ }
338
+ }, _callee7, this);
339
+ }));
340
+
341
+ function reindex(_x5) {
342
+ return _reindex.apply(this, arguments);
343
+ }
344
+
345
+ return reindex;
346
+ }()
267
347
  /**
268
348
  * Total number of elements in this embeddings index.
269
349
  *
@@ -273,25 +353,25 @@ var Embeddings = /*#__PURE__*/function (_API) {
273
353
  }, {
274
354
  key: "count",
275
355
  value: function () {
276
- var _count = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
277
- return _regenerator["default"].wrap(function _callee7$(_context7) {
356
+ var _count = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
357
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
278
358
  while (1) {
279
- switch (_context7.prev = _context7.next) {
359
+ switch (_context8.prev = _context8.next) {
280
360
  case 0:
281
- _context7.next = 2;
361
+ _context8.next = 2;
282
362
  return this.get("count", null)["catch"](function (e) {
283
363
  throw e;
284
364
  });
285
365
 
286
366
  case 2:
287
- return _context7.abrupt("return", _context7.sent);
367
+ return _context8.abrupt("return", _context8.sent);
288
368
 
289
369
  case 3:
290
370
  case "end":
291
- return _context7.stop();
371
+ return _context8.stop();
292
372
  }
293
373
  }
294
- }, _callee7, this);
374
+ }, _callee8, this);
295
375
  }));
296
376
 
297
377
  function count() {
@@ -313,12 +393,12 @@ var Embeddings = /*#__PURE__*/function (_API) {
313
393
  }, {
314
394
  key: "similarity",
315
395
  value: function () {
316
- var _similarity = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(query, texts) {
317
- return _regenerator["default"].wrap(function _callee8$(_context8) {
396
+ var _similarity = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(query, texts) {
397
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
318
398
  while (1) {
319
- switch (_context8.prev = _context8.next) {
399
+ switch (_context9.prev = _context9.next) {
320
400
  case 0:
321
- _context8.next = 2;
401
+ _context9.next = 2;
322
402
  return this.post("similarity", {
323
403
  query: query,
324
404
  texts: texts
@@ -327,17 +407,17 @@ var Embeddings = /*#__PURE__*/function (_API) {
327
407
  });
328
408
 
329
409
  case 2:
330
- return _context8.abrupt("return", _context8.sent);
410
+ return _context9.abrupt("return", _context9.sent);
331
411
 
332
412
  case 3:
333
413
  case "end":
334
- return _context8.stop();
414
+ return _context9.stop();
335
415
  }
336
416
  }
337
- }, _callee8, this);
417
+ }, _callee9, this);
338
418
  }));
339
419
 
340
- function similarity(_x5, _x6) {
420
+ function similarity(_x6, _x7) {
341
421
  return _similarity.apply(this, arguments);
342
422
  }
343
423
 
@@ -356,12 +436,12 @@ var Embeddings = /*#__PURE__*/function (_API) {
356
436
  }, {
357
437
  key: "batchsimilarity",
358
438
  value: function () {
359
- var _batchsimilarity = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(queries, texts) {
360
- return _regenerator["default"].wrap(function _callee9$(_context9) {
439
+ var _batchsimilarity = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(queries, texts) {
440
+ return _regenerator["default"].wrap(function _callee10$(_context10) {
361
441
  while (1) {
362
- switch (_context9.prev = _context9.next) {
442
+ switch (_context10.prev = _context10.next) {
363
443
  case 0:
364
- _context9.next = 2;
444
+ _context10.next = 2;
365
445
  return this.post("batchsimilarity", {
366
446
  queries: queries,
367
447
  texts: texts
@@ -370,17 +450,17 @@ var Embeddings = /*#__PURE__*/function (_API) {
370
450
  });
371
451
 
372
452
  case 2:
373
- return _context9.abrupt("return", _context9.sent);
453
+ return _context10.abrupt("return", _context10.sent);
374
454
 
375
455
  case 3:
376
456
  case "end":
377
- return _context9.stop();
457
+ return _context10.stop();
378
458
  }
379
459
  }
380
- }, _callee9, this);
460
+ }, _callee10, this);
381
461
  }));
382
462
 
383
- function batchsimilarity(_x7, _x8) {
463
+ function batchsimilarity(_x8, _x9) {
384
464
  return _batchsimilarity.apply(this, arguments);
385
465
  }
386
466
 
@@ -396,12 +476,12 @@ var Embeddings = /*#__PURE__*/function (_API) {
396
476
  }, {
397
477
  key: "transform",
398
478
  value: function () {
399
- var _transform = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(text) {
400
- return _regenerator["default"].wrap(function _callee10$(_context10) {
479
+ var _transform = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(text) {
480
+ return _regenerator["default"].wrap(function _callee11$(_context11) {
401
481
  while (1) {
402
- switch (_context10.prev = _context10.next) {
482
+ switch (_context11.prev = _context11.next) {
403
483
  case 0:
404
- _context10.next = 2;
484
+ _context11.next = 2;
405
485
  return this.get("transform", {
406
486
  text: text
407
487
  })["catch"](function (e) {
@@ -409,17 +489,17 @@ var Embeddings = /*#__PURE__*/function (_API) {
409
489
  });
410
490
 
411
491
  case 2:
412
- return _context10.abrupt("return", _context10.sent);
492
+ return _context11.abrupt("return", _context11.sent);
413
493
 
414
494
  case 3:
415
495
  case "end":
416
- return _context10.stop();
496
+ return _context11.stop();
417
497
  }
418
498
  }
419
- }, _callee10, this);
499
+ }, _callee11, this);
420
500
  }));
421
501
 
422
- function transform(_x9) {
502
+ function transform(_x10) {
423
503
  return _transform.apply(this, arguments);
424
504
  }
425
505
 
@@ -435,28 +515,28 @@ var Embeddings = /*#__PURE__*/function (_API) {
435
515
  }, {
436
516
  key: "batchtransform",
437
517
  value: function () {
438
- var _batchtransform = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(texts) {
439
- return _regenerator["default"].wrap(function _callee11$(_context11) {
518
+ var _batchtransform = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(texts) {
519
+ return _regenerator["default"].wrap(function _callee12$(_context12) {
440
520
  while (1) {
441
- switch (_context11.prev = _context11.next) {
521
+ switch (_context12.prev = _context12.next) {
442
522
  case 0:
443
- _context11.next = 2;
523
+ _context12.next = 2;
444
524
  return this.post("batchtransform", texts)["catch"](function (e) {
445
525
  throw e;
446
526
  });
447
527
 
448
528
  case 2:
449
- return _context11.abrupt("return", _context11.sent);
529
+ return _context12.abrupt("return", _context12.sent);
450
530
 
451
531
  case 3:
452
532
  case "end":
453
- return _context11.stop();
533
+ return _context12.stop();
454
534
  }
455
535
  }
456
- }, _callee11, this);
536
+ }, _callee12, this);
457
537
  }));
458
538
 
459
- function batchtransform(_x10) {
539
+ function batchtransform(_x11) {
460
540
  return _batchtransform.apply(this, arguments);
461
541
  }
462
542
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/embeddings.js"],"names":["Embeddings","query","limit","get","e","queries","post","documents","ids","texts","text","API"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAEA;AACA;AACA;IACMA,U;;;;;;;;;;;;;AACF;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;kGACI,iBAAaC,KAAb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAoBC,gBAAAA,KAApB,2DAA4B,EAA5B;AAAA;AAAA,uBACiB,KAAKC,GAAL,CAAS,QAAT,EAAmB;AAACF,kBAAAA,KAAK,EAAEA,KAAR;AAAeC,kBAAAA,KAAK,EAAEA;AAAtB,iBAAnB,WAAuD,UAAAE,CAAC,EAAI;AACrE,wBAAMA,CAAN;AACH,iBAFY,CADjB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;AAMA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;uGACI,kBAAkBC,OAAlB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA2B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B,WAA0C,UAAAN,CAAC,EAAI;AACxD,wBAAMA,CAAN;AACH,iBAFY,CADjB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;AAMA;AACJ;AACA;AACA;AACA;AACA;;;;;0GACI,mBAAqBK,KAArB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACiB,KAAKH,IAAL,CAAU,gBAAV,EAA4BG,KAA5B,WAAyC,UAAAL,CAAC,EAAI;AACvD,wBAAMA,CAAN;AACH,iBAFY,CADjB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EAnIqBO,e;;eA0IVX,U","sourcesContent":["import API from \"./api\";\n\n/**\n * txtai embeddings instance. \n */\nclass Embeddings extends API {\n /**\n * Finds documents in the embeddings model most similar to the input query. Returns\n * a list of {id: value, score: value} sorted by highest score, where id is the\n * document id in the embeddings model.\n * \n * @param query query text\n * @param limit maximum results (defaults to 10)\n * @return list of {id: value, score: value}\n */\n async search(query, limit = 10) {\n return await this.get(\"search\", {query: query, limit: limit}).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Finds documents in the embeddings model most similar to the input queries. Returns\n * a list of {id: value, score: value} sorted by highest score per query, where id is\n * the document id in the embeddings model.\n *\n * @param queries queries text\n * @param limit maximum results (defaults to 10)\n * @return list of {id: value, score: value} per query\n */\n async batchsearch(queries, limit = 10) {\n return await this.post(\"batchsearch\", {queries: queries, limit: limit}).catch (e => {\n throw(e);\n });\n }\n\n /**\n * Adds a batch of documents for indexing.\n * \n * @param documents list of {id: value, text: value}\n */\n async add(documents) {\n await this.post(\"add\", documents).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Builds an embeddings index for previously batched documents.\n */\n async index() {\n await this.get(\"index\", null).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Runs an embeddings upsert operation for previously batched documents.\n */\n async upsert() {\n await this.get(\"upsert\", null).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Deletes from an embeddings index. Returns list of ids deleted.\n *\n * @param ids list of ids to delete\n * @return ids deleted\n */\n async delete(ids) {\n return await this.post(\"delete\", ids).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Total number of elements in this embeddings index.\n *\n * @return number of elements in embeddings index\n */\n async count() {\n return await this.get(\"count\", null).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Computes the similarity between query and list of text. Returns a list of\n * {id: value, score: value} sorted by highest score, where id is the index\n * in texts.\n *\n * @param query query text\n * @param texts list of text\n * @return list of {id: value, score: value}\n */\n async similarity(query, texts) {\n return await this.post(\"similarity\", {query: query, texts: texts}).catch (e => {\n throw(e);\n });\n }\n\n /**\n * Computes the similarity between list of queries and list of text. Returns a list\n * of {id: value, score: value} sorted by highest score per query, where id is the\n * index in texts.\n * \n * @param queries queries text\n * @param texts list of text\n * @return list of {id: value, score: value} per query\n */\n async batchsimilarity(queries, texts) {\n return await this.post(\"batchsimilarity\", {queries: queries, texts: texts}).catch (e => {\n throw(e);\n });\n }\n\n /**\n * Transforms text into an embeddings array.\n *\n * @param text input text\n * @return embeddings array\n */\n async transform(text) {\n return await this.get(\"transform\", {text: text}).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Transforms list of text into embeddings arrays.\n *\n * @param texts list of text\n * @return embeddings array\n */\n async batchtransform(texts) {\n return await this.post(\"batchtransform\", texts).catch(e => {\n throw(e);\n });\n }\n}\n\nexport default Embeddings;\n"],"file":"embeddings.js"}
1
+ {"version":3,"sources":["../src/embeddings.js"],"names":["Embeddings","query","limit","weights","index","params","get","e","queries","post","documents","ids","config","func","texts","text","API"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAEA;AACA;AACA;IACMA,U;;;;;;;;;;;;;AACF;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;kGACI,iBAAaC,KAAb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAoBC,gBA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WAAsE,UAAAP,CAAC,EAAI;AACpF,wBAAMA,CAAN;AACH,iBAFY,CADjB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;AAMA;AACJ;AACA;AACA;AACA;AACA;;;;;qGACI,mBAAgBQ,IAAhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACiB,KAAKT,GAAL,CAAS,WAAT,EAAsB;AAACS,kBAAAA,IAAI,EAAEA;AAAP,iBAAtB,WAA0C,UAAAR,CAAC,EAAI;AACxD,wBAAMA,CAAN;AACH,iBAFY,CADjB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;AAMA;AACJ;AACA;AACA;AACA;AACA;;;;;0GACI,mBAAqBO,KAArB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACiB,KAAKL,IAAL,CAAU,gBAAV,EAA4BK,KAA5B,WAAyC,UAAAP,CAAC,EAAI;AACvD,wBAAMA,CAAN;AACH,iBAFY,CADjB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EAnLqBS,e;;eA0LVhB,U","sourcesContent":["import API from \"./api\";\n\n/**\n * txtai embeddings instance. \n */\nclass Embeddings extends API {\n /**\n * Finds documents in the embeddings model most similar to the input query. Returns\n * a list of {id: value, score: value} sorted by highest score, where id is the\n * document id in the embeddings model.\n * \n * @param query query text\n * @param limit maximum results (defaults to 10)\n * @param weights hybrid score weights, if applicable\n * @param index index name, if applicable\n * @return list of {id: value, score: value}\n */\n async search(query, limit = 10, weights = null, index = null) {\n let params = {\n query: query,\n limit: limit\n }\n\n if (weights != null) {\n params[\"weights\"] = weights\n }\n if (index != null) {\n params[\"index\"] = index\n }\n\n return await this.get(\"search\", params).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Finds documents in the embeddings model most similar to the input queries. Returns\n * a list of {id: value, score: value} sorted by highest score per query, where id is\n * the document id in the embeddings model.\n *\n * @param queries queries text\n * @param limit maximum results (defaults to 10)\n * @param weights hybrid score weights, if applicable\n * @param index index name, if applicable\n * @return list of {id: value, score: value} per query\n */\n async batchsearch(queries, limit = 10, weights = null, index = null) {\n let params = {\n queries: queries,\n limit: limit\n }\n\n if (weights != null) {\n params[\"weights\"] = weights\n }\n if (index != null) {\n params[\"index\"] = index\n }\n\n return await this.post(\"batchsearch\", params).catch (e => {\n throw(e);\n });\n }\n\n /**\n * Adds a batch of documents for indexing.\n * \n * @param documents list of {id: value, text: value}\n */\n async add(documents) {\n await this.post(\"add\", documents).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Builds an embeddings index for previously batched documents.\n */\n async index() {\n await this.get(\"index\", null).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Runs an embeddings upsert operation for previously batched documents.\n */\n async upsert() {\n await this.get(\"upsert\", null).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Deletes from an embeddings index. Returns list of ids deleted.\n *\n * @param ids list of ids to delete\n * @return ids deleted\n */\n async delete(ids) {\n return await this.post(\"delete\", ids).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Recreates this embeddings index using config. This method only works if document content storage is enabled.\n *\n * @param config new config\n * @param func optional function to prepare content for indexing\n */\n async reindex(config, func = null) {\n let params = {\n config: config,\n }\n\n if (func != null) {\n params[\"function\"] = func\n }\n\n await this.post(\"reindex\", params).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Total number of elements in this embeddings index.\n *\n * @return number of elements in embeddings index\n */\n async count() {\n return await this.get(\"count\", null).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Computes the similarity between query and list of text. Returns a list of\n * {id: value, score: value} sorted by highest score, where id is the index\n * in texts.\n *\n * @param query query text\n * @param texts list of text\n * @return list of {id: value, score: value}\n */\n async similarity(query, texts) {\n return await this.post(\"similarity\", {query: query, texts: texts}).catch (e => {\n throw(e);\n });\n }\n\n /**\n * Computes the similarity between list of queries and list of text. Returns a list\n * of {id: value, score: value} sorted by highest score per query, where id is the\n * index in texts.\n * \n * @param queries queries text\n * @param texts list of text\n * @return list of {id: value, score: value} per query\n */\n async batchsimilarity(queries, texts) {\n return await this.post(\"batchsimilarity\", {queries: queries, texts: texts}).catch (e => {\n throw(e);\n });\n }\n\n /**\n * Transforms text into an embeddings array.\n *\n * @param text input text\n * @return embeddings array\n */\n async transform(text) {\n return await this.get(\"transform\", {text: text}).catch(e => {\n throw(e);\n });\n }\n\n /**\n * Transforms list of text into embeddings arrays.\n *\n * @param texts list of text\n * @return embeddings array\n */\n async batchtransform(texts) {\n return await this.post(\"batchtransform\", texts).catch(e => {\n throw(e);\n });\n }\n}\n\nexport default Embeddings;\n"],"file":"embeddings.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "txtai",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "author": "NeuML",
5
5
  "description": "JavaScript client for txtai",
6
6
  "license": "Apache-2.0",