> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Astra Vector 存储 AstraVector 类使用 [DataStax Astra DB](https://www.datastax.com/products/datastax-astra) 提供 Vector 搜索。DataStax Astra DB 是一款基于 Apache Cassandra 构建的云原生无服务器数据库。 它提供企业级容量和高可用性的 Vector 搜索功能。 ## 构造函数选项 **token** (`string`): 用于访问 Astra DB 的 API token **endpoint** (`string`): Astra DB API endpoint 地址 **keyspace** (`string`): 可选的 keyspace 名称 ## 方法 ### `createIndex()` **indexName** (`string`): 要创建的索引名称 **dimension** (`number`): Vector 维度(必须与 embedding 模型匹配) **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): 相似度搜索的距离度量(dotproduct 映射到 dot\_product) (Default: `cosine`) ### `upsert()` **indexName** (`string`): 要执行 upsert 的索引名称 **vectors** (`number[][]`): embedding Vector 数组 **metadata** (`Record[]`): 每个 Vector 的元数据 **ids** (`string[]`): 可选的 Vector ID(未提供时自动生成) ### `query()` **indexName** (`string`): 要查询的索引名称 **queryVector** (`number[]`): 用于查找相似 Vector 的查询 Vector **topK** (`number`): 要返回的结果数量 (Default: `10`) **filter** (`Record`): 查询的元数据过滤条件 **includeVector** (`boolean`): 是否在结果中包含 Vector (Default: `false`) ### `listIndexes()` 返回由索引名称字符串组成的数组。 ### `describeIndex()` **indexName** (`string`): 要描述的索引名称 返回: ```typescript interface IndexStats { dimension: number count: number metric: 'cosine' | 'euclidean' | 'dotproduct' } ``` ### `deleteIndex()` **indexName** (`string`): 要删除的索引名称 ### `updateVector()` **indexName** (`string`): 包含该 Vector 的索引名称 **id** (`string`): 要更新的 Vector ID **update** (`object`): 包含 Vector 和/或元数据变更的更新对象 ### `deleteVector()` **indexName** (`string`): 包含该 Vector 的索引名称 **id** (`string`): 要删除的 Vector ID ## 响应类型 查询结果按以下格式返回: ```typescript interface QueryResult { id: string score: number metadata: Record vector?: number[] // Only included if includeVector is true } ``` ## 错误处理 该存储会抛出可捕获的类型化错误: ```typescript 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 } } ``` ## 环境变量 必需的环境变量: - `ASTRA_DB_TOKEN`:你的 Astra DB API token - `ASTRA_DB_ENDPOINT`:你的 Astra DB API endpoint ## 相关内容 - [元数据过滤器](https://mastra.zisheng.pro/reference/rag/metadata-filters)