1
1
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
3
- import * as Core from 'cloudflare/core' ;
4
3
import { APIResource } from 'cloudflare/resource' ;
5
4
import * as IndexesAPI from 'cloudflare/resources/vectorize/indexes' ;
6
- import { SinglePage } from 'cloudflare/pagination' ;
7
5
8
- export class Indexes extends APIResource {
9
- /**
10
- * Creates and returns a new Vectorize Index.
11
- */
12
- create (
13
- accountIdentifier : string ,
14
- body : IndexCreateParams ,
15
- options ?: Core . RequestOptions ,
16
- ) : Core . APIPromise < CreateIndex | null > {
17
- return (
18
- this . _client . post ( `/accounts/${ accountIdentifier } /vectorize/indexes` , {
19
- body,
20
- ...options ,
21
- } ) as Core . APIPromise < { result : CreateIndex | null } >
22
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
23
- }
24
-
25
- /**
26
- * Updates and returns the specified Vectorize Index.
27
- */
28
- update (
29
- accountIdentifier : string ,
30
- indexName : string ,
31
- body : IndexUpdateParams ,
32
- options ?: Core . RequestOptions ,
33
- ) : Core . APIPromise < CreateIndex | null > {
34
- return (
35
- this . _client . put ( `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } ` , {
36
- body,
37
- ...options ,
38
- } ) as Core . APIPromise < { result : CreateIndex | null } >
39
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
40
- }
41
-
42
- /**
43
- * Returns a list of Vectorize Indexes
44
- */
45
- list (
46
- accountIdentifier : string ,
47
- options ?: Core . RequestOptions ,
48
- ) : Core . PagePromise < CreateIndicesSinglePage , CreateIndex > {
49
- return this . _client . getAPIList (
50
- `/accounts/${ accountIdentifier } /vectorize/indexes` ,
51
- CreateIndicesSinglePage ,
52
- options ,
53
- ) ;
54
- }
55
-
56
- /**
57
- * Deletes the specified Vectorize Index.
58
- */
59
- delete (
60
- accountIdentifier : string ,
61
- indexName : string ,
62
- options ?: Core . RequestOptions ,
63
- ) : Core . APIPromise < IndexDeleteResponse > {
64
- return (
65
- this . _client . delete (
66
- `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } ` ,
67
- options ,
68
- ) as Core . APIPromise < { result : IndexDeleteResponse } >
69
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
70
- }
71
-
72
- /**
73
- * Delete a set of vectors from an index by their vector identifiers.
74
- */
75
- deleteByIds (
76
- accountIdentifier : string ,
77
- indexName : string ,
78
- body : IndexDeleteByIDsParams ,
79
- options ?: Core . RequestOptions ,
80
- ) : Core . APIPromise < IndexDeleteVectorsByID | null > {
81
- return (
82
- this . _client . post ( `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } /delete-by-ids` , {
83
- body,
84
- ...options ,
85
- } ) as Core . APIPromise < { result : IndexDeleteVectorsByID | null } >
86
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
87
- }
88
-
89
- /**
90
- * Returns the specified Vectorize Index.
91
- */
92
- get (
93
- accountIdentifier : string ,
94
- indexName : string ,
95
- options ?: Core . RequestOptions ,
96
- ) : Core . APIPromise < CreateIndex | null > {
97
- return (
98
- this . _client . get (
99
- `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } ` ,
100
- options ,
101
- ) as Core . APIPromise < { result : CreateIndex | null } >
102
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
103
- }
104
-
105
- /**
106
- * Get a set of vectors from an index by their vector identifiers.
107
- */
108
- getByIds (
109
- accountIdentifier : string ,
110
- indexName : string ,
111
- body : IndexGetByIDsParams ,
112
- options ?: Core . RequestOptions ,
113
- ) : Core . APIPromise < IndexGetByIDsResponse | null > {
114
- return (
115
- this . _client . post ( `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } /get-by-ids` , {
116
- body,
117
- ...options ,
118
- } ) as Core . APIPromise < { result : IndexGetByIDsResponse | null } >
119
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
120
- }
121
-
122
- /**
123
- * Inserts vectors into the specified index and returns the count of the vectors
124
- * successfully inserted.
125
- */
126
- insert (
127
- accountIdentifier : string ,
128
- indexName : string ,
129
- body : IndexInsertParams ,
130
- options ?: Core . RequestOptions ,
131
- ) : Core . APIPromise < IndexInsert | null > {
132
- return (
133
- this . _client . post ( `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } /insert` , {
134
- body,
135
- ...options ,
136
- } ) as Core . APIPromise < { result : IndexInsert | null } >
137
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
138
- }
139
-
140
- /**
141
- * Finds vectors closest to a given vector in an index.
142
- */
143
- query (
144
- accountIdentifier : string ,
145
- indexName : string ,
146
- body : IndexQueryParams ,
147
- options ?: Core . RequestOptions ,
148
- ) : Core . APIPromise < IndexQuery | null > {
149
- return (
150
- this . _client . post ( `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } /query` , {
151
- body,
152
- ...options ,
153
- } ) as Core . APIPromise < { result : IndexQuery | null } >
154
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
155
- }
156
-
157
- /**
158
- * Upserts vectors into the specified index, creating them if they do not exist and
159
- * returns the count of values and ids successfully inserted.
160
- */
161
- upsert (
162
- accountIdentifier : string ,
163
- indexName : string ,
164
- body : IndexUpsertParams ,
165
- options ?: Core . RequestOptions ,
166
- ) : Core . APIPromise < IndexUpsert | null > {
167
- return (
168
- this . _client . post ( `/accounts/${ accountIdentifier } /vectorize/indexes/${ indexName } /upsert` , {
169
- body,
170
- ...options ,
171
- } ) as Core . APIPromise < { result : IndexUpsert | null } >
172
- ) . _thenUnwrap ( ( obj ) => obj . result ) ;
173
- }
174
- }
175
-
176
- export class CreateIndicesSinglePage extends SinglePage < CreateIndex > { }
6
+ export class Indexes extends APIResource { }
177
7
178
8
export interface CreateIndex {
179
9
config ?: IndexDimensionConfiguration ;
@@ -252,14 +82,14 @@ export namespace IndexQuery {
252
82
*/
253
83
id ?: string ;
254
84
255
- metadata ?: unknown ;
85
+ metadata ?: unknown | null ;
256
86
257
87
/**
258
88
* The score of the vector according to the index's distance metric
259
89
*/
260
90
score ?: number ;
261
91
262
- values ?: Array < number > ;
92
+ values ?: Array < number > | null ;
263
93
}
264
94
}
265
95
@@ -275,103 +105,11 @@ export interface IndexUpsert {
275
105
ids ?: Array < string > ;
276
106
}
277
107
278
- export type IndexDeleteResponse = unknown | string | null ;
279
-
280
- /**
281
- * Array of vectors with matching ids.
282
- */
283
- export type IndexGetByIDsResponse = unknown ;
284
-
285
- export interface IndexCreateParams {
286
- /**
287
- * Specifies the type of configuration to use for the index.
288
- */
289
- config : IndexCreateParams . VectorizeIndexPresetConfiguration | IndexDimensionConfiguration ;
290
-
291
- name : string ;
292
-
293
- /**
294
- * Specifies the description of the index.
295
- */
296
- description ?: string ;
297
- }
298
-
299
- export namespace IndexCreateParams {
300
- export interface VectorizeIndexPresetConfiguration {
301
- /**
302
- * Specifies the preset to use for the index.
303
- */
304
- preset :
305
- | '@cf/baai/bge-small-en-v1.5'
306
- | '@cf/baai/bge-base-en-v1.5'
307
- | '@cf/baai/bge-large-en-v1.5'
308
- | 'openai/text-embedding-ada-002'
309
- | 'cohere/embed-multilingual-v2.0' ;
310
- }
311
- }
312
-
313
- export interface IndexUpdateParams {
314
- /**
315
- * Specifies the description of the index.
316
- */
317
- description : string ;
318
- }
319
-
320
- export interface IndexDeleteByIDsParams {
321
- /**
322
- * A list of vector identifiers to delete from the index indicated by the path.
323
- */
324
- ids ?: Array < string > ;
325
- }
326
-
327
- export interface IndexGetByIDsParams {
328
- /**
329
- * A list of vector identifiers to retrieve from the index indicated by the path.
330
- */
331
- ids ?: Array < string > ;
332
- }
333
-
334
- export type IndexInsertParams = unknown ;
335
-
336
- export interface IndexQueryParams {
337
- /**
338
- * Whether to return the metadata associated with the closest vectors.
339
- */
340
- returnMetadata ?: boolean ;
341
-
342
- /**
343
- * Whether to return the values associated with the closest vectors.
344
- */
345
- returnValues ?: boolean ;
346
-
347
- /**
348
- * The number of nearest neighbors to find.
349
- */
350
- topK ?: number ;
351
-
352
- /**
353
- * The search vector that will be used to find the nearest neighbors.
354
- */
355
- vector ?: Array < number > ;
356
- }
357
-
358
- export type IndexUpsertParams = unknown ;
359
-
360
108
export namespace Indexes {
361
109
export import CreateIndex = IndexesAPI . CreateIndex ;
362
110
export import IndexDeleteVectorsByID = IndexesAPI . IndexDeleteVectorsByID ;
363
111
export import IndexDimensionConfiguration = IndexesAPI . IndexDimensionConfiguration ;
364
112
export import IndexInsert = IndexesAPI . IndexInsert ;
365
113
export import IndexQuery = IndexesAPI . IndexQuery ;
366
114
export import IndexUpsert = IndexesAPI . IndexUpsert ;
367
- export import IndexDeleteResponse = IndexesAPI . IndexDeleteResponse ;
368
- export import IndexGetByIDsResponse = IndexesAPI . IndexGetByIDsResponse ;
369
- export import CreateIndicesSinglePage = IndexesAPI . CreateIndicesSinglePage ;
370
- export import IndexCreateParams = IndexesAPI . IndexCreateParams ;
371
- export import IndexUpdateParams = IndexesAPI . IndexUpdateParams ;
372
- export import IndexDeleteByIDsParams = IndexesAPI . IndexDeleteByIDsParams ;
373
- export import IndexGetByIDsParams = IndexesAPI . IndexGetByIDsParams ;
374
- export import IndexInsertParams = IndexesAPI . IndexInsertParams ;
375
- export import IndexQueryParams = IndexesAPI . IndexQueryParams ;
376
- export import IndexUpsertParams = IndexesAPI . IndexUpsertParams ;
377
115
}
0 commit comments