@relevanceai/sdk 1.0.0 → 1.5.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.
- package/README.md +31 -23
- package/dist-cjs/generated/VectorApi.js +123 -3
- package/dist-cjs/services/discovery/Dataset.js +10 -5
- package/dist-cjs/services/discovery/index.js +100 -60
- package/dist-es/generated/VectorApi.js +183 -3
- package/dist-es/services/discovery/Dataset.js +8 -4
- package/dist-es/services/discovery/index.js +124 -82
- package/dist-types/generated/VectorApi.d.ts +54 -9
- package/dist-types/generated/_VectorApiSchemaTypes.d.ts +732 -37
- package/dist-types/services/discovery/Dataset.d.ts +1 -0
- package/dist-types/services/discovery/index.d.ts +53 -15
- package/package.json +1 -1
- package/dist-cjs/generated/Discovery.js +0 -82
- package/dist-cjs/generated/Vector.js +0 -634
- package/dist-cjs/generated/_DiscoverySchemaTypes.js +0 -6
- package/dist-cjs/generated/_VectorSchemaTypes.js +0 -6
- package/dist-cjs/generated/clients.js +0 -82
- package/dist-es/generated/Discovery.js +0 -179
- package/dist-es/generated/Vector.js +0 -1007
- package/dist-es/generated/_DiscoverySchemaTypes.js +0 -5
- package/dist-es/generated/_VectorSchemaTypes.js +0 -5
- package/dist-es/generated/clients.js +0 -179
- package/dist-types/generated/Discovery.d.ts +0 -32
- package/dist-types/generated/Vector.d.ts +0 -239
- package/dist-types/generated/_DiscoverySchemaTypes.d.ts +0 -911
- package/dist-types/generated/_VectorSchemaTypes.d.ts +0 -5017
- package/dist-types/generated/clients.d.ts +0 -942
package/README.md
CHANGED
|
@@ -11,15 +11,14 @@ npm i @relevanceai/sdk
|
|
|
11
11
|
# Getting started
|
|
12
12
|
Get started in seconds with a demo dataset of popular movies.
|
|
13
13
|
```javascript
|
|
14
|
-
import {DiscoveryClient} from "@relevanceai/sdk";
|
|
14
|
+
import {DiscoveryClient,QueryBuilder} from "@relevanceai/sdk";
|
|
15
15
|
|
|
16
16
|
const discovery = new DiscoveryClient({
|
|
17
17
|
project:'dummy-collections',
|
|
18
18
|
api_key:'UzdYRktIY0JxNmlvb1NpOFNsenU6VGdTU0s4UjhUR0NsaDdnQTVwUkpKZw',
|
|
19
|
-
dataset_id:'1000-movies'
|
|
20
19
|
});
|
|
21
|
-
const
|
|
22
|
-
|
|
20
|
+
const dataset = discovery.dataset('1000-movies');
|
|
21
|
+
const {results} = await dataset.search(QueryBuilder().text('Las Vegas'));
|
|
23
22
|
```
|
|
24
23
|
## Set up your credentials
|
|
25
24
|
### Option 1 - Use environment variables
|
|
@@ -57,18 +56,27 @@ import {QueryBuilder,DiscoveryClient,BulkInsertOutput} from "@relevanceai/sdk";
|
|
|
57
56
|
```javascript
|
|
58
57
|
const discovery = new DiscoveryClient({ });
|
|
59
58
|
const dataset = discovery.dataset('tshirts-prod');
|
|
60
|
-
// Here we create some demo data. Replace this with your real data
|
|
59
|
+
// Here we create some demo data. Replace this with your real data
|
|
60
|
+
const fakeVector = [];
|
|
61
|
+
for (let i = 0; i < 768; i++) fakeVector.push(1);
|
|
61
62
|
const tshirtsData = [];
|
|
62
|
-
for (let i = 0; i <
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
for (let i = 0; i < 10000; i++) {
|
|
64
|
+
tshirtsData.push({_id:`tshirt-${i}1`,color:'red',price:i/1000,'title_text@1-0_vector_':fakeVector});
|
|
65
|
+
tshirtsData.push({_id:`tshirt-${i}2`,color:'blue',price:i/1000});
|
|
66
|
+
tshirtsData.push({_id:`tshirt-${i}3`,color:'orange',price:i/1000});
|
|
66
67
|
}
|
|
67
|
-
const res = await dataset.insertDocuments(tshirtsData,{batchSize:
|
|
68
|
+
const res = await dataset.insertDocuments(tshirtsData,{batchSize:10000});
|
|
68
69
|
```
|
|
69
70
|
### insertDocuments will output:
|
|
70
71
|
```javascript
|
|
71
|
-
{"inserted":
|
|
72
|
+
{"inserted":30000,"failed_documents":[]}
|
|
73
|
+
```
|
|
74
|
+
## Text Search and Vector Search
|
|
75
|
+
```javascript
|
|
76
|
+
const builder = QueryBuilder();
|
|
77
|
+
builder.query('red').text().vector('title_text@1-0_vector_',0.5).minimumRelevance(0.1);
|
|
78
|
+
// .text() searches all fields. alternatively, use .text(field1).text(field2)... to search specific fields
|
|
79
|
+
const searchResults = await dataset.search(builder);
|
|
72
80
|
```
|
|
73
81
|
## Filter and retrieve items
|
|
74
82
|
```javascript
|
|
@@ -89,7 +97,7 @@ const filteredItems = await dataset.search(filters);
|
|
|
89
97
|
}
|
|
90
98
|
...
|
|
91
99
|
],
|
|
92
|
-
resultsSize:
|
|
100
|
+
resultsSize: 10200,
|
|
93
101
|
aggregations: {},
|
|
94
102
|
aggregates: {},
|
|
95
103
|
aggregateStats: {}
|
|
@@ -106,21 +114,21 @@ const aggregatesResult = await dataset.search(aggregates);
|
|
|
106
114
|
{
|
|
107
115
|
aggregates:{
|
|
108
116
|
color: {
|
|
109
|
-
results: { blue:
|
|
117
|
+
results: { blue: 10000, orange: 10000, red: 10000 },
|
|
110
118
|
aggregates: {}
|
|
111
119
|
},
|
|
112
120
|
price: {
|
|
113
121
|
results: {
|
|
114
|
-
'0':
|
|
115
|
-
'10':
|
|
116
|
-
'20':
|
|
117
|
-
'30':
|
|
118
|
-
'40':
|
|
119
|
-
'50':
|
|
120
|
-
'60':
|
|
121
|
-
'70':
|
|
122
|
-
'80':
|
|
123
|
-
'90':
|
|
122
|
+
'0': 0000,
|
|
123
|
+
'10': 3000,
|
|
124
|
+
'20': 3000,
|
|
125
|
+
'30': 3000,
|
|
126
|
+
'40': 3000,
|
|
127
|
+
'50': 3000,
|
|
128
|
+
'60': 3000,
|
|
129
|
+
'70': 3000,
|
|
130
|
+
'80': 3000,
|
|
131
|
+
'90': 3000
|
|
124
132
|
},
|
|
125
133
|
aggregates: {}
|
|
126
134
|
}
|
|
@@ -302,6 +302,30 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
302
302
|
options
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
|
+
async encodebymodelapidatasetsdatasetidvectorizepost(input, options) {
|
|
306
|
+
return this.SendRequest({
|
|
307
|
+
input,
|
|
308
|
+
method: 'post',
|
|
309
|
+
path: '/datasets/{dataset_id}/vectorize',
|
|
310
|
+
options
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
async taskstatusbymodelapidatasetsdatasetidtaskstatusget(input, options) {
|
|
314
|
+
return this.SendRequest({
|
|
315
|
+
input,
|
|
316
|
+
method: 'get',
|
|
317
|
+
path: '/datasets/{dataset_id}/task_status',
|
|
318
|
+
options
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
async listtasksapidatasetsdatasetidtasksget(input, options) {
|
|
322
|
+
return this.SendRequest({
|
|
323
|
+
input,
|
|
324
|
+
method: 'get',
|
|
325
|
+
path: '/datasets/{dataset_id}/tasks',
|
|
326
|
+
options
|
|
327
|
+
});
|
|
328
|
+
}
|
|
305
329
|
async vectorsearchapiservicessearchvectorpost(input, options) {
|
|
306
330
|
return this.SendRequest({
|
|
307
331
|
input,
|
|
@@ -406,6 +430,14 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
406
430
|
options
|
|
407
431
|
});
|
|
408
432
|
}
|
|
433
|
+
async clustercentroidsapiv2servicesclustercentroidslistpost(input, options) {
|
|
434
|
+
return this.SendRequest({
|
|
435
|
+
input,
|
|
436
|
+
method: 'post',
|
|
437
|
+
path: '/services/cluster/centroids/list',
|
|
438
|
+
options
|
|
439
|
+
});
|
|
440
|
+
}
|
|
409
441
|
async clustercentroidsgetapiservicesclustercentroidsgetget(input, options) {
|
|
410
442
|
return this.SendRequest({
|
|
411
443
|
input,
|
|
@@ -414,7 +446,15 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
414
446
|
options
|
|
415
447
|
});
|
|
416
448
|
}
|
|
417
|
-
async
|
|
449
|
+
async clustercentroidsgetapiservicesclustercentroidsgetpost(input, options) {
|
|
450
|
+
return this.SendRequest({
|
|
451
|
+
input,
|
|
452
|
+
method: 'post',
|
|
453
|
+
path: '/services/cluster/centroids/get',
|
|
454
|
+
options
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
async insertclustercentroids2apiservicesclustercentroidsinsertpost(input, options) {
|
|
418
458
|
return this.SendRequest({
|
|
419
459
|
input,
|
|
420
460
|
method: 'post',
|
|
@@ -422,6 +462,38 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
422
462
|
options
|
|
423
463
|
});
|
|
424
464
|
}
|
|
465
|
+
async updatecentroidsapiv2servicesclustercentroidsupdatepost(input, options) {
|
|
466
|
+
return this.SendRequest({
|
|
467
|
+
input,
|
|
468
|
+
method: 'post',
|
|
469
|
+
path: '/services/cluster/centroids/update',
|
|
470
|
+
options
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
async deletecentroidsapiservicesclustercentroidscentroididdeleteget(input, options) {
|
|
474
|
+
return this.SendRequest({
|
|
475
|
+
input,
|
|
476
|
+
method: 'get',
|
|
477
|
+
path: '/services/cluster/centroids/{centroid_id}/delete',
|
|
478
|
+
options
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
async deletecentroidsapiservicesclustercentroidscentroididdeletepost(input, options) {
|
|
482
|
+
return this.SendRequest({
|
|
483
|
+
input,
|
|
484
|
+
method: 'post',
|
|
485
|
+
path: '/services/cluster/centroids/{centroid_id}/delete',
|
|
486
|
+
options
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
async clustercentroidsdeleteapiservicesclustercentroidsdeletepost(input, options) {
|
|
490
|
+
return this.SendRequest({
|
|
491
|
+
input,
|
|
492
|
+
method: 'post',
|
|
493
|
+
path: '/services/cluster/centroids/delete',
|
|
494
|
+
options
|
|
495
|
+
});
|
|
496
|
+
}
|
|
425
497
|
async clustercentroidsgetapiservicesclustercentroidsdocumentspost(input, options) {
|
|
426
498
|
return this.SendRequest({
|
|
427
499
|
input,
|
|
@@ -430,7 +502,39 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
430
502
|
options
|
|
431
503
|
});
|
|
432
504
|
}
|
|
433
|
-
async
|
|
505
|
+
async centroidsmetadatagetapiservicesclustercentroidsmetadataget(input, options) {
|
|
506
|
+
return this.SendRequest({
|
|
507
|
+
input,
|
|
508
|
+
method: 'get',
|
|
509
|
+
path: '/services/cluster/centroids/metadata',
|
|
510
|
+
options
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
async centroidsmetadatapostapiv2servicesclustercentroidsmetadatapost(input, options) {
|
|
514
|
+
return this.SendRequest({
|
|
515
|
+
input,
|
|
516
|
+
method: 'post',
|
|
517
|
+
path: '/services/cluster/centroids/metadata',
|
|
518
|
+
options
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
async centroidslistclosesttocenterv2servicesclustercentroidslistclosesttocenterpost(input, options) {
|
|
522
|
+
return this.SendRequest({
|
|
523
|
+
input,
|
|
524
|
+
method: 'post',
|
|
525
|
+
path: '/services/cluster/centroids/list_closest_to_center',
|
|
526
|
+
options
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
async centroidslistfurthestfromcenterv2servicesclustercentroidslistfurthestfromcenterpost(input, options) {
|
|
530
|
+
return this.SendRequest({
|
|
531
|
+
input,
|
|
532
|
+
method: 'post',
|
|
533
|
+
path: '/services/cluster/centroids/list_furthest_from_center',
|
|
534
|
+
options
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
async clusteraggregateapiv2servicesclusteraggregatepost(input, options) {
|
|
434
538
|
return this.SendRequest({
|
|
435
539
|
input,
|
|
436
540
|
method: 'post',
|
|
@@ -438,7 +542,7 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
438
542
|
options
|
|
439
543
|
});
|
|
440
544
|
}
|
|
441
|
-
async
|
|
545
|
+
async advancedclusterfacetsapiservicesclusterfacetsget(input, options) {
|
|
442
546
|
return this.SendRequest({
|
|
443
547
|
input,
|
|
444
548
|
method: 'get',
|
|
@@ -446,6 +550,22 @@ class VectorApiClient extends BaseClient_1._GenericClient {
|
|
|
446
550
|
options
|
|
447
551
|
});
|
|
448
552
|
}
|
|
553
|
+
async clusterlistservicesclusterlistget(input, options) {
|
|
554
|
+
return this.SendRequest({
|
|
555
|
+
input,
|
|
556
|
+
method: 'get',
|
|
557
|
+
path: '/services/cluster/list',
|
|
558
|
+
options
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
async clusterlistmultiservicesclusterlistpost(input, options) {
|
|
562
|
+
return this.SendRequest({
|
|
563
|
+
input,
|
|
564
|
+
method: 'post',
|
|
565
|
+
path: '/services/cluster/list',
|
|
566
|
+
options
|
|
567
|
+
});
|
|
568
|
+
}
|
|
449
569
|
async tagapiservicestaggertagpost(input, options) {
|
|
450
570
|
return this.SendRequest({
|
|
451
571
|
input,
|
|
@@ -27,8 +27,11 @@ class Dataset {
|
|
|
27
27
|
if (arg instanceof _1._QueryBuilder) {
|
|
28
28
|
payload = { ...payload, ...arg.build() };
|
|
29
29
|
}
|
|
30
|
-
else
|
|
30
|
+
else {
|
|
31
31
|
options = arg;
|
|
32
|
+
if (options.rawPayload)
|
|
33
|
+
payload = { ...payload, ...options.rawPayload };
|
|
34
|
+
}
|
|
32
35
|
}
|
|
33
36
|
const reqCallback = async () => await this.client.apiClient.SimpleSearchPost(payload, { dataset_id: this.name });
|
|
34
37
|
if (options.debounce && this.debounceTimer) {
|
|
@@ -67,7 +70,9 @@ class Dataset {
|
|
|
67
70
|
results.push(res);
|
|
68
71
|
break;
|
|
69
72
|
}
|
|
70
|
-
catch (e) {
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.error(`Bulk operation failed with error, retrying - ${e}`);
|
|
75
|
+
}
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
return results;
|
|
@@ -90,7 +95,7 @@ class Dataset {
|
|
|
90
95
|
return finalResults;
|
|
91
96
|
}
|
|
92
97
|
async updateDocumentsWhere(filters, partialUpdates) {
|
|
93
|
-
return (await this.client.apiClient.UpdateWhere({ filters: filters.
|
|
98
|
+
return (await this.client.apiClient.UpdateWhere({ filters: filters.build().filters, updates: partialUpdates })).body;
|
|
94
99
|
}
|
|
95
100
|
async getDocument(documentId) {
|
|
96
101
|
return (await this.client.apiClient.GetDocument({ document_id: documentId })).body;
|
|
@@ -101,11 +106,11 @@ class Dataset {
|
|
|
101
106
|
async deleteDocuments(documentIds) {
|
|
102
107
|
var _a;
|
|
103
108
|
const filters = (0, _1.QueryBuilder)().match('_id', documentIds);
|
|
104
|
-
return (await this.client.apiClient.DeleteWhere({ filters: (_a = filters.
|
|
109
|
+
return (await this.client.apiClient.DeleteWhere({ filters: (_a = filters.build().filters) !== null && _a !== void 0 ? _a : [] })).body;
|
|
105
110
|
}
|
|
106
111
|
async deleteDocumentsWhere(filters) {
|
|
107
112
|
var _a;
|
|
108
|
-
return (await this.client.apiClient.DeleteWhere({ filters: (_a = filters.
|
|
113
|
+
return (await this.client.apiClient.DeleteWhere({ filters: (_a = filters.build().filters) !== null && _a !== void 0 ? _a : [] })).body;
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
exports.Dataset = Dataset;
|
|
@@ -1,74 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiscoveryClient = exports._QueryBuilder = exports.QueryBuilder = void 0;
|
|
3
|
+
exports.DiscoveryClient = exports._QueryBuilder = exports._FilterBuilder = exports.FilterBuilder = exports.QueryBuilder = void 0;
|
|
4
4
|
const __1 = require("../../");
|
|
5
5
|
const Dataset_1 = require("./Dataset");
|
|
6
6
|
function QueryBuilder() {
|
|
7
7
|
return new _QueryBuilder();
|
|
8
8
|
}
|
|
9
9
|
exports.QueryBuilder = QueryBuilder;
|
|
10
|
-
|
|
10
|
+
function FilterBuilder() {
|
|
11
|
+
return new _FilterBuilder();
|
|
12
|
+
}
|
|
13
|
+
exports.FilterBuilder = FilterBuilder;
|
|
14
|
+
class _FilterBuilder {
|
|
11
15
|
constructor() {
|
|
12
16
|
this.body = { filters: [], fieldsToAggregate: [], fieldsToAggregateStats: [] };
|
|
13
17
|
}
|
|
14
|
-
|
|
15
|
-
return this.body;
|
|
16
|
-
}
|
|
17
|
-
text(query, ...args) {
|
|
18
|
-
this.body.query = query;
|
|
19
|
-
for (const arg of args) {
|
|
20
|
-
if (Array.isArray(arg))
|
|
21
|
-
this.body.fieldsToSearch = arg;
|
|
22
|
-
else
|
|
23
|
-
this.body.queryConfig = arg;
|
|
24
|
-
}
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
vector(field, model, ...args) {
|
|
28
|
-
var _a, _b;
|
|
29
|
-
if (!Array.isArray(this.body.vectorSearchQuery))
|
|
30
|
-
this.body.vectorSearchQuery = [];
|
|
31
|
-
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.body) === null || _a === void 0 ? void 0 : _a.vectorSearchQuery) === null || _b === void 0 ? void 0 : _b.length))
|
|
32
|
-
this.body.vectorSearchQuery = [];
|
|
33
|
-
let payload = { field, model };
|
|
34
|
-
for (const arg of args) {
|
|
35
|
-
if (typeof arg === 'number')
|
|
36
|
-
payload.weight = arg;
|
|
37
|
-
else
|
|
38
|
-
payload = { ...payload, ...arg };
|
|
39
|
-
}
|
|
40
|
-
this.body.vectorSearchQuery.push(payload);
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
sort(field, direction) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.body) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b.length))
|
|
46
|
-
this.body.sort = {};
|
|
47
|
-
this.body.sort[field] = direction;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
textSort(field, direction) {
|
|
51
|
-
var _a, _b;
|
|
52
|
-
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.body) === null || _a === void 0 ? void 0 : _a.textSort) === null || _b === void 0 ? void 0 : _b.length))
|
|
53
|
-
this.body.textSort = {};
|
|
54
|
-
this.body.textSort[field] = direction;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
rawOption(key, value) {
|
|
58
|
-
this.body[key] = value;
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
minimumRelevance(value) {
|
|
62
|
-
this.body.minimumRelevance = value;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
page(value) {
|
|
66
|
-
this.body.page = value;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
pageSize(value) {
|
|
70
|
-
this.body.pageSize = value;
|
|
71
|
-
return this;
|
|
18
|
+
buildFilters() {
|
|
19
|
+
return this.body.filters;
|
|
72
20
|
}
|
|
73
21
|
rawFilter(filter) {
|
|
74
22
|
var _a;
|
|
@@ -116,6 +64,98 @@ class _QueryBuilder {
|
|
|
116
64
|
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ not: (_c = (_b = filter.body) === null || _b === void 0 ? void 0 : _b.filters) !== null && _c !== void 0 ? _c : [] });
|
|
117
65
|
return this;
|
|
118
66
|
}
|
|
67
|
+
}
|
|
68
|
+
exports._FilterBuilder = _FilterBuilder;
|
|
69
|
+
class _QueryBuilder extends _FilterBuilder {
|
|
70
|
+
constructor() {
|
|
71
|
+
super();
|
|
72
|
+
this.shouldPerformTextQuery = false;
|
|
73
|
+
}
|
|
74
|
+
build() {
|
|
75
|
+
if (!this.shouldPerformTextQuery)
|
|
76
|
+
return this.body;
|
|
77
|
+
if (!this.defaultQueryValue)
|
|
78
|
+
throw new Error("Please set the search query by calling .query('my search query') before performing a text search.");
|
|
79
|
+
this.body.query = this.defaultQueryValue;
|
|
80
|
+
return this.body;
|
|
81
|
+
}
|
|
82
|
+
query(query, fieldsToSearch) {
|
|
83
|
+
this.defaultQueryValue = query;
|
|
84
|
+
if (fieldsToSearch)
|
|
85
|
+
this.body.fieldsToSearch = fieldsToSearch;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
queryConfig(weight, options) {
|
|
89
|
+
this.body.queryConfig = { weight, ...(options !== null && options !== void 0 ? options : {}) };
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
text(field, weight) {
|
|
93
|
+
this.shouldPerformTextQuery = true;
|
|
94
|
+
if (!field)
|
|
95
|
+
return this; // support searching all fields
|
|
96
|
+
if (!this.body.fieldsToSearch)
|
|
97
|
+
this.body.fieldsToSearch = [];
|
|
98
|
+
if (!weight)
|
|
99
|
+
this.body.fieldsToSearch.push(field);
|
|
100
|
+
else
|
|
101
|
+
this.body.fieldsToSearch.push({ key: field, weight });
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
vector(field, ...args) {
|
|
105
|
+
if (!Array.isArray(this.body.vectorSearchQuery))
|
|
106
|
+
this.body.vectorSearchQuery = [];
|
|
107
|
+
let payload = { field };
|
|
108
|
+
const inferredModelMatch = field.match(/_(.*)_.*vector_/); // title_text@1-0_vector_ -> text@1-0
|
|
109
|
+
if (inferredModelMatch && inferredModelMatch[1])
|
|
110
|
+
payload.model = inferredModelMatch[1]; // this can be overridden
|
|
111
|
+
for (const arg of args) {
|
|
112
|
+
if (typeof arg === 'number')
|
|
113
|
+
payload.weight = arg; // weight
|
|
114
|
+
else
|
|
115
|
+
payload = { ...payload, ...arg }; // options
|
|
116
|
+
}
|
|
117
|
+
this.body.vectorSearchQuery.push(payload);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
sort(field, direction) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.body) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b.length))
|
|
123
|
+
this.body.sort = {};
|
|
124
|
+
this.body.sort[field] = direction;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
textSort(field, direction) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.body) === null || _a === void 0 ? void 0 : _a.textSort) === null || _b === void 0 ? void 0 : _b.length))
|
|
130
|
+
this.body.textSort = {};
|
|
131
|
+
this.body.textSort[field] = direction;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
rawOption(key, value) {
|
|
135
|
+
this.body[key] = value;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
minimumRelevance(value) {
|
|
139
|
+
this.body.minimumRelevance = value;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
page(value) {
|
|
143
|
+
this.body.page = value;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
pageSize(value) {
|
|
147
|
+
this.body.pageSize = value;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
includeFields(fields) {
|
|
151
|
+
this.body.includeFields = fields;
|
|
152
|
+
}
|
|
153
|
+
excludeFields(fields) {
|
|
154
|
+
this.body.excludeFields = fields;
|
|
155
|
+
}
|
|
156
|
+
includeVectors(whetherToInclude) {
|
|
157
|
+
this.body.includeVectors = whetherToInclude;
|
|
158
|
+
}
|
|
119
159
|
aggregate(field, options) {
|
|
120
160
|
var _a, _b, _c;
|
|
121
161
|
(_a = this.body.fieldsToAggregate) === null || _a === void 0 ? void 0 : _a.push({ key: field, ...options, fieldsToAggregate: (_c = (_b = options === null || options === void 0 ? void 0 : options.aggregates) === null || _b === void 0 ? void 0 : _b.body.fieldsToAggregate) !== null && _c !== void 0 ? _c : [] });
|