Java Client Library for Data API 2.0.0-PREVIEW API

Overview

This client library provides a simplified way to interact with Data API with DataStax AstraDB or local deployments ( Stargate + Cassandra).

More resources can be found:

logicial overview

Installation

For Maven, add the following dependency to your pom.xml:

<dependency>
  <groupId>com.datastax.astra</groupId>
  <artifactId>astra-db-java</artifactId>
  <version>2.0.0-PREVIEW</version>
</dependency>

QuickStart

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.collections.Collection;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.collections.definition.documents.Document;
import com.datastax.astra.client.core.paging.FindIterable;
import java.util.List;
import static com.datastax.astra.client.model.Filters.eq;
import static com.datastax.astra.client.model.SimilarityMetric.cosine;

public class GettingStarted {
 public static void main(String[] args) {
  // Initializing client with a token
  DataAPIClient client = new DataAPIClient("my_token");

  // Accessing the Database through the HTTP endpoint
  Database db = client.getDatabase("http://db-region.apps.astra.datastax.com");

  // Create collection with vector support
  Collection<Document> col = db.createCollection("demo", 2, cosine);

  // Insert documents with embeddings
  col.insertMany(List.of(
   new Document("doc1").vector(new float[]{.1f, 0.2f}).append("key", "value1"),
   new Document().id("doc2").vector(new float[]{.2f, 0.4f}).append("hello", "world"),
   new Document("doc3").vector(new float[]{.5f, 0.6f}).append("key", "value1"))
  );

  // Semantic Search with metadata filtering
  FindIterable<Document> docs = col.find(
    eq("key", "value1"), // metadata filter
    new float[] {.5f, .5f},              //vector
    10);                                 // maxRecord

  // Iterate over and print your results
  for (Document doc : docs) System.out.println(doc);
 }
}
Packages
Package
Description
Entrypoint and core classes for the client.
Administration classes to manage Databases and Namespaces.
Top package to interact with Collections
Command Definitions for operating on Collections.
Objects representing cursors working with find collections commands.
Options and Inputs for Collections commands.
Outputs and DTO for Collections Commands.
Objects describing the structure of a collection.
Objects describing the structure of a Document.
Object representing the type Id for collections.
Specializations of the exceptions to work with Collections.
Core classes to interact both with Tables and Collections.
Internal technical classes to authenticate against API endpoint.
Utility classes for commands and operations.
Classes to specialize the HTTP Client.
Classes for options of the core commands.
Informations for cursor-based paging.
Classes uses to build queries with Sort and Projection.
Objects representing Vector options (vector)
Objects representing Vector Services options (vectorize)
Top package to interact with Databases and Keyspaces.
Objects representing commands against databases and keyspaces.
Object representing keyspace level returns objects.
Objects the informations of databases
Object representing the keyspaces.
Exceptions specialized checked and unchecked thrown by the client.
Top package to interact with Tables.
Command Definitions for operating on Tables.
Options and Inputs for Tables commands.
Outputs and DTO for Tables Commands.
Objects representing cursors working with find tables commands.
Objects describing the structure of a Table.
Objects representing Table Columns
Objects representing Table Indexes.
Objects representing Table Rows, like primary key.
Specializations of the exceptions to work with Tables.
Annotations Set to map objects as Row Entities.
Internal technical classes
Internal technical classes to marshall API responses
Internal technical classes to run commands against the API.
Internal technical classes to execute HTTP requests.
Utilities for reflection at runtime
Utilities classes for Serialization and Deserialization
Custom Serializers to work with Collections.
Custom Serializers applied for both tables and collections.
Custom Serializers to work with Tables
Internal technical classes for low-level utilities