Cloudflare vector store
The CloudflareVector class provides vector search using Cloudflare Vectorize, a vector database service integrated with Cloudflare's edge network.
Constructor optionsDirect link to Constructor options
accountId:
apiToken:
MethodsDirect link to Methods
createIndex()Direct link to createindex
indexName:
dimension:
metric?:
upsert()Direct link to upsert
indexName:
vectors:
metadata?:
ids?:
query()Direct link to query
indexName:
queryVector:
topK?:
filter?:
includeVector?:
listIndexes()Direct link to listindexes
Returns an array of index names as strings.
describeIndex()Direct link to describeindex
indexName:
Returns:
interface IndexStats {
dimension: number
count: number
metric: 'cosine' | 'euclidean' | 'dotproduct'
}
deleteIndex()Direct link to deleteindex
indexName:
createMetadataIndex()Direct link to createmetadataindex
Creates an index on a metadata field to enable filtering.
indexName:
propertyName:
indexType:
deleteMetadataIndex()Direct link to deletemetadataindex
Removes an index from a metadata field.
indexName:
propertyName:
listMetadataIndexes()Direct link to listmetadataindexes
Lists all metadata field indexes for an index.
indexName:
updateVector()Direct link to updatevector
Updates the vector and optionally the metadata for a specific ID within an index. Vectorize has no partial-update operation, so update.vector is required. Metadata-only updates aren't supported and throw an error.
indexName:
id:
update:
deleteVector()Direct link to deletevector
Deletes a vector and its associated metadata for a specific ID within an index.
indexName:
id:
deleteVectors()Direct link to deletevectors
Deletes multiple vectors and their associated metadata by ID. Vectorize has no filtered-delete operation, so deleting by metadata filter isn't supported and throws an error.
indexName:
ids:
filter?:
Response typesDirect link to Response types
Query results are returned in this format:
interface QueryResult {
id: string
score: number
metadata: Record<string, any>
vector?: number[]
}
Error handlingDirect link to Error handling
The store throws typed errors that can be caught:
try {
await store.query({
indexName: 'index_name',
queryVector: queryVector,
})
} catch (error) {
if (error instanceof VectorStoreError) {
console.log(error.code) // 'connection_failed' | 'invalid_dimension' | etc
console.log(error.details) // Additional error context
}
}
Environment variablesDirect link to Environment variables
Required environment variables:
CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account IDCLOUDFLARE_API_TOKEN: Your Cloudflare API token with Vectorize permissions