As AI-driven applications grow in popularity, so does the need to store and query vector embeddings. PostgreSQL, a powerful open-source database, supports this with the pgvector extension. But what if you’re using Azure Database for PostgreSQL โ Flexible Server?
In this post, weโll walk through how to enable the pgvector extension on Azure and start using it for vector similarity searches.
๐ง What is pgvector?
pgvector is a PostgreSQL extension that allows you to store vector data (VECTOR(n) types) and perform similarity searches using:
- Euclidean distance (
<->) - Cosine distance (
<=>) - Inner product (
<#>)
Itโs a foundational tool for AI applications using text or image embeddings from models like OpenAI, Cohere, or Hugging Face.
โ Prerequisites
- An existing Azure Database for PostgreSQL โ Flexible Server (version 14 or higher)
- Admin access to the server (not just database-level access)
- Familiarity with Azure Portal or Azure CLI
โ๏ธ Step 1: Add pgvector to the Allowed Extensions
By default, Azure restricts which extensions can be enabled. You’ll need to explicitly allow vector (the name used in PostgreSQL for pgvector).
Option A: Azure Portal
- Go to your PostgreSQL Flexible Server in the Azure Portal.
- Navigate to Settings โ Server parameters.
- Search for the parameter:
azure.extensions. - Add
vectorto the list (comma-separated values). - Click Save.
Option B: Azure CLI
If you prefer using the CLI:
bashCopyEditaz postgres flexible-server parameter set \
--resource-group <your-resource-group> \
--server-name <your-server-name> \
--name azure.extensions \
--value vector
โ
Note: If azure.extensions already includes values, append vector with a comma.
๐งช Step 2: Create the pgvector Extension
Now that vector is allowed, connect to your database using a tool like psql or Azure Data Studio and run:
sqlCopyEditCREATE EXTENSION vector;
To verify:
sqlCopyEditSELECT * FROM pg_extension WHERE extname = 'vector';
๐งฑ Step 3: Create a Table with Vector Embeddings
Now you can create tables using the vector type.
sqlCopyEditCREATE TABLE documents (
id SERIAL PRIMARY KEY,
content TEXT,
embedding VECTOR(1536) -- Match the dimensionality of your model
);

Leave a Reply