Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Astra Vector Store

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.

Constructor OptionsDirect link to Constructor Options

token:

string
Astra DB API token

endpoint:

string
Astra DB API endpoint

keyspace?:

string
Optional keyspace name

MethodsDirect 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

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[]; // Only included if includeVector is true
}

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:

  • ASTRA_DB_TOKEN: Your Astra DB API token
  • ASTRA_DB_ENDPOINT: Your Astra DB API endpoint