@@ -27,7 +27,7 @@ import { StorageVectorsClient } from '@supabase/storage-vectors-js'
2727
2828// Initialize client
2929const client = new StorageVectorsClient (' https://api.example.com' , {
30- headers: { ' Authorization' : ' Bearer YOUR_TOKEN' }
30+ headers: { Authorization: ' Bearer YOUR_TOKEN' },
3131})
3232
3333// Create a vector bucket
@@ -39,7 +39,7 @@ await bucket.createIndex({
3939 indexName: ' documents-openai' ,
4040 dataType: ' float32' ,
4141 dimension: 1536 ,
42- distanceMetric: ' cosine'
42+ distanceMetric: ' cosine' ,
4343})
4444
4545// Insert vectors
@@ -48,22 +48,22 @@ await index.putVectors({
4848 vectors: [
4949 {
5050 key: ' doc-1' ,
51- data: { float32: [0.1 , 0.2 , 0.3 , /* ...1536 dimensions */ ] },
52- metadata: { title: ' Introduction' , category: ' docs' }
53- }
54- ]
51+ data: { float32: [0.1 , 0.2 , 0.3 /* ...1536 dimensions */ ] },
52+ metadata: { title: ' Introduction' , category: ' docs' },
53+ },
54+ ],
5555})
5656
5757// Query similar vectors
5858const { data, error } = await index .queryVectors ({
59- queryVector: { float32: [0.15 , 0.25 , 0.35 , /* ...1536 dimensions */ ] },
59+ queryVector: { float32: [0.15 , 0.25 , 0.35 /* ...1536 dimensions */ ] },
6060 topK: 5 ,
6161 returnDistance: true ,
62- returnMetadata: true
62+ returnMetadata: true ,
6363})
6464
6565if (data ) {
66- data .matches .forEach (match => {
66+ data .matches .forEach (( match ) => {
6767 console .log (` ${match .key }: distance=${match .distance } ` )
6868 console .log (' Metadata:' , match .metadata )
6969 })
@@ -79,6 +79,7 @@ const client = new StorageVectorsClient(url, options?)
7979` ` `
8080
8181**Options:**
82+
8283- ` headers ?: Record <string , string >` - Custom HTTP headers (e.g., Authorization)
8384- ` fetch ?: Fetch ` - Custom fetch implementation
8485
@@ -104,7 +105,7 @@ console.log('Created at:', new Date(data.vectorBucket.creationTime! * 1000))
104105` ` ` typescript
105106const { data , error } = await client .listVectorBuckets ({
106107 prefix: ' prod-' ,
107- maxResults: 100
108+ maxResults: 100 ,
108109})
109110
110111// Pagination
@@ -135,12 +136,13 @@ await bucket.createIndex({
135136 dimension: 1536 ,
136137 distanceMetric: ' cosine' , // 'cosine' | 'euclidean' | 'dotproduct'
137138 metadataConfiguration: {
138- nonFilterableMetadataKeys: [' raw_text' , ' internal_id' ]
139- }
139+ nonFilterableMetadataKeys: [' raw_text' , ' internal_id' ],
140+ },
140141})
141142` ` `
142143
143144**Distance Metrics:**
145+
144146- ` cosine ` - Cosine similarity (normalized dot product)
145147- ` euclidean ` - Euclidean distance (L2 norm)
146148- ` dotproduct ` - Dot product similarity
@@ -158,7 +160,7 @@ console.log('Distance metric:', data?.index.distanceMetric)
158160` ` ` typescript
159161const { data , error } = await bucket .listIndexes ({
160162 prefix: ' documents-' ,
161- maxResults: 100
163+ maxResults: 100 ,
162164})
163165` ` `
164166
@@ -180,19 +182,24 @@ await index.putVectors({
180182 vectors: [
181183 {
182184 key: ' unique-id-1' ,
183- data: { float32: [/* 1536 numbers */ ] },
185+ data: {
186+ float32: [
187+ /* 1536 numbers */
188+ ],
189+ },
184190 metadata: {
185191 title: ' Document Title' ,
186192 category: ' technical' ,
187- page: 1
188- }
193+ page: 1 ,
194+ },
189195 },
190196 // ... up to 500 vectors per request
191- ]
197+ ],
192198})
193199` ` `
194200
195201**Limitations:**
202+
196203- 1-500 vectors per request
197204- Vectors must match index dimension
198205- Keys must be unique within index
@@ -202,11 +209,11 @@ await index.putVectors({
202209` ` ` typescript
203210const { data , error } = await index .getVectors ({
204211 keys: [' doc-1' , ' doc-2' , ' doc-3' ],
205- returnData: true , // Include embeddings (requires permission)
206- returnMetadata: true // Include metadata (requires permission)
212+ returnData: true , // Include embeddings (requires permission)
213+ returnMetadata: true , // Include metadata (requires permission)
207214})
208215
209- data ?.vectors .forEach (v => {
216+ data ?.vectors .forEach (( v ) => {
210217 console .log (v .key , v .metadata )
211218})
212219` ` `
@@ -215,18 +222,22 @@ data?.vectors.forEach(v => {
215222
216223` ` ` typescript
217224const { data , error } = await index .queryVectors ({
218- queryVector: { float32: [/* 1536 numbers */ ] },
225+ queryVector: {
226+ float32: [
227+ /* 1536 numbers */
228+ ],
229+ },
219230 topK: 10 ,
220231 filter: {
221232 category: ' technical' ,
222- published: true
233+ published: true ,
223234 },
224235 returnDistance: true ,
225- returnMetadata: true
236+ returnMetadata: true ,
226237})
227238
228239// Results ordered by similarity
229- data ?.matches .forEach (match => {
240+ data ?.matches .forEach (( match ) => {
230241 console .log (` ${match .key }: distance=${match .distance } ` )
231242})
232243` ` `
243254 const { data } = await index.listVectors({
244255 maxResults : 500 ,
245256 nextToken ,
246- returnMetadata : true
257+ returnMetadata : true ,
247258 })
248259
249260 console.log(' Batch:' , data?.vectors.length)
@@ -255,7 +266,7 @@ const workers = [0, 1, 2, 3].map(async (segmentIndex) => {
255266 const { data } = await index .listVectors ({
256267 segmentCount: 4 ,
257268 segmentIndex ,
258- returnMetadata: true
269+ returnMetadata: true ,
259270 })
260271 return data ?.vectors || []
261272})
@@ -265,6 +276,7 @@ const allVectors = results.flat()
265276` ` `
266277
267278**Limitations:**
279+
268280- ` maxResults ` : 1-1000 (default: 500)
269281- ` segmentCount ` : 1-16
270282- Response may be limited by 1MB size
@@ -273,7 +285,7 @@ const allVectors = results.flat()
273285
274286` ` ` typescript
275287await index .deleteVectors ({
276- keys: [' doc-1' , ' doc-2' , ' doc-3' ]
288+ keys: [' doc-1' , ' doc-2' , ' doc-3' ],
277289 // ... up to 500 keys per request
278290})
279291` ` `
@@ -294,14 +306,14 @@ if (error) {
294306
295307### Error Codes
296308
297- | Code | HTTP | Description |
298- |------| ------| -------------|
299- | ` InternalError ` | 500 | Internal server error |
300- | ` S3VectorConflictException ` | 409 | Resource already exists |
301- | ` S3VectorNotFoundException ` | 404 | Resource not found |
302- | ` S3VectorBucketNotEmpty ` | 400 | Bucket contains indexes |
303- | ` S3VectorMaxBucketsExceeded ` | 400 | Bucket quota exceeded |
304- | ` S3VectorMaxIndexesExceeded ` | 400 | Index quota exceeded |
309+ | Code | HTTP | Description |
310+ | ---------------------------- | ---- | ----------------------- |
311+ | ` InternalError ` | 500 | Internal server error |
312+ | ` S3VectorConflictException ` | 409 | Resource already exists |
313+ | ` S3VectorNotFoundException ` | 404 | Resource not found |
314+ | ` S3VectorBucketNotEmpty ` | 400 | Bucket contains indexes |
315+ | ` S3VectorMaxBucketsExceeded ` | 400 | Bucket quota exceeded |
316+ | ` S3VectorMaxIndexesExceeded ` | 400 | Index quota exceeded |
305317
306318### Throwing Errors
307319
@@ -330,13 +342,19 @@ Create scoped clients for cleaner code:
330342` ` ` typescript
331343// Bucket-scoped operations
332344const bucket = client .bucket (' embeddings-prod' )
333- await bucket .createIndex ({ /* ... */ })
345+ await bucket .createIndex ({
346+ /* ... */
347+ })
334348await bucket .listIndexes ()
335349
336350// Index-scoped operations
337351const index = bucket .index (' documents-openai' )
338- await index .putVectors ({ /* ... */ })
339- await index .queryVectors ({ /* ... */ })
352+ await index .putVectors ({
353+ /* ... */
354+ })
355+ await index .queryVectors ({
356+ /* ... */
357+ })
340358` ` `
341359
342360### Custom Fetch
@@ -348,7 +366,9 @@ import { StorageVectorsClient } from '@supabase/storage-vectors-js'
348366
349367const client = new StorageVectorsClient (url , {
350368 fetch: customFetch ,
351- headers: { /* ... */ }
369+ headers: {
370+ /* ... */
371+ },
352372})
353373` ` `
354374
@@ -375,7 +395,7 @@ Ensure vectors are properly normalized to float32:
375395` ` ` typescript
376396import { normalizeToFloat32 } from ' @supabase/storage-vectors-js'
377397
378- const vector = normalizeToFloat32 ([0.1 , 0.2 , 0.3 , /* ... */ ])
398+ const vector = normalizeToFloat32 ([0.1 , 0.2 , 0.3 /* ... */ ])
379399` ` `
380400
381401## Type Definitions
@@ -392,11 +412,11 @@ import type {
392412 VectorMetadata ,
393413 DistanceMetric ,
394414 ApiResponse ,
395- StorageVectorsError
415+ StorageVectorsError ,
396416} from ' @supabase/storage-vectors-js'
397417` ` `
398418
399419## Requirements
400420
401421- Node.js 14+ or modern browser with fetch support
402- - TypeScript 4.5+ (for type checking)
422+ - TypeScript 4.5+ (for type checking)
0 commit comments