Google Colab
Use Google Colab with Neon for vector similarity search
Google Colab is a hosted Jupyter Notebook service that requires no setup to use and provides free access to computing resources, including GPUs and TPUs. You can use Google Colab to run python code through the browser.
This guide shows how to create a notebook in Colab, connect to a Neon database, install the pgvector
extension to enabled Neon as a vector store, and run a vector search query.
Prerequisites
To perform the steps in this guide, you require a Neon database for storing vectors. You can use the ready-to-use neondb
database or create your own. See Create a database for instructions.
Retrieve your database connection string
In the Connection Details widget on the Neon Dashboard, select a branch, a user, and the database you want to connect to. A connection string is constructed for you.
Create a notebook
In your browser, navigate to Google Colab, and click New notebook.
Alternatively, you can open a predefined Google Colab notebook for this guide by clicking the Open in Colab button below.
Connect to your database
-
In your Colab notebook, create a code block to define your database connection and create a cursor object. Replace
postgresql://[user]:[password]@[neon_hostname]/[dbname]
with the database connection string you retrieved in the previous step. -
Execute the code block (Ctrl + Enter).
-
Add a code block for testing the database connection.
-
Execute the code block (Ctrl + Enter).
Install the pgvector extension
-
Create a codeblock to install the
pgvector
extension to enable your Neon database as a vector store: -
Execute the code block (Ctrl + Enter).
Create a table and add vector data
-
Add a code block to create a table and insert data:
-
Execute the code block (Ctrl + Enter).
Query your data
-
Add a codeblock to perform a vector similarity search.
-
Execute the code block (Ctrl + Enter).
Next steps
For more information about using Neon with pgvector
, see The pgvector extension.
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more details, see Getting Support.