@databricks/sdk-vectorsearch 0.0.0-dev → 0.1.0-dev.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.
@@ -0,0 +1,817 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import type {Call} from '@databricks/sdk-core/api';
5
+ import {retryOn} from '@databricks/sdk-core/api';
6
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
7
+ import type {Logger} from '@databricks/sdk-core/logger';
8
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
9
+ import type {CallOptions} from '@databricks/sdk-options/call';
10
+ import type {ClientOptions} from '@databricks/sdk-options/client';
11
+ import type {HttpClient} from '@databricks/sdk-core/http';
12
+ import {newHttpClient} from './transport';
13
+ import {
14
+ buildHttpRequest,
15
+ executeCall,
16
+ executeHttpCall,
17
+ marshalRequest,
18
+ parseResponse,
19
+ } from './utils';
20
+ import pkgJson from '../../package.json' with {type: 'json'};
21
+ import type {
22
+ CreateEndpointRequest,
23
+ CreateVectorIndexRequest,
24
+ DeleteDataVectorIndexRequest,
25
+ DeleteDataVectorIndexResponse,
26
+ DeleteEndpointRequest,
27
+ DeleteEndpointResponse,
28
+ DeleteVectorIndexRequest,
29
+ DeleteVectorIndexResponse,
30
+ Endpoint,
31
+ GetEndpointRequest,
32
+ GetVectorIndexRequest,
33
+ ListEndpointRequest,
34
+ ListEndpointResponse,
35
+ ListVectorIndexRequest,
36
+ ListVectorIndexResponse,
37
+ MiniVectorIndex,
38
+ PatchEndpointBudgetPolicyRequest,
39
+ PatchEndpointBudgetPolicyResponse,
40
+ PatchEndpointRequest,
41
+ QueryVectorIndexNextPageRequest,
42
+ QueryVectorIndexRequest,
43
+ QueryVectorIndexResponse,
44
+ RetrieveUserVisibleMetricsRequest,
45
+ RetrieveUserVisibleMetricsResponse,
46
+ ScanVectorIndexRequest,
47
+ ScanVectorIndexResponse,
48
+ SyncVectorIndexRequest,
49
+ SyncVectorIndexResponse,
50
+ UpdateEndpointCustomTagsRequest,
51
+ UpdateEndpointCustomTagsResponse,
52
+ UpsertDataVectorIndexRequest,
53
+ UpsertDataVectorIndexResponse,
54
+ VectorIndex,
55
+ } from './model';
56
+ import {
57
+ EndpointStatus_State,
58
+ marshalCreateEndpointRequestSchema,
59
+ marshalCreateVectorIndexRequestSchema,
60
+ marshalPatchEndpointBudgetPolicyRequestSchema,
61
+ marshalPatchEndpointRequestSchema,
62
+ marshalQueryVectorIndexNextPageRequestSchema,
63
+ marshalQueryVectorIndexRequestSchema,
64
+ marshalRetrieveUserVisibleMetricsRequestSchema,
65
+ marshalScanVectorIndexRequestSchema,
66
+ marshalSyncVectorIndexRequestSchema,
67
+ marshalUpdateEndpointCustomTagsRequestSchema,
68
+ marshalUpsertDataVectorIndexRequestSchema,
69
+ unmarshalDeleteDataVectorIndexResponseSchema,
70
+ unmarshalDeleteEndpointResponseSchema,
71
+ unmarshalDeleteVectorIndexResponseSchema,
72
+ unmarshalEndpointSchema,
73
+ unmarshalListEndpointResponseSchema,
74
+ unmarshalListVectorIndexResponseSchema,
75
+ unmarshalPatchEndpointBudgetPolicyResponseSchema,
76
+ unmarshalQueryVectorIndexResponseSchema,
77
+ unmarshalRetrieveUserVisibleMetricsResponseSchema,
78
+ unmarshalScanVectorIndexResponseSchema,
79
+ unmarshalSyncVectorIndexResponseSchema,
80
+ unmarshalUpdateEndpointCustomTagsResponseSchema,
81
+ unmarshalUpsertDataVectorIndexResponseSchema,
82
+ unmarshalVectorIndexSchema,
83
+ } from './model';
84
+
85
+ // Package identity segment for this client to be used in the User-Agent header.
86
+ const PACKAGE_SEGMENT = {
87
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
88
+ value: pkgJson.version,
89
+ };
90
+
91
+ class StillRunningError extends Error {}
92
+
93
+ export class Client {
94
+ private readonly host: string;
95
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
96
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
97
+ // request.
98
+ private readonly workspaceId: string | undefined;
99
+ private readonly httpClient: HttpClient;
100
+ private readonly logger: Logger;
101
+ // User-Agent header value. Composed once at construction from
102
+ // createDefault() merged with this package's identity and the active
103
+ // credential's name.
104
+ private readonly userAgent: string;
105
+
106
+ constructor(options: ClientOptions) {
107
+ if (options.host === undefined) {
108
+ throw new Error('Host is required.');
109
+ }
110
+ this.host = options.host.replace(/\/$/, '');
111
+ this.workspaceId = options.workspaceId;
112
+ this.logger = options.logger ?? new NoOpLogger();
113
+ let info = createDefault().with(PACKAGE_SEGMENT);
114
+ if (options.credentials !== undefined) {
115
+ info = info
116
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
117
+ .with({key: 'auth', value: options.credentials.name()});
118
+ }
119
+ this.userAgent = info.toString();
120
+ this.httpClient = newHttpClient(options);
121
+ }
122
+
123
+ /** Create a new endpoint. */
124
+ async createEndpoint(
125
+ req: CreateEndpointRequest,
126
+ options?: CallOptions
127
+ ): Promise<Endpoint> {
128
+ const url = `${this.host}/api/2.0/vector-search/endpoints`;
129
+ const body = marshalRequest(req, marshalCreateEndpointRequestSchema);
130
+ let resp: Endpoint | undefined;
131
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
132
+ const headers = new Headers({'Content-Type': 'application/json'});
133
+ if (this.workspaceId !== undefined) {
134
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
135
+ }
136
+ headers.set('User-Agent', this.userAgent);
137
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
138
+ const respBody = await executeHttpCall({
139
+ request: httpReq,
140
+ httpClient: this.httpClient,
141
+ logger: this.logger,
142
+ });
143
+ resp = parseResponse(respBody, unmarshalEndpointSchema);
144
+ };
145
+ await executeCall(call, options);
146
+ if (resp === undefined) {
147
+ throw new Error('API call completed without a result.');
148
+ }
149
+ return resp;
150
+ }
151
+
152
+ async createEndpointWaiter(
153
+ req: CreateEndpointRequest,
154
+ options?: CallOptions
155
+ ): Promise<CreateEndpointWaiter> {
156
+ const resp = await this.createEndpoint(req, options);
157
+ if (resp.name === undefined) {
158
+ throw new Error('response field name required for polling is missing');
159
+ }
160
+ return new CreateEndpointWaiter(this, resp.name);
161
+ }
162
+
163
+ /** Create a new index. */
164
+ async createVectorIndex(
165
+ req: CreateVectorIndexRequest,
166
+ options?: CallOptions
167
+ ): Promise<VectorIndex> {
168
+ const url = `${this.host}/api/2.0/vector-search/indexes`;
169
+ const body = marshalRequest(req, marshalCreateVectorIndexRequestSchema);
170
+ let resp: VectorIndex | undefined;
171
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
172
+ const headers = new Headers({'Content-Type': 'application/json'});
173
+ if (this.workspaceId !== undefined) {
174
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
175
+ }
176
+ headers.set('User-Agent', this.userAgent);
177
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
178
+ const respBody = await executeHttpCall({
179
+ request: httpReq,
180
+ httpClient: this.httpClient,
181
+ logger: this.logger,
182
+ });
183
+ resp = parseResponse(respBody, unmarshalVectorIndexSchema);
184
+ };
185
+ await executeCall(call, options);
186
+ if (resp === undefined) {
187
+ throw new Error('API call completed without a result.');
188
+ }
189
+ return resp;
190
+ }
191
+
192
+ /** Handles the deletion of data from a specified vector index. */
193
+ async deleteDataVectorIndex(
194
+ req: DeleteDataVectorIndexRequest,
195
+ options?: CallOptions
196
+ ): Promise<DeleteDataVectorIndexResponse> {
197
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}/delete-data`;
198
+ const params = new URLSearchParams();
199
+ if (req.primaryKeys !== undefined) {
200
+ params.append('primary_keys', String(req.primaryKeys));
201
+ }
202
+ const query = params.toString();
203
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
204
+ let resp: DeleteDataVectorIndexResponse | undefined;
205
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
206
+ const headers = new Headers();
207
+ if (this.workspaceId !== undefined) {
208
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
209
+ }
210
+ headers.set('User-Agent', this.userAgent);
211
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
212
+ const respBody = await executeHttpCall({
213
+ request: httpReq,
214
+ httpClient: this.httpClient,
215
+ logger: this.logger,
216
+ });
217
+ resp = parseResponse(
218
+ respBody,
219
+ unmarshalDeleteDataVectorIndexResponseSchema
220
+ );
221
+ };
222
+ await executeCall(call, options);
223
+ if (resp === undefined) {
224
+ throw new Error('API call completed without a result.');
225
+ }
226
+ return resp;
227
+ }
228
+
229
+ /** Delete an AI Search endpoint. */
230
+ async deleteEndpoint(
231
+ req: DeleteEndpointRequest,
232
+ options?: CallOptions
233
+ ): Promise<DeleteEndpointResponse> {
234
+ const url = `${this.host}/api/2.0/vector-search/endpoints/${req.name ?? ''}`;
235
+ let resp: DeleteEndpointResponse | undefined;
236
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
237
+ const headers = new Headers();
238
+ if (this.workspaceId !== undefined) {
239
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
240
+ }
241
+ headers.set('User-Agent', this.userAgent);
242
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
243
+ const respBody = await executeHttpCall({
244
+ request: httpReq,
245
+ httpClient: this.httpClient,
246
+ logger: this.logger,
247
+ });
248
+ resp = parseResponse(respBody, unmarshalDeleteEndpointResponseSchema);
249
+ };
250
+ await executeCall(call, options);
251
+ if (resp === undefined) {
252
+ throw new Error('API call completed without a result.');
253
+ }
254
+ return resp;
255
+ }
256
+
257
+ /** Delete an index. */
258
+ async deleteVectorIndex(
259
+ req: DeleteVectorIndexRequest,
260
+ options?: CallOptions
261
+ ): Promise<DeleteVectorIndexResponse> {
262
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}`;
263
+ let resp: DeleteVectorIndexResponse | undefined;
264
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
265
+ const headers = new Headers();
266
+ if (this.workspaceId !== undefined) {
267
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
268
+ }
269
+ headers.set('User-Agent', this.userAgent);
270
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
271
+ const respBody = await executeHttpCall({
272
+ request: httpReq,
273
+ httpClient: this.httpClient,
274
+ logger: this.logger,
275
+ });
276
+ resp = parseResponse(respBody, unmarshalDeleteVectorIndexResponseSchema);
277
+ };
278
+ await executeCall(call, options);
279
+ if (resp === undefined) {
280
+ throw new Error('API call completed without a result.');
281
+ }
282
+ return resp;
283
+ }
284
+
285
+ /** Get details for a single AI Search endpoint. */
286
+ async getEndpoint(
287
+ req: GetEndpointRequest,
288
+ options?: CallOptions
289
+ ): Promise<Endpoint> {
290
+ const url = `${this.host}/api/2.0/vector-search/endpoints/${req.name ?? ''}`;
291
+ let resp: Endpoint | undefined;
292
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
293
+ const headers = new Headers();
294
+ if (this.workspaceId !== undefined) {
295
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
296
+ }
297
+ headers.set('User-Agent', this.userAgent);
298
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
299
+ const respBody = await executeHttpCall({
300
+ request: httpReq,
301
+ httpClient: this.httpClient,
302
+ logger: this.logger,
303
+ });
304
+ resp = parseResponse(respBody, unmarshalEndpointSchema);
305
+ };
306
+ await executeCall(call, options);
307
+ if (resp === undefined) {
308
+ throw new Error('API call completed without a result.');
309
+ }
310
+ return resp;
311
+ }
312
+
313
+ /** Get an index. */
314
+ async getVectorIndex(
315
+ req: GetVectorIndexRequest,
316
+ options?: CallOptions
317
+ ): Promise<VectorIndex> {
318
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}`;
319
+ const params = new URLSearchParams();
320
+ if (req.ensureRerankerCompatible !== undefined) {
321
+ params.append(
322
+ 'ensure_reranker_compatible',
323
+ String(req.ensureRerankerCompatible)
324
+ );
325
+ }
326
+ const query = params.toString();
327
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
328
+ let resp: VectorIndex | undefined;
329
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
330
+ const headers = new Headers();
331
+ if (this.workspaceId !== undefined) {
332
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
333
+ }
334
+ headers.set('User-Agent', this.userAgent);
335
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
336
+ const respBody = await executeHttpCall({
337
+ request: httpReq,
338
+ httpClient: this.httpClient,
339
+ logger: this.logger,
340
+ });
341
+ resp = parseResponse(respBody, unmarshalVectorIndexSchema);
342
+ };
343
+ await executeCall(call, options);
344
+ if (resp === undefined) {
345
+ throw new Error('API call completed without a result.');
346
+ }
347
+ return resp;
348
+ }
349
+
350
+ /** List all AI Search endpoints in the workspace. */
351
+ async listEndpoint(
352
+ req: ListEndpointRequest,
353
+ options?: CallOptions
354
+ ): Promise<ListEndpointResponse> {
355
+ const url = `${this.host}/api/2.0/vector-search/endpoints`;
356
+ const params = new URLSearchParams();
357
+ if (req.pageToken !== undefined) {
358
+ params.append('page_token', req.pageToken);
359
+ }
360
+ const query = params.toString();
361
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
362
+ let resp: ListEndpointResponse | undefined;
363
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
364
+ const headers = new Headers();
365
+ if (this.workspaceId !== undefined) {
366
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
367
+ }
368
+ headers.set('User-Agent', this.userAgent);
369
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
370
+ const respBody = await executeHttpCall({
371
+ request: httpReq,
372
+ httpClient: this.httpClient,
373
+ logger: this.logger,
374
+ });
375
+ resp = parseResponse(respBody, unmarshalListEndpointResponseSchema);
376
+ };
377
+ await executeCall(call, options);
378
+ if (resp === undefined) {
379
+ throw new Error('API call completed without a result.');
380
+ }
381
+ return resp;
382
+ }
383
+
384
+ async *listEndpointIter(
385
+ req: ListEndpointRequest,
386
+ options?: CallOptions
387
+ ): AsyncGenerator<Endpoint> {
388
+ const pageReq: ListEndpointRequest = {...req};
389
+ for (;;) {
390
+ const resp = await this.listEndpoint(pageReq, options);
391
+ for (const item of resp.endpoints ?? []) {
392
+ yield item;
393
+ }
394
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
395
+ return;
396
+ }
397
+ pageReq.pageToken = resp.nextPageToken;
398
+ }
399
+ }
400
+
401
+ /** List all indexes in the given endpoint. */
402
+ async listVectorIndex(
403
+ req: ListVectorIndexRequest,
404
+ options?: CallOptions
405
+ ): Promise<ListVectorIndexResponse> {
406
+ const url = `${this.host}/api/2.0/vector-search/indexes`;
407
+ const params = new URLSearchParams();
408
+ if (req.endpointName !== undefined) {
409
+ params.append('endpoint_name', req.endpointName);
410
+ }
411
+ if (req.pageToken !== undefined) {
412
+ params.append('page_token', req.pageToken);
413
+ }
414
+ const query = params.toString();
415
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
416
+ let resp: ListVectorIndexResponse | undefined;
417
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
418
+ const headers = new Headers();
419
+ if (this.workspaceId !== undefined) {
420
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
421
+ }
422
+ headers.set('User-Agent', this.userAgent);
423
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
424
+ const respBody = await executeHttpCall({
425
+ request: httpReq,
426
+ httpClient: this.httpClient,
427
+ logger: this.logger,
428
+ });
429
+ resp = parseResponse(respBody, unmarshalListVectorIndexResponseSchema);
430
+ };
431
+ await executeCall(call, options);
432
+ if (resp === undefined) {
433
+ throw new Error('API call completed without a result.');
434
+ }
435
+ return resp;
436
+ }
437
+
438
+ async *listVectorIndexIter(
439
+ req: ListVectorIndexRequest,
440
+ options?: CallOptions
441
+ ): AsyncGenerator<MiniVectorIndex> {
442
+ const pageReq: ListVectorIndexRequest = {...req};
443
+ for (;;) {
444
+ const resp = await this.listVectorIndex(pageReq, options);
445
+ for (const item of resp.vectorIndexes ?? []) {
446
+ yield item;
447
+ }
448
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
449
+ return;
450
+ }
451
+ pageReq.pageToken = resp.nextPageToken;
452
+ }
453
+ }
454
+
455
+ /** Update an endpoint */
456
+ async patchEndpoint(
457
+ req: PatchEndpointRequest,
458
+ options?: CallOptions
459
+ ): Promise<Endpoint> {
460
+ const url = `${this.host}/api/2.0/vector-search/endpoints/${req.name ?? ''}`;
461
+ const body = marshalRequest(req, marshalPatchEndpointRequestSchema);
462
+ let resp: Endpoint | undefined;
463
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
464
+ const headers = new Headers({'Content-Type': 'application/json'});
465
+ if (this.workspaceId !== undefined) {
466
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
467
+ }
468
+ headers.set('User-Agent', this.userAgent);
469
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
470
+ const respBody = await executeHttpCall({
471
+ request: httpReq,
472
+ httpClient: this.httpClient,
473
+ logger: this.logger,
474
+ });
475
+ resp = parseResponse(respBody, unmarshalEndpointSchema);
476
+ };
477
+ await executeCall(call, options);
478
+ if (resp === undefined) {
479
+ throw new Error('API call completed without a result.');
480
+ }
481
+ return resp;
482
+ }
483
+
484
+ /** Update the budget policy of an endpoint */
485
+ async patchEndpointBudgetPolicy(
486
+ req: PatchEndpointBudgetPolicyRequest,
487
+ options?: CallOptions
488
+ ): Promise<PatchEndpointBudgetPolicyResponse> {
489
+ const url = `${this.host}/api/2.0/vector-search/endpoints/${req.name ?? ''}/budget-policy`;
490
+ const body = marshalRequest(
491
+ req,
492
+ marshalPatchEndpointBudgetPolicyRequestSchema
493
+ );
494
+ let resp: PatchEndpointBudgetPolicyResponse | undefined;
495
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
496
+ const headers = new Headers({'Content-Type': 'application/json'});
497
+ if (this.workspaceId !== undefined) {
498
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
499
+ }
500
+ headers.set('User-Agent', this.userAgent);
501
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
502
+ const respBody = await executeHttpCall({
503
+ request: httpReq,
504
+ httpClient: this.httpClient,
505
+ logger: this.logger,
506
+ });
507
+ resp = parseResponse(
508
+ respBody,
509
+ unmarshalPatchEndpointBudgetPolicyResponseSchema
510
+ );
511
+ };
512
+ await executeCall(call, options);
513
+ if (resp === undefined) {
514
+ throw new Error('API call completed without a result.');
515
+ }
516
+ return resp;
517
+ }
518
+
519
+ /** Query the specified vector index. */
520
+ async queryVectorIndex(
521
+ req: QueryVectorIndexRequest,
522
+ options?: CallOptions
523
+ ): Promise<QueryVectorIndexResponse> {
524
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}/query`;
525
+ const body = marshalRequest(req, marshalQueryVectorIndexRequestSchema);
526
+ let resp: QueryVectorIndexResponse | undefined;
527
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
528
+ const headers = new Headers({'Content-Type': 'application/json'});
529
+ if (this.workspaceId !== undefined) {
530
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
531
+ }
532
+ headers.set('User-Agent', this.userAgent);
533
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
534
+ const respBody = await executeHttpCall({
535
+ request: httpReq,
536
+ httpClient: this.httpClient,
537
+ logger: this.logger,
538
+ });
539
+ resp = parseResponse(respBody, unmarshalQueryVectorIndexResponseSchema);
540
+ };
541
+ await executeCall(call, options);
542
+ if (resp === undefined) {
543
+ throw new Error('API call completed without a result.');
544
+ }
545
+ return resp;
546
+ }
547
+
548
+ /** Use `next_page_token` returned from previous `QueryVectorIndex` or `QueryVectorIndexNextPage` request to fetch next page of results. */
549
+ async queryVectorIndexNextPage(
550
+ req: QueryVectorIndexNextPageRequest,
551
+ options?: CallOptions
552
+ ): Promise<QueryVectorIndexResponse> {
553
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}/query-next-page`;
554
+ const body = marshalRequest(
555
+ req,
556
+ marshalQueryVectorIndexNextPageRequestSchema
557
+ );
558
+ let resp: QueryVectorIndexResponse | undefined;
559
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
560
+ const headers = new Headers({'Content-Type': 'application/json'});
561
+ if (this.workspaceId !== undefined) {
562
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
563
+ }
564
+ headers.set('User-Agent', this.userAgent);
565
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
566
+ const respBody = await executeHttpCall({
567
+ request: httpReq,
568
+ httpClient: this.httpClient,
569
+ logger: this.logger,
570
+ });
571
+ resp = parseResponse(respBody, unmarshalQueryVectorIndexResponseSchema);
572
+ };
573
+ await executeCall(call, options);
574
+ if (resp === undefined) {
575
+ throw new Error('API call completed without a result.');
576
+ }
577
+ return resp;
578
+ }
579
+
580
+ /** Retrieve user-visible metrics for an endpoint */
581
+ async retrieveUserVisibleMetrics(
582
+ req: RetrieveUserVisibleMetricsRequest,
583
+ options?: CallOptions
584
+ ): Promise<RetrieveUserVisibleMetricsResponse> {
585
+ const url = `${this.host}/api/2.0/vector-search/endpoints/${req.name ?? ''}/metrics`;
586
+ const body = marshalRequest(
587
+ req,
588
+ marshalRetrieveUserVisibleMetricsRequestSchema
589
+ );
590
+ let resp: RetrieveUserVisibleMetricsResponse | undefined;
591
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
592
+ const headers = new Headers({'Content-Type': 'application/json'});
593
+ if (this.workspaceId !== undefined) {
594
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
595
+ }
596
+ headers.set('User-Agent', this.userAgent);
597
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
598
+ const respBody = await executeHttpCall({
599
+ request: httpReq,
600
+ httpClient: this.httpClient,
601
+ logger: this.logger,
602
+ });
603
+ resp = parseResponse(
604
+ respBody,
605
+ unmarshalRetrieveUserVisibleMetricsResponseSchema
606
+ );
607
+ };
608
+ await executeCall(call, options);
609
+ if (resp === undefined) {
610
+ throw new Error('API call completed without a result.');
611
+ }
612
+ return resp;
613
+ }
614
+
615
+ /** Scan the specified vector index and return the first `num_results` entries after the exclusive `primary_key`. */
616
+ async scanVectorIndex(
617
+ req: ScanVectorIndexRequest,
618
+ options?: CallOptions
619
+ ): Promise<ScanVectorIndexResponse> {
620
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}/scan`;
621
+ const body = marshalRequest(req, marshalScanVectorIndexRequestSchema);
622
+ let resp: ScanVectorIndexResponse | undefined;
623
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
624
+ const headers = new Headers({'Content-Type': 'application/json'});
625
+ if (this.workspaceId !== undefined) {
626
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
627
+ }
628
+ headers.set('User-Agent', this.userAgent);
629
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
630
+ const respBody = await executeHttpCall({
631
+ request: httpReq,
632
+ httpClient: this.httpClient,
633
+ logger: this.logger,
634
+ });
635
+ resp = parseResponse(respBody, unmarshalScanVectorIndexResponseSchema);
636
+ };
637
+ await executeCall(call, options);
638
+ if (resp === undefined) {
639
+ throw new Error('API call completed without a result.');
640
+ }
641
+ return resp;
642
+ }
643
+
644
+ /** Triggers a synchronization process for a specified vector index. */
645
+ async syncVectorIndex(
646
+ req: SyncVectorIndexRequest,
647
+ options?: CallOptions
648
+ ): Promise<SyncVectorIndexResponse> {
649
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}/sync`;
650
+ const body = marshalRequest(req, marshalSyncVectorIndexRequestSchema);
651
+ let resp: SyncVectorIndexResponse | undefined;
652
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
653
+ const headers = new Headers({'Content-Type': 'application/json'});
654
+ if (this.workspaceId !== undefined) {
655
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
656
+ }
657
+ headers.set('User-Agent', this.userAgent);
658
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
659
+ const respBody = await executeHttpCall({
660
+ request: httpReq,
661
+ httpClient: this.httpClient,
662
+ logger: this.logger,
663
+ });
664
+ resp = parseResponse(respBody, unmarshalSyncVectorIndexResponseSchema);
665
+ };
666
+ await executeCall(call, options);
667
+ if (resp === undefined) {
668
+ throw new Error('API call completed without a result.');
669
+ }
670
+ return resp;
671
+ }
672
+
673
+ /** Update the custom tags of an endpoint. */
674
+ async updateEndpointCustomTags(
675
+ req: UpdateEndpointCustomTagsRequest,
676
+ options?: CallOptions
677
+ ): Promise<UpdateEndpointCustomTagsResponse> {
678
+ const url = `${this.host}/api/2.0/vector-search/endpoints/${req.name ?? ''}/tags`;
679
+ const body = marshalRequest(
680
+ req,
681
+ marshalUpdateEndpointCustomTagsRequestSchema
682
+ );
683
+ let resp: UpdateEndpointCustomTagsResponse | undefined;
684
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
685
+ const headers = new Headers({'Content-Type': 'application/json'});
686
+ if (this.workspaceId !== undefined) {
687
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
688
+ }
689
+ headers.set('User-Agent', this.userAgent);
690
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
691
+ const respBody = await executeHttpCall({
692
+ request: httpReq,
693
+ httpClient: this.httpClient,
694
+ logger: this.logger,
695
+ });
696
+ resp = parseResponse(
697
+ respBody,
698
+ unmarshalUpdateEndpointCustomTagsResponseSchema
699
+ );
700
+ };
701
+ await executeCall(call, options);
702
+ if (resp === undefined) {
703
+ throw new Error('API call completed without a result.');
704
+ }
705
+ return resp;
706
+ }
707
+
708
+ /** Handles the upserting of data into a specified vector index. */
709
+ async upsertDataVectorIndex(
710
+ req: UpsertDataVectorIndexRequest,
711
+ options?: CallOptions
712
+ ): Promise<UpsertDataVectorIndexResponse> {
713
+ const url = `${this.host}/api/2.0/vector-search/indexes/${req.name ?? ''}/upsert-data`;
714
+ const body = marshalRequest(req, marshalUpsertDataVectorIndexRequestSchema);
715
+ let resp: UpsertDataVectorIndexResponse | undefined;
716
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
717
+ const headers = new Headers({'Content-Type': 'application/json'});
718
+ if (this.workspaceId !== undefined) {
719
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
720
+ }
721
+ headers.set('User-Agent', this.userAgent);
722
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
723
+ const respBody = await executeHttpCall({
724
+ request: httpReq,
725
+ httpClient: this.httpClient,
726
+ logger: this.logger,
727
+ });
728
+ resp = parseResponse(
729
+ respBody,
730
+ unmarshalUpsertDataVectorIndexResponseSchema
731
+ );
732
+ };
733
+ await executeCall(call, options);
734
+ if (resp === undefined) {
735
+ throw new Error('API call completed without a result.');
736
+ }
737
+ return resp;
738
+ }
739
+ }
740
+
741
+ export class CreateEndpointWaiter {
742
+ constructor(
743
+ private readonly client: Client,
744
+ readonly name: string
745
+ ) {}
746
+
747
+ /**
748
+ * Polls until the operation reaches a terminal state.
749
+ *
750
+ * Throws if a failure state is reached.
751
+ */
752
+ async wait(options?: CallOptions): Promise<Endpoint> {
753
+ let result: Endpoint | undefined;
754
+
755
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
756
+ const pollResp = await this.client.getEndpoint(
757
+ {
758
+ name: this.name,
759
+ },
760
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
761
+ );
762
+
763
+ const status = pollResp.endpointStatus?.state;
764
+ if (status === undefined) {
765
+ throw new Error('response missing required status field');
766
+ }
767
+
768
+ switch (status) {
769
+ case EndpointStatus_State.ONLINE:
770
+ result = pollResp;
771
+ return;
772
+ case EndpointStatus_State.OFFLINE: {
773
+ const msg = pollResp.endpointStatus?.message ?? '(no message)';
774
+ throw new Error(`terminal state ${status}: ${msg}`);
775
+ }
776
+ default:
777
+ throw new StillRunningError();
778
+ }
779
+ };
780
+
781
+ const retryOptions: CallOptions = {
782
+ ...(options?.signal !== undefined && {signal: options.signal}),
783
+ retrier: () =>
784
+ retryOn({}, (err: Error) => {
785
+ return err instanceof StillRunningError;
786
+ }),
787
+ };
788
+ await executeCall(call, retryOptions);
789
+ if (result === undefined) {
790
+ throw new Error('API call completed without a result.');
791
+ }
792
+ return result;
793
+ }
794
+
795
+ /** Checks whether the operation has reached a terminal state. */
796
+ async done(options?: CallOptions): Promise<boolean> {
797
+ const pollResp = await this.client.getEndpoint(
798
+ {
799
+ name: this.name,
800
+ },
801
+ options
802
+ );
803
+
804
+ const status = pollResp.endpointStatus?.state;
805
+ if (status === undefined) {
806
+ throw new Error('response missing required status field');
807
+ }
808
+
809
+ switch (status) {
810
+ case EndpointStatus_State.ONLINE:
811
+ case EndpointStatus_State.OFFLINE:
812
+ return true;
813
+ default:
814
+ return false;
815
+ }
816
+ }
817
+ }