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
-
You have created a Serverless (Vector) database or a Serverless (Non-Vector) database.
-
You have created an application token with the Organization Administrator or Database Administrator role. This is optional if using the Astra Portal.
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.
-
In the Astra Portal, go to Databases, and then select your Serverless (Vector) database.
-
Click Data Explorer.
To create a sample collection with a pre-loaded vector dataset, see Load a sample vector dataset. -
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. -
Click Create Empty Collection.
-
In the Create Collection dialog, enter a name for the new collection in the Collection Name field.
-
(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.
-
-
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.
-
In the Astra Portal, go to Databases, and then select your Serverless (Vector) database.
-
Click Data Explorer.
-
Use the Namespace dropdown to select the namespace that contains the collection you want to delete.
-
In the Collections section, click
More next to the collection you want to delete. Select Delete Collection. -
In the Delete Collection dialog, enter the name of the collection to confirm that you want to delete it.
-
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.
-
In the Astra Portal, go to Databases, and then select your Serverless (Non-Vector) database.
-
In the Overview tab, note the list of available keyspaces in the Keyspaces section. You will create your table in one of these keyspaces.
-
Click CQL Console. Wait a few seconds for the
token@cqlsh>
prompt to appear. -
Select the keyspace you want to create your table in.
use KEYSPACE_NAME;
-
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.
-
In the Astra Portal, go to Databases, and then select your Serverless (Non-Vector) database.
-
In the Overview tab, note the list of available keyspaces in the Keyspaces section. You will delete a table from one of these keyspaces.
-
Click CQL Console. Wait a few seconds for the
token@cqlsh>
prompt to appear. -
Select the keyspace containing the table you want to delete.
use KEYSPACE_NAME;
-
Get a list of all tables in this keyspace.
desc tables;
-
Delete the table and all of its data.
drop table users;
The table and all of its data is deleted permanently.