Java Client Library for Data API 1.4.0 API


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


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



import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.Collection;
import com.datastax.astra.client.Database;
import com.datastax.astra.client.model.Document;
import com.datastax.astra.client.model.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("");

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

  // Insert documents with embeddings
   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);
Entrypoint and core classes for the client.
Administration classes to manage Databases and Namespaces.
Internal technical classes to authenticate against API endpoint.
Exceptions specialized checked and unchecked thrown by the client.
Domain model classes with Requests, Results, Options and Iterables.
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.
Internal technical classes for low-level utilities