Cloudflare vector store
The CloudflareVector class provides vector search using Cloudflare Vectorize, a vector database service integrated with Cloudflare's edge network.
Constructor optionsConstructor options的直接链接
accountId:
apiToken:
MethodsMethods的直接链接
createIndex()createindex的直接链接
indexName:
dimension:
metric?:
upsert()upsert的直接链接
indexName:
vectors:
metadata?:
ids?:
query()query的直接链接
indexName:
queryVector:
topK?:
filter?:
includeVector?:
listIndexes()listindexes的直接链接
Returns an array of index names as strings.
describeIndex()describeindex的直接链接
indexName:
Returns:
interface IndexStats {
dimension: number
count: number
metric: 'cosine' | 'euclidean' | 'dotproduct'
}
deleteIndex()deleteindex的直接链接
indexName:
createMetadataIndex()createmetadataindex的直接链接
Creates an index on a metadata field to enable filtering.
indexName:
propertyName:
indexType:
deleteMetadataIndex()deletemetadataindex的直接链接
Removes an index from a metadata field.
indexName:
propertyName:
listMetadataIndexes()listmetadataindexes的直接链接
Lists all metadata field indexes for an index.
indexName:
updateVector()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()deletevector的直接链接
Deletes a vector and its associated metadata for a specific ID within an index.
indexName:
id:
deleteVectors()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 typesResponse types的直接链接
Query results are returned in this format:
interface QueryResult {
id: string
score: number
metadata: Record<string, any>
vector?: number[]
}
Error handlingError handling的直接链接
The store throws MastraError instances from @mastra/core/error:
import { MastraError } from '@mastra/core/error'
try {
await store.query({
indexName: 'index_name',
queryVector: queryVector,
})
} catch (error) {
if (error instanceof MastraError) {
console.log(error.id) // 'MASTRA_VECTOR_VECTORIZE_QUERY_FAILED'
console.log(error.domain) // 'STORAGE'
console.log(error.category) // 'USER' | 'THIRD_PARTY'
console.log(error.details) // Additional error context
}
}
Environment variablesEnvironment variables的直接链接
Required environment variables:
CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account IDCLOUDFLARE_API_TOKEN: Your Cloudflare API token with Vectorize permissions