mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
## What kind of change does this PR introduce? a11y fix ## What is the current behavior? Colab badge image is missing alt attribute leaving both image and the link unnamed _ screen reader users have no way to tell what the link does ## What is the new behavior? - adds `alt="Open in Colab"`, matching the text rendered inside the SVG so voice control users can activate it by its visible label ## Test 1. visit [/docs/guides/ai/google-colab](https://supabase.com/docs/guides/ai/google-colab) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Improved accessibility across AI guides and quickstarts by adding descriptive alternative text to “Open in Colab” badge images. - Updated Google Colab, LlamaIndex, face similarity, hello world, and text deduplication documentation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
114 lines
3.9 KiB
Plaintext
114 lines
3.9 KiB
Plaintext
---
|
|
id: 'ai-google-colab'
|
|
title: 'Google Colab'
|
|
description: 'Use Google Colab to manage your Supabase Vector store.'
|
|
subtitle: 'Use Google Colab to manage your Supabase Vector store.'
|
|
sidebar_label: 'Google Colab'
|
|
---
|
|
|
|
<a
|
|
className="w-64"
|
|
href="https://colab.research.google.com/github/supabase/supabase/blob/master/examples/ai/vector_hello_world.ipynb"
|
|
>
|
|
<img src="/docs/img/ai/colab-badge.svg" alt="Open in Colab" />
|
|
</a>
|
|
|
|
Google Colab is a hosted Jupyter Notebook service. It provides free access to computing resources, including GPUs and TPUs, and is well-suited to machine learning, data science, and education. We can use Colab to manage collections using [Supabase Vecs](/docs/guides/ai/vecs-python-client).
|
|
|
|
In this tutorial we'll connect to a database running on the Supabase [platform](/dashboard/). If you don't already have a database, you can create one here: [database.new](https://database.new).
|
|
|
|
## Create a new notebook
|
|
|
|
Start by visiting [colab.research.google.com](https://colab.research.google.com/). There you can create a new notebook.
|
|
|
|

|
|
|
|
## Install Vecs
|
|
|
|
We'll use the Supabase Vector client, [Vecs](/docs/guides/ai/vecs-python-client), to manage our collections.
|
|
|
|
At the top of the notebook, paste the following code and click "Execute" (`ctrl+enter`):
|
|
|
|
```py
|
|
pip install vecs
|
|
```
|
|
|
|

|
|
|
|
## Connect to your database
|
|
|
|
On your project dashboard, click [Connect](/dashboard/project/_?showConnect=true). The connection string should look like `postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres`
|
|
|
|
Create a new code block below the install block (`ctrl+m b`) and add the following code using the Postgres URI you copied above:
|
|
|
|
```py
|
|
import vecs
|
|
|
|
DB_CONNECTION = "postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres"
|
|
|
|
# create vector store client
|
|
vx = vecs.create_client(DB_CONNECTION)
|
|
```
|
|
|
|
Execute the code block (`ctrl+enter`). If no errors were returned then your connection was successful.
|
|
|
|
## Create a collection
|
|
|
|
Now we're going to create a new collection and insert some documents.
|
|
|
|
Create a new code block below the install block (`ctrl+m b`). Add the following code to the code block and execute it (`ctrl+enter`):
|
|
|
|
```py
|
|
collection = vx.get_or_create_collection(name="colab_collection", dimension=3)
|
|
|
|
collection.upsert(
|
|
vectors=[
|
|
(
|
|
"vec0", # the vector's identifier
|
|
[0.1, 0.2, 0.3], # the vector. list or np.array
|
|
{"year": 1973} # associated metadata
|
|
),
|
|
(
|
|
"vec1",
|
|
[0.7, 0.8, 0.9],
|
|
{"year": 2012}
|
|
)
|
|
]
|
|
)
|
|
```
|
|
|
|
This will create a table inside your database within the `vecs` schema, called `colab_collection`. You can view the inserted items in the [Table Editor](/dashboard/project/_/editor/), by selecting the `vecs` schema from the schema dropdown.
|
|
|
|

|
|
|
|
## Query your documents
|
|
|
|
Now we can search for documents based on their similarity. Create a new code block and execute the following code:
|
|
|
|
```py
|
|
collection.query(
|
|
query_vector=[0.4,0.5,0.6], # required
|
|
limit=5, # number of records to return
|
|
filters={}, # metadata filters
|
|
measure="cosine_distance", # distance measure to use
|
|
include_value=False, # should distance measure values be returned?
|
|
include_metadata=False, # should record metadata be returned?
|
|
)
|
|
```
|
|
|
|
You will see that this returns two documents in an array `['vec1', 'vec0']`:
|
|
|
|

|
|
|
|
It also returns a warning:
|
|
|
|
```
|
|
Query does not have a covering index for cosine_distance.
|
|
```
|
|
|
|
You can lean more about creating indexes in the [Vecs documentation](https://supabase.github.io/vecs/api/#create-an-index).
|
|
|
|
## Resources
|
|
|
|
- Vecs API: [supabase.github.io/vecs/api](https://supabase.github.io/vecs/api)
|