@relevanceai/sdk 1.149.0 → 2.0.1
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 +27 -49
- package/dist-cjs/generated/{DiscoveryApi.js → VecDBApi.js} +329 -25
- package/dist-cjs/generated/index.js +1 -1
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/services/index.js +16 -1
- package/dist-cjs/services/vecdb/Dataset.js +137 -0
- package/dist-cjs/services/vecdb/index.js +137 -0
- package/dist-cjs/shared/serviceConfigs.js +4 -4
- package/dist-es/generated/{DiscoveryApi.js → VecDBApi.js} +651 -195
- package/dist-es/generated/index.js +1 -1
- package/dist-es/index.js +1 -1
- package/dist-es/services/index.js +1 -2
- package/dist-es/services/vecdb/Dataset.js +356 -0
- package/dist-es/services/vecdb/index.js +184 -0
- package/dist-es/shared/serviceConfigs.js +4 -4
- package/dist-types/generated/{DiscoveryApi.d.ts → VecDBApi.d.ts} +137 -23
- package/dist-types/generated/{_DiscoveryApiSchemaTypes.d.ts → _VecDBApiSchemaTypes.d.ts} +6841 -4543
- package/dist-types/generated/index.d.ts +1 -1
- package/dist-types/index.d.ts +1 -0
- package/dist-types/services/index.d.ts +1 -0
- package/dist-types/services/vecdb/Dataset.d.ts +52 -0
- package/dist-types/services/vecdb/index.d.ts +44 -0
- package/package.json +3 -2
- /package/dist-cjs/generated/{_DiscoveryApiSchemaTypes.js → _VecDBApiSchemaTypes.js} +0 -0
- /package/dist-es/generated/{_DiscoveryApiSchemaTypes.js → _VecDBApiSchemaTypes.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./VecDBApi";
|
package/dist-es/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './generated';
|
|
2
|
-
|
|
2
|
+
export * from './services';
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __values = (this && this.__values) || function(o) {
|
|
49
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
50
|
+
if (m) return m.call(o);
|
|
51
|
+
if (o && typeof o.length === "number") return {
|
|
52
|
+
next: function () {
|
|
53
|
+
if (o && i >= o.length) o = void 0;
|
|
54
|
+
return { value: o && o[i++], done: !o };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
|
+
};
|
|
59
|
+
import { QueryBuilder, _QueryBuilder } from ".";
|
|
60
|
+
var Dataset = /** @class */ (function () {
|
|
61
|
+
function Dataset(client, name, options) {
|
|
62
|
+
// TODO validate name
|
|
63
|
+
this.client = client;
|
|
64
|
+
this.name = name;
|
|
65
|
+
this.config = options;
|
|
66
|
+
}
|
|
67
|
+
Object.defineProperty(Dataset.prototype, "datasetName", {
|
|
68
|
+
get: function () {
|
|
69
|
+
return this.name;
|
|
70
|
+
},
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
;
|
|
75
|
+
Dataset.prototype.createIfNotExist = function () {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var err_1;
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
_a.trys.push([0, 2, , 4]);
|
|
82
|
+
return [4 /*yield*/, this.client.apiClient.GetDatasetDetails({}, { dataset_id: this.name })];
|
|
83
|
+
case 1:
|
|
84
|
+
_a.sent();
|
|
85
|
+
return [2 /*return*/, false];
|
|
86
|
+
case 2:
|
|
87
|
+
err_1 = _a.sent();
|
|
88
|
+
return [4 /*yield*/, this.client.apiClient.CreateDataset(__assign({ id: this.name }, (this.config.schema ? { schema: this.config.schema } : {})))];
|
|
89
|
+
case 3:
|
|
90
|
+
_a.sent();
|
|
91
|
+
return [2 /*return*/, true];
|
|
92
|
+
case 4: return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
Dataset.prototype.recreateIfExists = function () {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
+
var err_2;
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
_a.trys.push([0, 4, , 5]);
|
|
104
|
+
return [4 /*yield*/, this.client.apiClient.GetDatasetDetails({}, { dataset_id: this.name })];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
return [4 /*yield*/, this.client.apiClient.DeleteDataset({}, { dataset_id: this.name })];
|
|
108
|
+
case 2:
|
|
109
|
+
_a.sent();
|
|
110
|
+
return [4 /*yield*/, this.client.apiClient.CreateDataset(__assign({ id: this.name }, (this.config.schema ? { schema: this.config.schema } : {})))];
|
|
111
|
+
case 3:
|
|
112
|
+
_a.sent();
|
|
113
|
+
return [2 /*return*/, true];
|
|
114
|
+
case 4:
|
|
115
|
+
err_2 = _a.sent();
|
|
116
|
+
return [2 /*return*/, false];
|
|
117
|
+
case 5: return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
Dataset.prototype.insertDocument = function (document, options) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var response;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0: return [4 /*yield*/, this.client.apiClient.Insert(__assign({ document: document }, options), { dataset_id: this.name })];
|
|
128
|
+
case 1:
|
|
129
|
+
response = _a.sent();
|
|
130
|
+
return [2 /*return*/, response.body];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
Dataset.prototype.search = function () {
|
|
136
|
+
var args = [];
|
|
137
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
138
|
+
args[_i] = arguments[_i];
|
|
139
|
+
}
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
var payload, options, args_1, args_1_1, arg, reqCallback, response;
|
|
142
|
+
var e_1, _a;
|
|
143
|
+
var _this = this;
|
|
144
|
+
return __generator(this, function (_b) {
|
|
145
|
+
switch (_b.label) {
|
|
146
|
+
case 0:
|
|
147
|
+
payload = {};
|
|
148
|
+
options = {};
|
|
149
|
+
try {
|
|
150
|
+
for (args_1 = __values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
|
|
151
|
+
arg = args_1_1.value;
|
|
152
|
+
if (arg instanceof _QueryBuilder) {
|
|
153
|
+
payload = __assign(__assign({}, payload), arg.build());
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
options = arg;
|
|
157
|
+
if (options.rawPayload)
|
|
158
|
+
payload = __assign(__assign({}, payload), options.rawPayload);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
163
|
+
finally {
|
|
164
|
+
try {
|
|
165
|
+
if (args_1_1 && !args_1_1.done && (_a = args_1.return)) _a.call(args_1);
|
|
166
|
+
}
|
|
167
|
+
finally { if (e_1) throw e_1.error; }
|
|
168
|
+
}
|
|
169
|
+
reqCallback = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0: return [4 /*yield*/, this.client.apiClient.SimpleSearchPost(payload, { dataset_id: this.name })];
|
|
172
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
173
|
+
}
|
|
174
|
+
}); }); };
|
|
175
|
+
if (!(options.debounce && this.debounceTimer)) return [3 /*break*/, 1];
|
|
176
|
+
clearTimeout(this.debounceTimer);
|
|
177
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
178
|
+
_this.debounceTimer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { var res; return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0: return [4 /*yield*/, reqCallback()];
|
|
181
|
+
case 1:
|
|
182
|
+
res = _a.sent();
|
|
183
|
+
resolve(res);
|
|
184
|
+
return [2 /*return*/];
|
|
185
|
+
}
|
|
186
|
+
}); }); }, options.debounce);
|
|
187
|
+
})];
|
|
188
|
+
case 1: return [4 /*yield*/, reqCallback()];
|
|
189
|
+
case 2:
|
|
190
|
+
response = _b.sent();
|
|
191
|
+
return [2 /*return*/, response.body];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
Dataset.prototype.insertDocuments = function (documents, encoders, options) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var results, finalResults;
|
|
199
|
+
var _this = this;
|
|
200
|
+
return __generator(this, function (_a) {
|
|
201
|
+
switch (_a.label) {
|
|
202
|
+
case 0: return [4 /*yield*/, this._GenericBulkOperation(__assign(__assign({ data: documents !== null && documents !== void 0 ? documents : [] }, options), { fn: function (documentsSlice) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
203
|
+
switch (_a.label) {
|
|
204
|
+
case 0: return [4 /*yield*/, this.client.apiClient.BulkInsert(__assign({ documents: documentsSlice }, (encoders ? { encoders: encoders } : {})), { dataset_id: this.name })];
|
|
205
|
+
case 1: return [2 /*return*/, (_a.sent()).body];
|
|
206
|
+
}
|
|
207
|
+
}); }); } }))];
|
|
208
|
+
case 1:
|
|
209
|
+
results = _a.sent();
|
|
210
|
+
finalResults = results.reduce(function (prev, cur) {
|
|
211
|
+
prev.failed_documents = prev.failed_documents.concat(cur.failed_documents);
|
|
212
|
+
prev.inserted += cur.inserted;
|
|
213
|
+
return prev;
|
|
214
|
+
}, { inserted: 0, failed_documents: [] });
|
|
215
|
+
return [2 /*return*/, finalResults];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
// TODO - ChunkSearch, insert, insertAndVectorize?, vectorize,
|
|
221
|
+
Dataset.prototype._GenericBulkOperation = function (_a) {
|
|
222
|
+
var data = _a.data, batchSize = _a.batchSize, fn = _a.fn, retryCount = _a.retryCount;
|
|
223
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
+
var results, i, retrysSoFar, res, e_2;
|
|
225
|
+
return __generator(this, function (_b) {
|
|
226
|
+
switch (_b.label) {
|
|
227
|
+
case 0:
|
|
228
|
+
batchSize = batchSize !== null && batchSize !== void 0 ? batchSize : 10000;
|
|
229
|
+
retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 1;
|
|
230
|
+
results = [];
|
|
231
|
+
i = 0;
|
|
232
|
+
_b.label = 1;
|
|
233
|
+
case 1:
|
|
234
|
+
if (!(i < (data === null || data === void 0 ? void 0 : data.length))) return [3 /*break*/, 8];
|
|
235
|
+
retrysSoFar = 0;
|
|
236
|
+
_b.label = 2;
|
|
237
|
+
case 2:
|
|
238
|
+
if (!(retrysSoFar < retryCount)) return [3 /*break*/, 7];
|
|
239
|
+
_b.label = 3;
|
|
240
|
+
case 3:
|
|
241
|
+
_b.trys.push([3, 5, , 6]);
|
|
242
|
+
return [4 /*yield*/, fn(data.slice(i, i + batchSize))];
|
|
243
|
+
case 4:
|
|
244
|
+
res = _b.sent();
|
|
245
|
+
results.push(res);
|
|
246
|
+
return [3 /*break*/, 7];
|
|
247
|
+
case 5:
|
|
248
|
+
e_2 = _b.sent();
|
|
249
|
+
console.error("Bulk operation failed with error, retrying - ".concat(e_2));
|
|
250
|
+
return [3 /*break*/, 6];
|
|
251
|
+
case 6:
|
|
252
|
+
retrysSoFar++;
|
|
253
|
+
return [3 /*break*/, 2];
|
|
254
|
+
case 7:
|
|
255
|
+
i += batchSize;
|
|
256
|
+
return [3 /*break*/, 1];
|
|
257
|
+
case 8: return [2 /*return*/, results];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
Dataset.prototype.updateDocument = function (documentId, partialUpdates) {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
+
var response;
|
|
265
|
+
return __generator(this, function (_a) {
|
|
266
|
+
switch (_a.label) {
|
|
267
|
+
case 0: return [4 /*yield*/, this.client.apiClient.Update({ id: documentId, updates: partialUpdates })];
|
|
268
|
+
case 1:
|
|
269
|
+
response = _a.sent();
|
|
270
|
+
return [2 /*return*/, response.body];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
Dataset.prototype.updateDocuments = function (updates, options) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var results, finalResults;
|
|
278
|
+
var _this = this;
|
|
279
|
+
return __generator(this, function (_a) {
|
|
280
|
+
switch (_a.label) {
|
|
281
|
+
case 0: return [4 /*yield*/, this._GenericBulkOperation(__assign(__assign({ data: updates !== null && updates !== void 0 ? updates : [] }, options), { fn: function (updatesSlice) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
282
|
+
switch (_a.label) {
|
|
283
|
+
case 0: return [4 /*yield*/, this.client.apiClient.BulkUpdate({ updates: updatesSlice }, { dataset_id: this.name })];
|
|
284
|
+
case 1: return [2 /*return*/, (_a.sent()).body];
|
|
285
|
+
}
|
|
286
|
+
}); }); } }))];
|
|
287
|
+
case 1:
|
|
288
|
+
results = _a.sent();
|
|
289
|
+
finalResults = results.reduce(function (prev, cur) {
|
|
290
|
+
prev.failed_documents = prev.failed_documents.concat(cur.failed_documents);
|
|
291
|
+
prev.inserted += cur.inserted;
|
|
292
|
+
return prev;
|
|
293
|
+
}, { inserted: 0, failed_documents: [] });
|
|
294
|
+
return [2 /*return*/, finalResults];
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
Dataset.prototype.updateDocumentsWhere = function (filters, partialUpdates) {
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0: return [4 /*yield*/, this.client.apiClient.UpdateWhere({ filters: filters.build().filters, updates: partialUpdates })];
|
|
304
|
+
case 1: return [2 /*return*/, (_a.sent()).body];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
Dataset.prototype.getDocument = function (documentId) {
|
|
310
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
311
|
+
return __generator(this, function (_a) {
|
|
312
|
+
switch (_a.label) {
|
|
313
|
+
case 0: return [4 /*yield*/, this.client.apiClient.GetDocument({ document_id: documentId })];
|
|
314
|
+
case 1: return [2 /*return*/, (_a.sent()).body];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
Dataset.prototype.deleteDocument = function (documentId) {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
321
|
+
return __generator(this, function (_a) {
|
|
322
|
+
switch (_a.label) {
|
|
323
|
+
case 0: return [4 /*yield*/, this.client.apiClient.DeleteDocument({ id: documentId })];
|
|
324
|
+
case 1: return [2 /*return*/, (_a.sent()).body];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
Dataset.prototype.deleteDocuments = function (documentIds) {
|
|
330
|
+
var _a;
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
var filters;
|
|
333
|
+
return __generator(this, function (_b) {
|
|
334
|
+
switch (_b.label) {
|
|
335
|
+
case 0:
|
|
336
|
+
filters = QueryBuilder().match('_id', documentIds);
|
|
337
|
+
return [4 /*yield*/, this.client.apiClient.DeleteWhere({ filters: (_a = filters.build().filters) !== null && _a !== void 0 ? _a : [] })];
|
|
338
|
+
case 1: return [2 /*return*/, (_b.sent()).body];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
Dataset.prototype.deleteDocumentsWhere = function (filters) {
|
|
344
|
+
var _a;
|
|
345
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
+
return __generator(this, function (_b) {
|
|
347
|
+
switch (_b.label) {
|
|
348
|
+
case 0: return [4 /*yield*/, this.client.apiClient.DeleteWhere({ filters: (_a = filters.build().filters) !== null && _a !== void 0 ? _a : [] })];
|
|
349
|
+
case 1: return [2 /*return*/, (_b.sent()).body];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
return Dataset;
|
|
355
|
+
}());
|
|
356
|
+
export { Dataset };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
var __values = (this && this.__values) || function(o) {
|
|
28
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
+
if (m) return m.call(o);
|
|
30
|
+
if (o && typeof o.length === "number") return {
|
|
31
|
+
next: function () {
|
|
32
|
+
if (o && i >= o.length) o = void 0;
|
|
33
|
+
return { value: o && o[i++], done: !o };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
+
};
|
|
38
|
+
import { VecDBApiClient } from '../../';
|
|
39
|
+
import { Dataset } from './Dataset';
|
|
40
|
+
export function QueryBuilder() {
|
|
41
|
+
return new _QueryBuilder();
|
|
42
|
+
}
|
|
43
|
+
export function FilterBuilder() {
|
|
44
|
+
return new _FilterBuilder();
|
|
45
|
+
}
|
|
46
|
+
var _FilterBuilder = /** @class */ (function () {
|
|
47
|
+
function _FilterBuilder() {
|
|
48
|
+
this.body = { filters: [], fieldsToAggregate: [], fieldsToAggregateStats: [] };
|
|
49
|
+
}
|
|
50
|
+
_FilterBuilder.prototype.buildFilters = function () {
|
|
51
|
+
return this.body.filters;
|
|
52
|
+
};
|
|
53
|
+
_FilterBuilder.prototype.rawFilter = function (filter) {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push(filter);
|
|
56
|
+
return this;
|
|
57
|
+
};
|
|
58
|
+
_FilterBuilder.prototype.filter = function (type, key, value) {
|
|
59
|
+
var _a;
|
|
60
|
+
var _b;
|
|
61
|
+
var options = [];
|
|
62
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
63
|
+
options[_i - 3] = arguments[_i];
|
|
64
|
+
}
|
|
65
|
+
(_b = this.body.filters) === null || _b === void 0 ? void 0 : _b.push((_a = {},
|
|
66
|
+
_a[type] = __assign({ key: key, value: value }, options),
|
|
67
|
+
_a));
|
|
68
|
+
return this;
|
|
69
|
+
};
|
|
70
|
+
_FilterBuilder.prototype.match = function (field, value) {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ match: { field: field, value: value } });
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
75
|
+
_FilterBuilder.prototype.wildcard = function (field, value) {
|
|
76
|
+
var _a;
|
|
77
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ wildcard: { field: field, value: value } });
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
_FilterBuilder.prototype.range = function (field, options) {
|
|
81
|
+
var _a;
|
|
82
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ range: __assign({ field: field }, options) });
|
|
83
|
+
return this;
|
|
84
|
+
};
|
|
85
|
+
_FilterBuilder.prototype.or = function (filters) {
|
|
86
|
+
var _a;
|
|
87
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ or: filters.map(function (f) { var _a; return (_a = f.body.filters) !== null && _a !== void 0 ? _a : []; }) });
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
return _FilterBuilder;
|
|
91
|
+
}());
|
|
92
|
+
export { _FilterBuilder };
|
|
93
|
+
var _QueryBuilder = /** @class */ (function (_super) {
|
|
94
|
+
__extends(_QueryBuilder, _super);
|
|
95
|
+
function _QueryBuilder() {
|
|
96
|
+
var _this = _super.call(this) || this;
|
|
97
|
+
_this.shouldPerformTextQuery = false;
|
|
98
|
+
return _this;
|
|
99
|
+
}
|
|
100
|
+
_QueryBuilder.prototype.build = function () {
|
|
101
|
+
if (!this.shouldPerformTextQuery)
|
|
102
|
+
return this.body;
|
|
103
|
+
if (!this.defaultQueryValue)
|
|
104
|
+
throw new Error("Please set the search query by calling .query('my search query') before performing a text search.");
|
|
105
|
+
this.body.query = this.defaultQueryValue;
|
|
106
|
+
return this.body;
|
|
107
|
+
};
|
|
108
|
+
_QueryBuilder.prototype.vector = function (field) {
|
|
109
|
+
var e_1, _a;
|
|
110
|
+
var args = [];
|
|
111
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
112
|
+
args[_i - 1] = arguments[_i];
|
|
113
|
+
}
|
|
114
|
+
if (!Array.isArray(this.body.vectorSearchQuery))
|
|
115
|
+
this.body.vectorSearchQuery = [];
|
|
116
|
+
var payload = { field: field }; // TODO components['schemas']['simpleSearchAndFlatFilterItem']['search']['vectorSearchQuery']
|
|
117
|
+
var inferredModelMatch = field.match(/_(.*)_.*vector_/); // title_text@1-0_vector_ -> text@1-0
|
|
118
|
+
if (inferredModelMatch && inferredModelMatch[1])
|
|
119
|
+
payload.model = inferredModelMatch[1]; // this can be overridden
|
|
120
|
+
try {
|
|
121
|
+
for (var args_1 = __values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
|
|
122
|
+
var arg = args_1_1.value;
|
|
123
|
+
if (typeof arg === 'number')
|
|
124
|
+
payload.weight = arg; // weight
|
|
125
|
+
else
|
|
126
|
+
payload = __assign(__assign({}, payload), arg); // options
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
130
|
+
finally {
|
|
131
|
+
try {
|
|
132
|
+
if (args_1_1 && !args_1_1.done && (_a = args_1.return)) _a.call(args_1);
|
|
133
|
+
}
|
|
134
|
+
finally { if (e_1) throw e_1.error; }
|
|
135
|
+
}
|
|
136
|
+
this.body.vectorSearchQuery.push(payload);
|
|
137
|
+
return this;
|
|
138
|
+
};
|
|
139
|
+
_QueryBuilder.prototype.sort = function (field, direction) {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
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))
|
|
142
|
+
this.body.sort = {};
|
|
143
|
+
this.body.sort[field] = direction;
|
|
144
|
+
return this;
|
|
145
|
+
};
|
|
146
|
+
_QueryBuilder.prototype.rawOption = function (key, value) {
|
|
147
|
+
this.body[key] = value;
|
|
148
|
+
return this;
|
|
149
|
+
};
|
|
150
|
+
_QueryBuilder.prototype.minimumRelevance = function (value) {
|
|
151
|
+
this.body.minimumRelevance = value;
|
|
152
|
+
return this;
|
|
153
|
+
};
|
|
154
|
+
_QueryBuilder.prototype.page = function (value) {
|
|
155
|
+
this.body.page = value;
|
|
156
|
+
return this;
|
|
157
|
+
};
|
|
158
|
+
_QueryBuilder.prototype.pageSize = function (value) {
|
|
159
|
+
this.body.pageSize = value;
|
|
160
|
+
return this;
|
|
161
|
+
};
|
|
162
|
+
_QueryBuilder.prototype.includeFields = function (fields) {
|
|
163
|
+
this.body.includeFields = fields;
|
|
164
|
+
return this;
|
|
165
|
+
};
|
|
166
|
+
_QueryBuilder.prototype.ask = function (query, field, options) {
|
|
167
|
+
var _a;
|
|
168
|
+
this.body.instantAnswerQuery = __assign(__assign({ query: query, field: field, preset: (_a = options.preset) !== null && _a !== void 0 ? _a : 'support3' }, (options.titleReferenceField ? { titleReferenceField: options.titleReferenceField } : {})), (options.urlReferenceField ? { urlReferenceField: options.urlReferenceField } : {}));
|
|
169
|
+
return this;
|
|
170
|
+
};
|
|
171
|
+
return _QueryBuilder;
|
|
172
|
+
}(_FilterBuilder));
|
|
173
|
+
export { _QueryBuilder };
|
|
174
|
+
var VecDBClient = /** @class */ (function () {
|
|
175
|
+
function VecDBClient(config) {
|
|
176
|
+
this.apiClient = new VecDBApiClient(config !== null && config !== void 0 ? config : {});
|
|
177
|
+
}
|
|
178
|
+
VecDBClient.prototype.dataset = function (name, options) {
|
|
179
|
+
var dataset = new Dataset(this, name, options);
|
|
180
|
+
return dataset;
|
|
181
|
+
};
|
|
182
|
+
return VecDBClient;
|
|
183
|
+
}());
|
|
184
|
+
export { VecDBClient };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export var serviceConfigs = {
|
|
2
|
-
|
|
3
|
-
schema_url: 'https://api
|
|
4
|
-
endpoint: 'https://api
|
|
5
|
-
name: '
|
|
2
|
+
VecDBApi: {
|
|
3
|
+
schema_url: 'https://api-f1db6c.stack.tryrelevance.com/latest/openapi_schema.json',
|
|
4
|
+
endpoint: 'https://api-f1db6c.stack.tryrelevance.com',
|
|
5
|
+
name: 'VecDBApi',
|
|
6
6
|
},
|
|
7
7
|
};
|