Cloudflare 向量存储
🌐 Cloudflare Vector Store
CloudflareVector 类使用 Cloudflare Vectorize 提供向量搜索,这是一种与 Cloudflare 边缘网络集成的向量数据库服务。
🌐 The CloudflareVector class provides vector search using Cloudflare Vectorize, a vector database service integrated with Cloudflare's edge network.
构造函数选项Direct link to 构造函数选项
🌐 Constructor Options
accountId:
apiToken:
方法Direct 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()
更新索引中某个特定 ID 的向量或元数据。
🌐 Updates a vector or metadata for a specific ID within an index.
indexName:
id:
update:
deleteVector()Direct link to deleteVector()
删除索引中某个特定 ID 的向量及其相关元数据。
🌐 Deletes a vector and its associated metadata for a specific ID within an index.
indexName:
id:
响应类型Direct link to 响应类型
🌐 Response Types
查询结果以此格式返回:
🌐 Query results are returned in this format:
interface QueryResult {
id: string;
score: number;
metadata: Record<string, any>;
vector?: number[];
}
错误处理Direct 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
}
}
环境变量Direct link to 环境变量
🌐 Environment Variables
所需的环境变量:
🌐 Required environment variables:
CLOUDFLARE_ACCOUNT_ID:你的 Cloudflare 账户 IDCLOUDFLARE_API_TOKEN:具有 Vectorize 权限的 Cloudflare API 令牌
相关Direct link to 相关
🌐 Related