|
| 1 | += Quickstart |
| 2 | +:navtitle: Quickstart |
| 3 | +:page-layout: tutorial |
| 4 | +:page-colab-link: https://colab.research.google.com/github/CassioML/cassio-website/blob/main/docs/frameworks/langchain/.colab/colab_qa-basic.ipynb |
| 5 | +:page-time-commitment: 15 min |
| 6 | +:page-skill-level: Beginner |
| 7 | +:astra-link: https://astra.datastax.com |
| 8 | +:astra-nodejs-link: https://docs.datastax.com/en/astra-serverless/docs/develop/sdks/rest-nodejs-client.html |
| 9 | +:astra-json-link: https://docs.datastax.com/en/astra-serverless/docs/develop/dev-with-json.html |
| 10 | +:keywords: Machine Learning Frameworks, Embeding Services, Astra, SDK |
| 11 | + |
| 12 | +== Objective |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +image::ROOT:template-examples/quickstart-overview.png["Tutorial overview"] |
| 17 | + |
| 18 | +== Prerequisites |
| 19 | + |
| 20 | +To get started, ensure you have an {astra-link}[active Astra account] with the requisite permissions. |
| 21 | + |
| 22 | +=== [.step]#1# Install the Python SDK and open a Python REPL. |
| 23 | + |
| 24 | +[source,shell] |
| 25 | +---- |
| 26 | +pip install astra-vector |
| 27 | +---- |
| 28 | + |
| 29 | +[source,shell] |
| 30 | +---- |
| 31 | +python |
| 32 | +---- |
| 33 | + |
| 34 | +[TIP] |
| 35 | +==== |
| 36 | +Additional clients, such as {astra-nodejs-link}[Node.js] and {astra-json-link}[JSON API], are available. |
| 37 | +==== |
| 38 | + |
| 39 | +=== [.step]#2# Connect to Astra and create a database. |
| 40 | + |
| 41 | +[source,python] |
| 42 | +---- |
| 43 | +import astra_vector |
| 44 | +
|
| 45 | +# Authenticate to the SaaS database |
| 46 | +api_key = 'your_api_key' |
| 47 | +client = astra_vector.Client(api_key) |
| 48 | +
|
| 49 | +# Create a new database |
| 50 | +database_name = 'my_vector_database' |
| 51 | +client.create_database(database_name) |
| 52 | +
|
| 53 | +# Connect to the database |
| 54 | +db = client.connect(database_name) |
| 55 | +
|
| 56 | +# Create a new table for vectors |
| 57 | +table_name = 'vector_data' |
| 58 | +db.create_table(table_name) |
| 59 | +---- |
| 60 | + |
| 61 | +== Core steps |
| 62 | + |
| 63 | +=== [.step]#3# Prepare and ingest data. |
| 64 | + |
| 65 | +[source,python] |
| 66 | +---- |
| 67 | +# Load sample vector data |
| 68 | +sample_vectors = [ |
| 69 | + {'id': 1, 'vector': [0.1, 0.2, 0.3]}, |
| 70 | + {'id': 2, 'vector': [0.4, 0.5, 0.7]} |
| 71 | +] |
| 72 | +
|
| 73 | +for data in sample_vectors: |
| 74 | + db.insert_record(table_name, data) |
| 75 | +---- |
| 76 | + |
| 77 | +=== [.step]#4# Perform a similarity search. |
| 78 | + |
| 79 | +[source,python] |
| 80 | +---- |
| 81 | +# Run a similarity search |
| 82 | +query_vector = [0.2, 0.3, 0.4] |
| 83 | +results = db.similarity_search(table_name, query_vector, k=5) |
| 84 | +---- |
| 85 | + |
| 86 | +=== [.step]#5# Show the results. |
| 87 | + |
| 88 | +[source,python] |
| 89 | +---- |
| 90 | +# Similarity search results |
| 91 | +for result in results: |
| 92 | + print(f"ID: {result['id']}, Similarity Score: {result['score']}") |
| 93 | +---- |
| 94 | + |
| 95 | +== Cleanup |
| 96 | + |
| 97 | +=== [.step]#6# Delete all resources. |
| 98 | + |
| 99 | +[source,python] |
| 100 | +---- |
| 101 | +# Delete the table |
| 102 | +db.delete_table(table_name) |
| 103 | +print(f"Table '{table_name}' deleted.") |
| 104 | +
|
| 105 | +# Delete the database |
| 106 | +client.delete_database(database_name) |
| 107 | +print(f"Database '{database_name}' deleted.") |
| 108 | +---- |
| 109 | + |
| 110 | +== Conclusion |
| 111 | + |
| 112 | +In this tutorial, you learned how to: |
| 113 | + |
| 114 | +* [*] Create a new database |
| 115 | +* [*] Connect to your database |
| 116 | +* [*] Load a set of vector embeddings |
| 117 | +* [*] Perform a similarity search to find vectors that are close to the one in your query |
| 118 | + |
| 119 | +You're well on your way to becoming an Astra Vector expert! |
| 120 | + |
| 121 | +[.header-noline] |
| 122 | +== Next Steps |
| 123 | + |
| 124 | +[.ds-card] |
| 125 | +-- |
| 126 | +[unstyled] |
| 127 | +* https://example.com[Grasp the basics] [.material-icons]#auto_stories# Tutorial |
| 128 | ++ |
| 129 | +Before diving deep, ensure a solid understanding of foundational concepts surrounding vector databases. |
| 130 | +Delve into embeddings, the nature of high-dimensional data, and their profound impact on machine learning processes. |
| 131 | +-- |
| 132 | + |
| 133 | +[.ds-card] |
| 134 | +-- |
| 135 | +[unstyled.guide] |
| 136 | +* https://example.com[Installation] [.material-icons]#fact_check# Guide |
| 137 | ++ |
| 138 | +Before diving deep, ensure a solid understanding of foundational concepts surrounding vector databases. |
| 139 | +Delve into embeddings, the nature of high-dimensional data, and their profound impact on machine learning processes. |
| 140 | +-- |
| 141 | + |
| 142 | +[.ds-card] |
| 143 | +-- |
| 144 | +[unstyled] |
| 145 | +* https://example.com[Ingest and store vector data] [.material-icons]#auto_stories# Tutorial |
| 146 | ++ |
| 147 | +Before diving deep, ensure a solid understanding of foundational concepts surrounding vector databases. |
| 148 | +Delve into embeddings, the nature of high-dimensional data, and their profound impact on machine learning processes. |
| 149 | +-- |
0 commit comments