Skip to main content

Astra 向量存储

🌐 Astra Vector Store

AstraVector 类使用 DataStax Astra DB 提供向量搜索,Astra DB 是基于 Apache Cassandra 构建的云原生无服务器数据库。 它提供具有企业级可扩展性和高可用性的向量搜索功能。

🌐 The AstraVector class provides vector search using DataStax Astra DB, a cloud-native, serverless database built on Apache Cassandra. It provides vector search capabilities with enterprise-grade scalability and high availability.

构造函数选项
Direct link to 构造函数选项

🌐 Constructor Options

token:

string
Astra DB API token

endpoint:

string
Astra DB API endpoint

keyspace?:

string
Optional keyspace name

方法
Direct link to 方法

🌐 Methods

createIndex()
Direct link to createIndex()

indexName:

string
Name of the index to create

dimension:

number
Vector dimension (must match your embedding model)

metric?:

'cosine' | 'euclidean' | 'dotproduct'
= cosine
Distance metric for similarity search (maps to dot_product for dotproduct)

upsert()
Direct link to upsert()

indexName:

string
Name of the index to upsert into

vectors:

number[][]
Array of embedding vectors

metadata?:

Record<string, any>[]
Metadata for each vector

ids?:

string[]
Optional vector IDs (auto-generated if not provided)

query()
Direct link to query()

indexName:

string
Name of the index to query

queryVector:

number[]
Query vector to find similar vectors

topK?:

number
= 10
Number of results to return

filter?:

Record<string, any>
Metadata filters for the query

includeVector?:

boolean
= false
Whether to include vectors in the results

listIndexes()
Direct link to listIndexes()

返回一个由索引名称组成的字符串数组。

🌐 Returns an array of index names as strings.

describeIndex()
Direct link to describeIndex()

indexName:

string
Name of the index to describe

返回:

🌐 Returns:

interface IndexStats {
dimension: number;
count: number;
metric: "cosine" | "euclidean" | "dotproduct";
}

deleteIndex()
Direct link to deleteIndex()

indexName:

string
Name of the index to delete

updateVector()
Direct link to updateVector()

indexName:

string
Name of the index containing the vector

id:

string
ID of the vector to update

update:

object
Update object containing vector and/or metadata changes
number[]
Record<string, any>

deleteVector()
Direct link to deleteVector()

indexName:

string
Name of the index containing the vector

id:

string
ID of the vector to delete

响应类型
Direct link to 响应类型

🌐 Response Types

查询结果以此格式返回:

🌐 Query results are returned in this format:

interface QueryResult {
id: string;
score: number;
metadata: Record<string, any>;
vector?: number[]; // Only included if includeVector is true
}

错误处理
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:

  • ASTRA_DB_TOKEN:你的 Astra DB API 令牌
  • ASTRA_DB_ENDPOINT:你的 Astra DB API 端点

🌐 Related