@databricks/sdk-vectorsearch 0.1.0-dev.4 → 0.1.0-dev.6

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