Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Adds the colab guide

Copple15703b5f8067
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index 5bdd1b7a41d..754707ba5dd 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -919,6 +919,10 @@ export const ai: NavMenuConstant = {
name: 'Hugging Face',
url: '/guides/ai/hugging-face',
},
+ {
+ name: 'Google Colab',
+ url: '/guides/ai/google-colab',
+ },
],
},
],
diff --git a/apps/docs/pages/guides/ai/google-colab.mdx b/apps/docs/pages/guides/ai/google-colab.mdx
new file mode 100644
index 00000000000..f8dff9aa064
--- /dev/null
+++ b/apps/docs/pages/guides/ai/google-colab.mdx
@@ -0,0 +1,112 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ 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: 'Langchain',
+}
+
+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/ai/vecs-python-client).
+
+In this tutorial we'll connect to a database running on the Supabase [platform](https://app.supabase.com/). 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.
+
+![Google Colab new notebook](/docs/img/ai/google-colab/colab-new.png)
+
+## 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 add the notebook paste the following code and hit the "execute" button (`ctrl+enter`):
+
+```py
+pip install vecs
+```
+
+![Install vecs](/docs/img/ai/google-colab/install-vecs.png)
+
+## Connect to your database
+
+Find the Postgres connection string for your Supabase project in the [database settings](https://app.supabase.com/_/settings/database) of the dashboard. Copy the "URI" format, which should look something like `postgresql:/postgres:<password>@<host>:5432/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 = "postgresql://postgres:<password>@<host>:5432/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.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](https://app.supabase.com/project/_/editor/), by selecting the `vecs` schema from the schema dropdown.
+
+![Colab documents](/docs/img/ai/google-colab/colab-documents.png)
+
+## 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']`:
+
+![Colab results](/docs/img/ai/google-colab/colab-results.png)
+
+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)
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+
+export default Page
diff --git a/apps/docs/public/img/ai/google-colab/colab-documents.png b/apps/docs/public/img/ai/google-colab/colab-documents.png
new file mode 100644
index 00000000000..95f995ea971
Binary files /dev/null and b/apps/docs/public/img/ai/google-colab/colab-documents.png differ
diff --git a/apps/docs/public/img/ai/google-colab/colab-new.png b/apps/docs/public/img/ai/google-colab/colab-new.png
new file mode 100644
index 00000000000..19d7c09ecda
Binary files /dev/null and b/apps/docs/public/img/ai/google-colab/colab-new.png differ
diff --git a/apps/docs/public/img/ai/google-colab/colab-results.png b/apps/docs/public/img/ai/google-colab/colab-results.png
new file mode 100644
index 00000000000..6fc50dc5818
Binary files /dev/null and b/apps/docs/public/img/ai/google-colab/colab-results.png differ
diff --git a/apps/docs/public/img/ai/google-colab/install-vecs.png b/apps/docs/public/img/ai/google-colab/install-vecs.png
new file mode 100644
index 00000000000..0126e0e2fa0
Binary files /dev/null and b/apps/docs/public/img/ai/google-colab/install-vecs.png differ