Tutorial
Tutorial-specific formatting
- Special page attributes
-
Add the following attributes to the page header to automatically add the corresponding heading details to the top of the page.
:page-skill-level: Beginner :page-time-commitment: 15 min :page-colab-link: https://colab.research.google.com/
- Automatic steps
-
Add the
.step
role to a section title to prefix it with an auto-incrementing step number. The number does not appear in the auto-generated anchor link or the table of contents.[.step] === Install the Python SDK and open a Python REPL. ... [.step] === Connect to Astra and create a database.
- Step reset
-
Add the
.step-reset
role to a section title to reset the step number.[.step-reset] === This title will now be prefixed with "1." regardless of order.
Objective
Learn how to create a new database, connect to your database, load a set of vector embeddings, and perform a similarity search to find vectors that are close to the one in your query.
Prerequisites
To get started, ensure you have an active Astra account with the requisite permissions.
Connect to Astra and create a database
import astra_vector
# Authenticate to the SaaS database
api_key = 'your_api_key'
client = astra_vector.Client(api_key)
# Create a new database
database_name = 'my_vector_database'
client.create_database(database_name)
# Connect to the database
db = client.connect(database_name)
# Create a new table for vectors
table_name = 'vector_data'
db.create_table(table_name)
Core steps
Prepare and ingest data
# Load sample vector data
sample_vectors = [
{'id': 1, 'vector': [0.1, 0.2, 0.3]},
{'id': 2, 'vector': [0.4, 0.5, 0.7]}
]
for data in sample_vectors:
db.insert_record(table_name, data)
Conclusion
In this tutorial, you learned how to:
-
Create a new database
-
Connect to your database
-
Load a set of vector embeddings
-
Perform a similarity search to find vectors that are close to the one in your query
You’re well on your way to becoming an Astra Vector expert!
Next steps
-
Grasp the basics Tutorial
Before diving deep, ensure a solid understanding of foundational concepts surrounding vector databases. Delve into embeddings, the nature of high-dimensional data, and their profound impact on machine learning processes.
-
Installation Guide
Before diving deep, ensure a solid understanding of foundational concepts surrounding vector databases. Delve into embeddings, the nature of high-dimensional data, and their profound impact on machine learning processes.
-
Ingest and store vector data Tutorial
Before diving deep, ensure a solid understanding of foundational concepts surrounding vector databases. Delve into embeddings, the nature of high-dimensional data, and their profound impact on machine learning processes.