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.

    To create a sample collection with a pre-loaded vector dataset, see Load a sample vector dataset.
  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 Empty 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

    • Dot Product

    • Euclidean

    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. If you're not
# sure what dimension to set, use whatever dimension vector your embeddings
# model produces.
collection = database.create_collection(
    "vector_test",
    dimension=5,
    metric=VectorMetric.COSINE,  # or simply "cosine"
    check_exists=False,
)
print(f"* Collection: {collection.full_name}\n")

Use the TypeScript client to create a collection.

// Schema for the collection (VectorDoc adds the $vector field)
interface Idea extends VectorDoc {
  idea: string,
}

(async function () {
  // Create a typed, vector-enabled collection. The default metric is cosine.
  // If you're not sure what dimension to set, use whatever dimension vector
  // your embeddings model produces.
  const collection = await db.createCollection<Idea>('vector_test', {
    vector: {
      dimension: 5,
      metric: 'cosine',
    },
    checkExists: false,
  });
  console.log(* Created collection ${collection.namespace}.${collection.collectionName});

Use the Java client to create a collection.

    // Create a collection. The default similarity metric is cosine. If you're
    // not sure what dimension to set, use whatever dimension vector your
    // embeddings model produces.
    Collection<Document> collection = db
            .createCollection("vector_test", 5, COSINE);
    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.

# Cleanup (if desired)
drop_result = collection.drop()
print(f"\nCleanup: {drop_result}\n")

Use the TypeScript client to delete a collection.

  // Cleanup (if desired)
  await db.dropCollection('vector_test');
  console.log('* Collection dropped.');

  // Close the client
  await client.close();

Use the Java client to delete a collection.

    // Delete the collection
    collection.drop();
    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