Skip to main content

Overview

DataStax Astra DB is a cloud-native vector database built on Apache Cassandra. It provides serverless vector search with automatic scaling and multi-region support.

Installation

Basic Usage

Constructor Options

string
required
Astra DB application token (defaults to ASTRA_DB_APPLICATION_TOKEN env var)
string
required
Astra DB API endpoint (defaults to ASTRA_DB_API_ENDPOINT env var)
string
default:"default_keyspace"
Astra DB namespace/keyspace (defaults to ASTRA_DB_NAMESPACE env var)
string
default:"_id"
Field name for storing document IDs
string
default:"content"
Field name for storing text content

Configuration

Environment Variables

Getting Astra DB Credentials

  1. Sign up at Astra DB
  2. Create a new database
  3. Generate an application token
  4. Copy the API endpoint from the database overview

Collection Management

Create and Connect

Connect to Existing Collection

Important

You must call either connect() or createAndConnect() before adding, deleting, or querying documents.

Querying

Basic Query

Metadata Filtering

Supported Filter Operators

Astra DB supports:
  • EQ - Equal
  • NE - Not equal
  • GT - Greater than
  • LT - Less than
  • GTE - Greater than or equal
  • LTE - Less than or equal
  • IN - Value in array
  • NIN - Value not in array
  • IS_EMPTY - Array is empty (size = 0)

Managing Data

Add Documents

Delete by Document ID

Access Astra DB Client

Complete Example

Distance Metrics

Astra DB supports different similarity metrics:

Multi-Region Support

Astra DB automatically replicates data across multiple regions:

Namespaces (Keyspaces)

Organize collections into namespaces:

Best Practices

  1. Use appropriate metric: Cosine for normalized vectors, dot_product for speed
  2. Organize with namespaces: Separate environments or use cases
  3. Monitor usage: Track API requests and storage in Astra console
  4. Handle errors: Implement retry logic for transient failures
  5. Batch operations: Insert multiple documents at once for efficiency
  6. Use serverless: Automatic scaling eliminates capacity planning

Troubleshooting

Authentication Failed

Verify your credentials:

Collection Not Found

Create the collection first:

Dimension Mismatch

Ensure embedding dimensions match collection configuration:

See Also