File size: 19,208 Bytes
96c8713 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | import VectorIndexApi, { CreateIndexOptions } from './VectorIndexApi'
import VectorDataApi from './VectorDataApi'
import { Fetch } from '../lib/common/fetch'
import VectorBucketApi from './VectorBucketApi'
import {
ApiResponse,
DeleteVectorsOptions,
GetVectorsOptions,
ListIndexesOptions,
ListVectorsOptions,
ListVectorBucketsOptions,
ListVectorBucketsResponse,
PutVectorsOptions,
QueryVectorsOptions,
VectorBucket,
} from '../lib/types'
/**
*
* @alpha
*
* Configuration options for the Storage Vectors client
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*/
export interface StorageVectorsClientOptions {
/**
* Custom headers to include in all requests
*/
headers?: { [key: string]: string }
/**
* Custom fetch implementation (optional)
* Useful for testing or custom request handling
*/
fetch?: Fetch
}
/**
*
* @alpha
*
* Main client for interacting with S3 Vectors API
* Provides access to bucket, index, and vector data operations
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* **Usage Patterns:**
*
* ```typescript
* const { data, error } = await supabase
* .storage
* .vectors
* .createBucket('embeddings-prod')
*
* // Access index operations via buckets
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* await bucket.createIndex({
* indexName: 'documents',
* dataType: 'float32',
* dimension: 1536,
* distanceMetric: 'cosine'
* })
*
* // Access vector operations via index
* const index = bucket.index('documents')
* await index.putVectors({
* vectors: [
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
* ]
* })
*
* // Query similar vectors
* const { data } = await index.queryVectors({
* queryVector: { float32: [...] },
* topK: 5,
* returnDistance: true
* })
* ```
*/
export class StorageVectorsClient extends VectorBucketApi {
/**
* @alpha
*
* Creates a StorageVectorsClient that can manage buckets, indexes, and vectors.
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param url - Base URL of the Storage Vectors REST API.
* @param options.headers - Optional headers (for example `Authorization`) applied to every request.
* @param options.fetch - Optional custom `fetch` implementation for non-browser runtimes.
*
* @example Using supabase-js (recommended)
* ```typescript
* import { createClient } from '@supabase/supabase-js'
*
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* ```
*
* @example Standalone import for bundle-sensitive environments
* ```typescript
* import { StorageVectorsClient } from '@supabase/storage-js'
*
* const client = new StorageVectorsClient(url, options)
* ```
*/
constructor(url: string, options: StorageVectorsClientOptions = {}) {
super(url, options.headers || {}, options.fetch)
}
/**
*
* @alpha
*
* Access operations for a specific vector bucket
* Returns a scoped client for index and vector operations within the bucket
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param vectorBucketName - Name of the vector bucket
* @returns Bucket-scoped client with index and vector operations
*
* @example Accessing a vector bucket
* ```typescript
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* ```
*/
from(vectorBucketName: string): VectorBucketScope {
return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch)
}
/**
*
* @alpha
*
* Creates a new vector bucket
* Vector buckets are containers for vector indexes and their data
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param vectorBucketName - Unique name for the vector bucket
* @returns Promise with empty response on success or error
*
* @example Creating a vector bucket
* ```typescript
* const { data, error } = await supabase
* .storage
* .vectors
* .createBucket('embeddings-prod')
* ```
*/
async createBucket(vectorBucketName: string): Promise<ApiResponse<undefined>> {
return super.createBucket(vectorBucketName)
}
/**
*
* @alpha
*
* Retrieves metadata for a specific vector bucket
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param vectorBucketName - Name of the vector bucket
* @returns Promise with bucket metadata or error
*
* @example Get bucket metadata
* ```typescript
* const { data, error } = await supabase
* .storage
* .vectors
* .getBucket('embeddings-prod')
*
* console.log('Bucket created:', data?.vectorBucket.creationTime)
* ```
*/
async getBucket(vectorBucketName: string): Promise<ApiResponse<{ vectorBucket: VectorBucket }>> {
return super.getBucket(vectorBucketName)
}
/**
*
* @alpha
*
* Lists all vector buckets with optional filtering and pagination
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Optional filters (prefix, maxResults, nextToken)
* @returns Promise with list of buckets or error
*
* @example List vector buckets
* ```typescript
* const { data, error } = await supabase
* .storage
* .vectors
* .listBuckets({ prefix: 'embeddings-' })
*
* data?.vectorBuckets.forEach(bucket => {
* console.log(bucket.vectorBucketName)
* })
* ```
*/
async listBuckets(
options: ListVectorBucketsOptions = {}
): Promise<ApiResponse<ListVectorBucketsResponse>> {
return super.listBuckets(options)
}
/**
*
* @alpha
*
* Deletes a vector bucket (bucket must be empty)
* All indexes must be deleted before deleting the bucket
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param vectorBucketName - Name of the vector bucket to delete
* @returns Promise with empty response on success or error
*
* @example Delete a vector bucket
* ```typescript
* const { data, error } = await supabase
* .storage
* .vectors
* .deleteBucket('embeddings-old')
* ```
*/
async deleteBucket(vectorBucketName: string): Promise<ApiResponse<undefined>> {
return super.deleteBucket(vectorBucketName)
}
}
/**
*
* @alpha
*
* Scoped client for operations within a specific vector bucket
* Provides index management and access to vector operations
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*/
export class VectorBucketScope extends VectorIndexApi {
private vectorBucketName: string
/**
* @alpha
*
* Creates a helper that automatically scopes all index operations to the provided bucket.
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @example Creating a vector bucket scope
* ```typescript
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* ```
*/
constructor(
url: string,
headers: { [key: string]: string },
vectorBucketName: string,
fetch?: Fetch
) {
super(url, headers, fetch)
this.vectorBucketName = vectorBucketName
}
/**
*
* @alpha
*
* Creates a new vector index in this bucket
* Convenience method that automatically includes the bucket name
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Index configuration (vectorBucketName is automatically set)
* @returns Promise with empty response on success or error
*
* @example Creating a vector index
* ```typescript
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* await bucket.createIndex({
* indexName: 'documents-openai',
* dataType: 'float32',
* dimension: 1536,
* distanceMetric: 'cosine',
* metadataConfiguration: {
* nonFilterableMetadataKeys: ['raw_text']
* }
* })
* ```
*/
override async createIndex(options: Omit<CreateIndexOptions, 'vectorBucketName'>) {
return super.createIndex({
...options,
vectorBucketName: this.vectorBucketName,
})
}
/**
*
* @alpha
*
* Lists indexes in this bucket
* Convenience method that automatically includes the bucket name
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Listing options (vectorBucketName is automatically set)
* @returns Promise with response containing indexes array and pagination token or error
*
* @example List indexes
* ```typescript
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* const { data } = await bucket.listIndexes({ prefix: 'documents-' })
* ```
*/
override async listIndexes(options: Omit<ListIndexesOptions, 'vectorBucketName'> = {}) {
return super.listIndexes({
...options,
vectorBucketName: this.vectorBucketName,
})
}
/**
*
* @alpha
*
* Retrieves metadata for a specific index in this bucket
* Convenience method that automatically includes the bucket name
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param indexName - Name of the index to retrieve
* @returns Promise with index metadata or error
*
* @example Get index metadata
* ```typescript
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* const { data } = await bucket.getIndex('documents-openai')
* console.log('Dimension:', data?.index.dimension)
* ```
*/
override async getIndex(indexName: string) {
return super.getIndex(this.vectorBucketName, indexName)
}
/**
*
* @alpha
*
* Deletes an index from this bucket
* Convenience method that automatically includes the bucket name
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param indexName - Name of the index to delete
* @returns Promise with empty response on success or error
*
* @example Delete an index
* ```typescript
* const bucket = supabase.storage.vectors.from('embeddings-prod')
* await bucket.deleteIndex('old-index')
* ```
*/
override async deleteIndex(indexName: string) {
return super.deleteIndex(this.vectorBucketName, indexName)
}
/**
*
* @alpha
*
* Access operations for a specific index within this bucket
* Returns a scoped client for vector data operations
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param indexName - Name of the index
* @returns Index-scoped client with vector data operations
*
* @example Accessing an index
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
*
* // Insert vectors
* await index.putVectors({
* vectors: [
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
* ]
* })
*
* // Query similar vectors
* const { data } = await index.queryVectors({
* queryVector: { float32: [...] },
* topK: 5
* })
* ```
*/
index(indexName: string): VectorIndexScope {
return new VectorIndexScope(
this.url,
this.headers,
this.vectorBucketName,
indexName,
this.fetch
)
}
}
/**
*
* @alpha
*
* Scoped client for operations within a specific vector index
* Provides vector data operations (put, get, list, query, delete)
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*/
export class VectorIndexScope extends VectorDataApi {
private vectorBucketName: string
private indexName: string
/**
*
* @alpha
*
* Creates a helper that automatically scopes all vector operations to the provided bucket/index names.
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @example Creating a vector index scope
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
* ```
*/
constructor(
url: string,
headers: { [key: string]: string },
vectorBucketName: string,
indexName: string,
fetch?: Fetch
) {
super(url, headers, fetch)
this.vectorBucketName = vectorBucketName
this.indexName = indexName
}
/**
*
* @alpha
*
* Inserts or updates vectors in this index
* Convenience method that automatically includes bucket and index names
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Vector insertion options (bucket and index names automatically set)
* @returns Promise with empty response on success or error
*
* @example Insert vectors into an index
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
* await index.putVectors({
* vectors: [
* {
* key: 'doc-1',
* data: { float32: [0.1, 0.2, ...] },
* metadata: { title: 'Introduction', page: 1 }
* }
* ]
* })
* ```
*/
override async putVectors(options: Omit<PutVectorsOptions, 'vectorBucketName' | 'indexName'>) {
return super.putVectors({
...options,
vectorBucketName: this.vectorBucketName,
indexName: this.indexName,
})
}
/**
*
* @alpha
*
* Retrieves vectors by keys from this index
* Convenience method that automatically includes bucket and index names
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Vector retrieval options (bucket and index names automatically set)
* @returns Promise with response containing vectors array or error
*
* @example Get vectors by keys
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
* const { data } = await index.getVectors({
* keys: ['doc-1', 'doc-2'],
* returnMetadata: true
* })
* ```
*/
override async getVectors(options: Omit<GetVectorsOptions, 'vectorBucketName' | 'indexName'>) {
return super.getVectors({
...options,
vectorBucketName: this.vectorBucketName,
indexName: this.indexName,
})
}
/**
*
* @alpha
*
* Lists vectors in this index with pagination
* Convenience method that automatically includes bucket and index names
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Listing options (bucket and index names automatically set)
* @returns Promise with response containing vectors array and pagination token or error
*
* @example List vectors with pagination
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
* const { data } = await index.listVectors({
* maxResults: 500,
* returnMetadata: true
* })
* ```
*/
override async listVectors(
options: Omit<ListVectorsOptions, 'vectorBucketName' | 'indexName'> = {}
) {
return super.listVectors({
...options,
vectorBucketName: this.vectorBucketName,
indexName: this.indexName,
})
}
/**
*
* @alpha
*
* Queries for similar vectors in this index
* Convenience method that automatically includes bucket and index names
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Query options (bucket and index names automatically set)
* @returns Promise with response containing matches array of similar vectors ordered by distance or error
*
* @example Query similar vectors
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
* const { data } = await index.queryVectors({
* queryVector: { float32: [0.1, 0.2, ...] },
* topK: 5,
* filter: { category: 'technical' },
* returnDistance: true,
* returnMetadata: true
* })
* ```
*/
override async queryVectors(
options: Omit<QueryVectorsOptions, 'vectorBucketName' | 'indexName'>
) {
return super.queryVectors({
...options,
vectorBucketName: this.vectorBucketName,
indexName: this.indexName,
})
}
/**
*
* @alpha
*
* Deletes vectors by keys from this index
* Convenience method that automatically includes bucket and index names
*
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
*
* @category Storage
* @subcategory Vector Buckets
* @param options - Deletion options (bucket and index names automatically set)
* @returns Promise with empty response on success or error
*
* @example Delete vectors by keys
* ```typescript
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
* await index.deleteVectors({
* keys: ['doc-1', 'doc-2', 'doc-3']
* })
* ```
*/
override async deleteVectors(
options: Omit<DeleteVectorsOptions, 'vectorBucketName' | 'indexName'>
) {
return super.deleteVectors({
...options,
vectorBucketName: this.vectorBucketName,
indexName: this.indexName,
})
}
}
|