Azure Data Studio Notebooks
Use Azure Data Studio Notebooks with Neon for vector similarity search
A Jupyter Notebook is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. Azure Data Studio supports Jupyter Notebooks, enabling users to combine SQL queries, Python code, and markdown text in a single interactive document.
This guide describes how to create a new python notebook in Azure Data Studio, connect to a Neon database, install the pgvector
extension to enable Neon as a vector store, and run a vector search query.
Prerequisites
To perform the steps in this guide, you will require:
-
Azure Data Studio - Download the latest version of Azure Data Studio for your operating system here.
-
A Neon account - If you do not have one, sign up at Neon. Your Neon project comes with a ready-to-use Postgres database named
neondb
. You can use it, or create your own by following the instructions here.
Retrieve your Neon 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
- Go to the File menu for Azure Data Studio and select New Notebook.
- Select Python 3 for the Kernel and set Attach to to "localhost" where it can access your Python installation.
You can save the notebook using the Save or Save as... command from the File menu.
Configure Python for Notebooks
The first time you connect to the Python kernel in a notebook, the Configure Python for Notebooks page is displayed. You can select either:
- New Python installation to install a new copy of Python for Azure Data Studio, or
- Use existing Python installation to specify the path to an existing Python installation for Azure Data Studio to use
To view the location and version of the active Python kernel, you can create a code cell and run the following Python commands:
Running a code cell
You can create cells containing Python code that you can run in place by clicking the Run cell button (the round blue arrow) to the left of the cell. The results are shown in the notebook after the cell finishes running. In the pgvector
example that follows, you'll add and execute several code cells.
pgvector example
After you've set up Azure Data Studio and have created a notebook, you can use the following basic example to get started with Neon and pgvector
.
Install the psycopg driver
psycopg is a popular Postgres database adapter for the Python programming language. It allows Python applications to connect to and interact with Postgres databases.
Install the psycopg
adapter by adding and executing the following code cell:
Connect to your database
-
In your notebook, create a code block to define your Neon database connection and create a cursor object. Replace
postgres://[user]:[password]@[neon_hostname]/[dbname]
with the database connection string you retrieved previously. -
Execute the code block.
-
Add a code block for testing the database connection.
-
Execute the code block.
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.
Create a table and add vector data
-
Add a code block to create a table and insert data:
-
Execute the code block.
Query your data
-
Add a codeblock to perform a vector similarity search.
-
Execute the code block.
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 detail, see Getting Support.
Last updated on