This folder includes the notebooks to demonstrate vector search capabilities of Azure CosmosDb for PostgreSQL for text, documents and images.
Follow the steps to run the code locally.
-
The samples uses Conda to manage virtual environments. Create a conda environment using the azure_cosmosdb_postgresql_conda.yml file to include all necessary python dependencies.
conda env create -f azure_cosmosdb_postgresql_conda.yml
-
Create a .env file from the .env-template and populate it with all necessary keys.
-
Finally, follow the instructions mentioned here to run the code locally using VS Code - Run the Code Locally
-
Azure CosmosDb for PostgreSQL
Create resource
Vector search feature can be used with Azure CosmosDb for PostgreSQL. Azure CosmosDb for PostgreSQL can be deployed from the Azure Portal.
For IAC deployment, infrastructure folder has a bicep script to deploy the Azure CosmosDb for PostgreSQL. In the bicep script, fill out the parameters values in
params
section according to your environment, and run the following command.az deployment group create --resource-group resource_group_name --template-file azure_cosmosdb_postgresql.bicep
Enable extension
Vector search in CosmosDb for PostgreSQL is supported via the pgvector extension. And for the Azure Cosmos DB for PostgreSQL Cluster (PostgreSQL version 12 - 16) the pgvector extension is enabled by default.
Extension details - how to use Azure CosmosDb PostgreSQL extensions.
PostgreSQL extensions must be installed in your database before you can use them.
-- list the standard PostgreSQL extensions that are supported on Azure Cosmos DB for PostgreSQL. SELECT * FROM pg_available_extensions; -- install vector extension SELECT create_extension('vector'); -- To remove an extension installed this way, use drop_extension(). SELECT create_extension('vector');
-
Azure OpenAI
Azure OpenAI Service resource can be deployed using Azure Portal, Azure CLI or Azure PowerShell. Again, private endpoints can be used for Azure AI services resources to allow clients on a virtual network to securely access data over Azure Private Link.