Manage collections and tables

A collection is a set of structured vector data. A table is the same but for non-vector data. You can use collections with a Serverless (Vector) database and tables with a Serverless (Non-Vector) database.

Prerequisites

Create a collection

Before you can load vector data, you must have an existing collection.

You cannot create a collection or load data to a specific region using the Astra Portal. You must use the initial region you selected when you created the database.

Here’s how to create an empty collection:

  • Astra Portal

  • Python

  • TypeScript

  • Java

Use the Astra Portal to create a collection.

  1. In the Astra Portal, go to Databases, and then select your Serverless (Vector) database.

  2. Click Data Explorer.

  3. Use the Namespace dropdown to select the namespace where you want to create the collection.

    You can use the default_keyspace namespace or create a new namespace.
  4. Click Create Collection.

  5. In the Create Collection dialog, enter a name for the new collection in the Collection Name field.

  6. (Optional) Enable vectors.

    The Enable Vector toggle determines whether the resulting collection is vector-enabled.

    The displayed fields are:

    Dimensions

    The length of the vector in your dataset. Clicking this field reveals a list of common embedding models and their dimensions. You can also enter a custom dimension.

    Similarity Metric

    The criterion used by your embedding model to compare vectors.

    The available metrics are:

    • Cosine Similarity

    • Dot Product

    • Euclidean Distance

    To learn more about similarity metrics, see Intro to vector databases.

    If you turn off Enable Vector, the resulting collection is not vector-enabled. You cannot add vector data to a non-vector collection.

  7. Click Create Collection.

    If you get a Collection Limit Reached message, you’ll need to delete a collection before you can create a new one.

An empty collection appears in the list of collections. You can now load data into this collection.

Use the Python client to create a collection.

# Create a collection. The default similarity metric is "cosine".
collection = db.create_collection("vector_test", dimension=5, metric="cosine")
print(collection)

Use the TypeScript client to create a collection.

  // Create a collection. The default similarity metric is "cosine".
  await db.createCollection(
    "vector_test",
    {
      "vector": {
        "dimension": 5,
        "metric": "cosine"
      }
    }
  );
  const collection = await db.collection("vector_test");
  console.log(collection);

Use the Java client to create a collection.

    // Create a collection. The default similarity metric is cosine.
    CollectionDefinition colDefinition = CollectionDefinition.builder()
        .name("vector_test")
        .vector(5, SimilarityMetric.cosine)
        .build();
    db.createCollection(colDefinition);
    AstraDBCollection collection = db.collection("vector_test");
    System.out.println("Created a collection");

Delete a collection

You can delete a collection that you’re not using. All of the data in the collection is permanently deleted.

  • Astra Portal

  • Python

  • TypeScript

  • Java

Use the Astra Portal to delete a collection.

  1. In the Astra Portal, go to Databases, and then select your Serverless (Vector) database.

  2. Click Data Explorer.

  3. Use the Namespace dropdown to select the namespace that contains the collection you want to delete.

  4. In the Collections section, click more_vert More next to the collection you want to delete. Select Delete Collection.

  5. In the Delete Collection dialog, enter the name of the collection to confirm that you want to delete it.

  6. Click Delete Collection.

The collection and all of its data is deleted permanently.

Use the Python client to delete a collection.

# Delete the collection
res = db.delete_collection(collection_name="vector_test")
print(res)

Use the TypeScript client to delete a collection.

  // Delete the collection
  const response = await db.dropCollection("vector_test");
  console.log(response);

Use the Java client to delete a collection.

    // Delete the collection
    db.deleteCollection("vector_test");
    System.out.println("Deleted the collection");

Create a table

Here’s how to create an empty table using the Astra Portal.

  1. In the Astra Portal, go to Databases, and then select your Serverless (Non-Vector) database.

  2. In the Overview tab, note the list of available keyspaces in the Keyspaces section. You will create your table in one of these keyspaces.

  3. Click CQL Console. Wait a few seconds for the token@cqlsh> prompt to appear.

  4. Select the keyspace you want to create your table in.

    use KEYSPACE_NAME;
  5. Create your table.

    CREATE TABLE users (
        firstname text,
        lastname text,
        email text,
        "favorite color" text,
        PRIMARY KEY (firstname, lastname)
    ) WITH CLUSTERING ORDER BY (lastname ASC);
    For more examples of CQL usage, see Developing with CQL API.

You can now load data into this table.

Delete a table

You can delete a table that you’re not using. All of the data in the table is deleted permanently.

  1. In the Astra Portal, go to Databases, and then select your Serverless (Non-Vector) database.

  2. In the Overview tab, note the list of available keyspaces in the Keyspaces section. You will delete a table from one of these keyspaces.

  3. Click CQL Console. Wait a few seconds for the token@cqlsh> prompt to appear.

  4. Select the keyspace containing the table you want to delete.

    use KEYSPACE_NAME;
  5. Get a list of all tables in this keyspace.

    desc tables;
  6. Delete the table and all of its data.

    drop table users;

The table and all of its data is deleted permanently.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com