@relevanceai/sdk 2.0.0 → 2.0.2

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 (37) hide show
  1. package/dist-cjs/generated/VecDBApi.js +1682 -0
  2. package/dist-cjs/generated/_VecDBApiSchemaTypes.js +3 -0
  3. package/dist-cjs/generated/index.js +17 -0
  4. package/dist-cjs/index.js +18 -0
  5. package/dist-cjs/services/discovery/Dataset.js +126 -0
  6. package/dist-cjs/services/discovery/index.js +159 -0
  7. package/dist-cjs/services/index.js +18 -0
  8. package/dist-cjs/services/vecdb/Dataset.js +137 -0
  9. package/dist-cjs/services/vecdb/index.js +137 -0
  10. package/dist-cjs/shared/BaseClient.js +35 -0
  11. package/dist-cjs/shared/generate.js +90 -0
  12. package/dist-cjs/shared/serviceConfigs.js +10 -0
  13. package/dist-es/generated/VecDBApi.js +2579 -0
  14. package/dist-es/generated/_VecDBApiSchemaTypes.js +2 -0
  15. package/dist-es/generated/index.js +1 -0
  16. package/dist-es/index.js +2 -0
  17. package/dist-es/services/discovery/Dataset.js +126 -0
  18. package/dist-es/services/discovery/index.js +159 -0
  19. package/dist-es/services/index.js +2 -0
  20. package/dist-es/services/vecdb/Dataset.js +356 -0
  21. package/dist-es/services/vecdb/index.js +184 -0
  22. package/dist-es/shared/BaseClient.js +82 -0
  23. package/dist-es/shared/generate.js +224 -0
  24. package/dist-es/shared/serviceConfigs.js +7 -0
  25. package/dist-types/generated/VecDBApi.d.ts +632 -0
  26. package/dist-types/generated/_VecDBApiSchemaTypes.d.ts +22299 -0
  27. package/dist-types/generated/index.d.ts +1 -0
  28. package/dist-types/index.d.ts +2 -0
  29. package/dist-types/services/discovery/Dataset.d.ts +0 -0
  30. package/dist-types/services/discovery/index.d.ts +0 -0
  31. package/dist-types/services/index.d.ts +1 -0
  32. package/dist-types/services/vecdb/Dataset.d.ts +52 -0
  33. package/dist-types/services/vecdb/index.d.ts +44 -0
  34. package/dist-types/shared/BaseClient.d.ts +28 -0
  35. package/dist-types/shared/generate.d.ts +1 -0
  36. package/dist-types/shared/serviceConfigs.d.ts +8 -0
  37. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ ;
2
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./VecDBApi";
@@ -0,0 +1,2 @@
1
+ export * from './generated';
2
+ export * from './services';
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ // import { QueryBuilder, DiscoveryClient, _QueryBuilder } from ".";
3
+ // import { DeleteDocumentOutput, DeleteWhereOutput, GetDocumentOutput, SimpleSearchPostOutput, BulkInsertOutput,UpdateWhereOutput,BulkUpdateOutput } from "../..";
4
+ // import { _GenericMethodOptions } from "../../shared/BaseClient";
5
+ // interface searchOptions {
6
+ // debounce?:number;
7
+ // rawPayload?:any;
8
+ // }
9
+ // export class Dataset {
10
+ // client: DiscoveryClient;
11
+ // name: string;
12
+ // config: any;
13
+ // debounceTimer?:NodeJS.Timeout;
14
+ // constructor(client: DiscoveryClient, name: string, options: any) {
15
+ // // TODO validate name
16
+ // this.client = client;
17
+ // this.name = name;
18
+ // this.config = options;
19
+ // }
20
+ // get datasetName(): string {
21
+ // return this.name;
22
+ // };
23
+ // async insertDocument(document: any, options?: _GenericMethodOptions) {
24
+ // const response = await this.client.apiClient.Insert({
25
+ // document,
26
+ // ...options
27
+ // }, { dataset_id: this.name });
28
+ // return response.body;
29
+ // }
30
+ // // without options
31
+ // async search(): Promise<SimpleSearchPostOutput>;
32
+ // async search(query?: _QueryBuilder): Promise<SimpleSearchPostOutput>;
33
+ // async search(options?:searchOptions): Promise<SimpleSearchPostOutput>;
34
+ // async search(query?: _QueryBuilder,options?:searchOptions): Promise<SimpleSearchPostOutput>;
35
+ // async search(...args:any[]) {
36
+ // let payload: any = {};
37
+ // let options:searchOptions = {};
38
+ // for (const arg of args) {
39
+ // if (arg instanceof _QueryBuilder) {
40
+ // payload = {...payload,...arg.build()};
41
+ // }
42
+ // else {
43
+ // options = arg;
44
+ // if (options.rawPayload) payload = {...payload,...options.rawPayload};
45
+ // }
46
+ // }
47
+ // const reqCallback = async () => await this.client.apiClient.SimpleSearchPost(payload, { dataset_id: this.name });
48
+ // if (options.debounce && this.debounceTimer) {
49
+ // clearTimeout(this.debounceTimer);
50
+ // return new Promise((resolve) => {
51
+ // this.debounceTimer = setTimeout(async () => {const res = await reqCallback();resolve(res)},options.debounce);
52
+ // });
53
+ // } else {
54
+ // const response = await reqCallback();
55
+ // return response.body;
56
+ // }
57
+ // }
58
+ // async insertDocuments(documents: any, options?: _GenericMethodOptions & { batchSize?: number,retryCount?:number, progressCallback?: (progress:BulkInsertOutput[]) => any }):Promise<BulkInsertOutput> {
59
+ // const results = await this._GenericBulkOperation<any,BulkInsertOutput>({
60
+ // data:documents??[],
61
+ // ...options,
62
+ // fn:async (documentsSlice) => (await this.client.apiClient.BulkInsert({ documents:documentsSlice }, { dataset_id: this.name })).body
63
+ // });
64
+ // const finalResults = results.reduce((prev,cur) => {
65
+ // prev.failed_documents = prev.failed_documents.concat(cur.failed_documents);
66
+ // prev.inserted += cur.inserted
67
+ // return prev;
68
+ // },{inserted:0,failed_documents:[]});
69
+ // return finalResults;
70
+ // }
71
+ // // TODO - ChunkSearch, insert, insertAndVectorize?, vectorize,
72
+ // async _GenericBulkOperation<InputItem,OutputItem>({data,batchSize,fn,retryCount}:{
73
+ // data:InputItem[],
74
+ // fn:(data:InputItem[]) => Promise<OutputItem>,
75
+ // batchSize?:number,
76
+ // retryCount?:number,
77
+ // progressCallback?:(progress:OutputItem[]) => any
78
+ // }):Promise<OutputItem[]> {
79
+ // batchSize = batchSize ?? 10000;
80
+ // retryCount = retryCount ?? 1;
81
+ // const results:OutputItem[] = [];
82
+ // for (let i = 0; i < data?.length; i += batchSize) {
83
+ // for (let retrysSoFar = 0; retrysSoFar < retryCount; retrysSoFar++) {
84
+ // try {
85
+ // const res = await fn(data.slice(i, i + batchSize));
86
+ // results.push(res);
87
+ // break;
88
+ // } catch (e) { console.error(`Bulk operation failed with error, retrying - ${e}`) }
89
+ // }
90
+ // }
91
+ // return results;
92
+ // }
93
+ // async updateDocument(documentId: string, partialUpdates: any) {
94
+ // const response = await this.client.apiClient.Update({ id: documentId, updates: partialUpdates });
95
+ // return response.body;
96
+ // }
97
+ // async updateDocuments(updates: any, options?: _GenericMethodOptions & { batchSize?: number,retryCount?:number, progressCallback?: (progress:BulkUpdateOutput[]) => any }):Promise<BulkUpdateOutput> {
98
+ // const results = await this._GenericBulkOperation<any,BulkUpdateOutput>({
99
+ // data:updates??[],
100
+ // ...options,
101
+ // fn:async (updatesSlice) => (await this.client.apiClient.BulkUpdate({ updates:updatesSlice }, { dataset_id: this.name })).body
102
+ // });
103
+ // const finalResults = results.reduce((prev,cur) => {
104
+ // prev.failed_documents = prev.failed_documents.concat(cur.failed_documents);
105
+ // prev.inserted += cur.inserted
106
+ // return prev;
107
+ // },{inserted:0,failed_documents:[]});
108
+ // return finalResults;
109
+ // }
110
+ // async updateDocumentsWhere(filters: _QueryBuilder, partialUpdates: {[id:string]:any}):Promise<UpdateWhereOutput> {
111
+ // return (await this.client.apiClient.UpdateWhere({ filters: filters.build().filters, updates: partialUpdates })).body;
112
+ // }
113
+ // async getDocument(documentId: string):Promise<GetDocumentOutput> {
114
+ // return (await this.client.apiClient.GetDocument({document_id:documentId})).body;
115
+ // }
116
+ // async deleteDocument(documentId: string):Promise<DeleteDocumentOutput> {
117
+ // return (await this.client.apiClient.DeleteDocument({id:documentId})).body;
118
+ // }
119
+ // async deleteDocuments(documentIds: [string]):Promise<DeleteWhereOutput> {
120
+ // const filters = QueryBuilder().match('_id',documentIds);
121
+ // return (await this.client.apiClient.DeleteWhere({ filters: filters.build().filters??[] })).body;
122
+ // }
123
+ // async deleteDocumentsWhere(filters: _QueryBuilder):Promise<DeleteWhereOutput> {
124
+ // return (await this.client.apiClient.DeleteWhere({ filters: filters.build().filters??[]})).body;
125
+ // }
126
+ // }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ // import { DiscoveryApiClient, BulkInsertInput, BulkInsertOutput } from '../../';
3
+ // import { _ClientInput, CommandInput, CommandOutput, _GenericMethodOptions } from '../../shared/BaseClient';
4
+ // import { operations, components } from '../../generated/_DiscoveryApiSchemaTypes';
5
+ // import { Dataset } from './Dataset';
6
+ // type bodyType = operations['SimpleSearchPost']['requestBody']['content']['application/json'];
7
+ // export function QueryBuilder():_QueryBuilder{
8
+ // return new _QueryBuilder();
9
+ // }
10
+ // export function FilterBuilder():_FilterBuilder{
11
+ // return new _FilterBuilder();
12
+ // }
13
+ // export class _FilterBuilder {
14
+ // body: bodyType;
15
+ // constructor() {
16
+ // this.body = {filters:[],fieldsToAggregate:[],fieldsToAggregateStats:[]};
17
+ // }
18
+ // buildFilters() {
19
+ // return this.body.filters;
20
+ // }
21
+ // rawFilter(filter: components['schemas']['filterListItem']) {
22
+ // this.body.filters?.push(filter);
23
+ // return this;
24
+ // }
25
+ // filter(type: string, key: string, value: string, ...options: any) {
26
+ // this.body.filters?.push({
27
+ // [type]: {
28
+ // key,
29
+ // value,
30
+ // ...options
31
+ // }
32
+ // });
33
+ // return this;
34
+ // }
35
+ // match(field: string, value: any) {
36
+ // this.body.filters?.push({ match: { key: field, value } });
37
+ // return this;
38
+ // }
39
+ // wildcard(field: string, value: any) {
40
+ // this.body.filters?.push({ wildcard: { key: field, value } });
41
+ // return this;
42
+ // }
43
+ // selfreference(fielda: string, fieldb: string, operation: "<=" | ">=" | "<" | ">" | "==" | "!=") {
44
+ // this.body.filters?.push({ selfreference: { a: fielda, b: fieldb, operation } });
45
+ // return this;
46
+ // }
47
+ // range(field: string, options: Omit<components['schemas']['filterListItem']['range'],'key'>) {
48
+ // this.body.filters?.push({ range: { key: field, ...options } });
49
+ // return this;
50
+ // }
51
+ // or(filters: _FilterBuilder[]) {
52
+ // this.body.filters?.push({ or: filters.map(f => f.body.filters ?? []) });
53
+ // return this;
54
+ // }
55
+ // not(filter: _FilterBuilder) {
56
+ // this.body.filters?.push({ not: filter.body?.filters ?? [] });
57
+ // return this;
58
+ // }
59
+ // }
60
+ // export class _QueryBuilder extends _FilterBuilder {
61
+ // defaultQueryValue?: string;
62
+ // shouldPerformTextQuery:boolean;
63
+ // constructor() {
64
+ // super();
65
+ // this.shouldPerformTextQuery = false;
66
+ // }
67
+ // build() {
68
+ // if (!this.shouldPerformTextQuery) return this.body;
69
+ // if (!this.defaultQueryValue) throw new Error("Please set the search query by calling .query('my search query') before performing a text search.");
70
+ // this.body.query = this.defaultQueryValue;
71
+ // return this.body;
72
+ // }
73
+ // query(query:string,fieldsToSearch?: bodyType['fieldsToSearch']) {
74
+ // this.defaultQueryValue = query;
75
+ // if (fieldsToSearch) this.body.fieldsToSearch = fieldsToSearch;
76
+ // return this;
77
+ // }
78
+ // queryConfig(weight:number,options?:bodyType['queryConfig']) {
79
+ // this.body.queryConfig = {weight,...(options??{})};
80
+ // return this;
81
+ // }
82
+ // text(field?:string): _QueryBuilder;
83
+ // text(field?:string,weight?:number):_QueryBuilder{
84
+ // this.shouldPerformTextQuery = true;
85
+ // if (!field) return this; // support searching all fields
86
+ // if (!this.body.fieldsToSearch) this.body.fieldsToSearch = [];
87
+ // if (!weight) this.body.fieldsToSearch.push(field);
88
+ // else this.body.fieldsToSearch.push({field,weight});
89
+ // return this;
90
+ // }
91
+ // vector(field: string, weight?: number): _QueryBuilder;
92
+ // vector(field: string, options?: components['schemas']['vectorSearchQuery']): _QueryBuilder;
93
+ // vector(field: string, weight?: number, options?: components['schemas']['vectorSearchQuery']): _QueryBuilder;
94
+ // vector(field: string, ...args:any[]) {
95
+ // if (!Array.isArray(this.body.vectorSearchQuery)) this.body.vectorSearchQuery = [];
96
+ // let payload:components['schemas']['vectorSearchQuery'] = {field};
97
+ // const inferredModelMatch = field.match(/_(.*)_.*vector_/) // title_text@1-0_vector_ -> text@1-0
98
+ // if (inferredModelMatch && inferredModelMatch[1]) payload.model = inferredModelMatch[1]; // this can be overridden
99
+ // for (const arg of args) {
100
+ // if (typeof arg ==='number') payload.weight = arg; // weight
101
+ // else payload = {...payload,...arg}; // options
102
+ // }
103
+ // this.body.vectorSearchQuery.push(payload);
104
+ // return this;
105
+ // }
106
+ // sort(field: string, direction: 'asc' | 'desc') {
107
+ // if (!this?.body?.sort?.length) this.body.sort = {};
108
+ // this.body.sort[field] = direction;
109
+ // return this;
110
+ // }
111
+ // textSort(field: string, direction: 'asc' | 'desc') {
112
+ // if (!this?.body?.textSort?.length) this.body.textSort = {};
113
+ // this.body.textSort[field] = direction;
114
+ // return this;
115
+ // }
116
+ // rawOption(key: string, value: any) {
117
+ // (this.body as any)[key] = value;
118
+ // return this;
119
+ // }
120
+ // minimumRelevance(value: bodyType['minimumRelevance']) {
121
+ // this.body.minimumRelevance = value;
122
+ // return this;
123
+ // }
124
+ // page(value: bodyType['page']) {
125
+ // this.body.page = value;
126
+ // return this;
127
+ // }
128
+ // pageSize(value: bodyType['pageSize']) {
129
+ // this.body.pageSize = value;
130
+ // return this;
131
+ // }
132
+ // includeFields(fields:bodyType['includeFields']) {
133
+ // this.body.includeFields = fields;
134
+ // }
135
+ // excludeFields(fields:bodyType['excludeFields']) {
136
+ // this.body.excludeFields = fields;
137
+ // }
138
+ // includeVectors(whetherToInclude:bodyType['includeVectors']){
139
+ // this.body.includeVectors = whetherToInclude;
140
+ // }
141
+ // aggregate(field: string, options?: { options?: any, aggregates?: _QueryBuilder }) {
142
+ // this.body.fieldsToAggregate?.push({ field, ...options, fieldsToAggregate: options?.aggregates?.body.fieldsToAggregate ?? [] });
143
+ // return this;
144
+ // }
145
+ // aggregateStats(field: string, interval?: number) {
146
+ // this.body.fieldsToAggregateStats?.push({ field, interval });
147
+ // return this;
148
+ // }
149
+ // }
150
+ // export class DiscoveryClient {
151
+ // apiClient:DiscoveryApiClient;
152
+ // constructor(config?: _ClientInput) {
153
+ // this.apiClient = new DiscoveryApiClient(config ?? {});
154
+ // }
155
+ // dataset(name: string, options?: any) {
156
+ // let dataset = new Dataset(this, name, options);
157
+ // return dataset;
158
+ // }
159
+ // }
@@ -0,0 +1,2 @@
1
+ // export * from './discovery';
2
+ export * from './vecdb';
@@ -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 };