You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for PgVector extension to postgres resource #3052
PGVector is a popular extension for exposing vector search capabilities in a postgres database. Today eShop hack around this by using code like this
We should build a more first class API for adding/enabling PGVector on the postgres resource.
Reacted by Morgan Lyddon, Devis Lucato, manuel-bespokelabs, Quinn Karpowitz, Dmiller, Paul Irwin, Luis von der Eltz, Torben Sudau, Matthew-Hope Eland, Berkan Sasmaz and 4 more
But if you're using a non-ef database connector, say the memory pipeline in Semantic Kernel, you need to add the extension another way. My approach is to bind mount a SQL script into the init path of the Postgres container (see this code).
From a deployment perspective, we need to then ensure that we're surfacing up the metadata required for the IaC provider, with Azure and AWS we need to enable the right feature on the DB resource being deployed rather than using the container image.
From a deployment perspective, we need to then ensure that we're surfacing up the metadata required for the IaC provider, with Azure and AWS we need to enable the right feature on the DB resource being deployed rather than using the container image.
That should be as simple as representing it in the model is some first class way. The azure/aws postgres extension method should be able to look at the model the glean that it needs the pgvector extension (I'm not sure we need to make this super generic until we have more concrete use cases).
You still need to install the extension in the Postgres server - locally we have to use the pgvector Docker image, whereas databases like Azure PostgreSQL have the extension installed, then we have to enable it on the database using the CREATE EXTENSION vector; (since you have to opt-in which database(s) on the server have the extension supported).
So this was the closest issue I could find to it, but it looks like we also need the ability to set Microsoft.DBforPostgreSQL/flexibleServers/configurations as a part of the postgres deployment for many extensions (ex. citext) otherwise you can't use CREATE EXTENSION at all.
Is there any way to set this property currently?
EF Core can already do CREATE EXTENSION as a part of a migration with ngpsql, but you still have to enable it on the extensions on the DB server in azure.
Not sure we want additonal bicep, I'd rather us expand the Azure.Provisioning libraries to support setting this .
Yes, that might be a better option, but presently (or at least, 4 weeks ago when I looked before going on leave 🤣) there isn't support for that in the SDK to do it.
I wonder if we should add this to the Community Toolkit extensions pack to at least configure the extension - running the SQL is a bit more complicated as it really depends on how the database is being "provisioned"
Agree, would be nice if this worked OOB for both aspire run and aspire deploy - stumbled on this based on the exciting Microsoft.Extensions.DataInjestion that sits on top of Microsoft.Extensions.VectorData https://www.youtube.com/watch?v=pQivzi4n6jM
Activity
aaronpowell commentedon Mar 22, 2024
It's a little more complex than, as you need to add the
vectorextension to the database that you're going to be storing the vectors in.I believe that eShop does it here: https://github.com/dotnet/eShop/blob/72445fd19c85e46420a4ae4c33eb46245c970c9b/src/Catalog.API/Infrastructure/Migrations/20231009153249_Initial.cs#L15
But if you're using a non-ef database connector, say the memory pipeline in Semantic Kernel, you need to add the extension another way. My approach is to bind mount a SQL script into the init path of the Postgres container (see this code).
From a deployment perspective, we need to then ensure that we're surfacing up the metadata required for the IaC provider, with Azure and AWS we need to enable the right feature on the DB resource being deployed rather than using the container image.
davidfowl commentedon Mar 22, 2024
Isn't that automagic when you use https://github.com/dotnet/eShop/blob/72445fd19c85e46420a4ae4c33eb46245c970c9b/src/Catalog.API/Extensions/Extensions.cs#L11?
That should be as simple as representing it in the model is some first class way. The azure/aws postgres extension method should be able to look at the model the glean that it needs the pgvector extension (I'm not sure we need to make this super generic until we have more concrete use cases).
aaronpowell commentedon Mar 23, 2024
No, that extension method is used to enable the Vector extension in the npgsql driver for .NET - https://github.com/pgvector/pgvector-dotnet/blob/master/src/Pgvector/Npgsql/VectorExtensions.cs#L10
You still need to install the extension in the Postgres server - locally we have to use the pgvector Docker image, whereas databases like Azure PostgreSQL have the extension installed, then we have to enable it on the database using the
CREATE EXTENSION vector;(since you have to opt-in which database(s) on the server have the extension supported).I do this in my apps using a SQL script (https://github.com/aaronpowell/HanselminutesBot/blob/main/HanselminutesBot.AppHost/database/init.sql) that is added to the DB container image (https://github.com/aaronpowell/HanselminutesBot/blob/main/HanselminutesBot.AppHost/Program.cs#L45) as part of its startup pipeline.
andrewbabbittdev commentedon May 2, 2024
So this was the closest issue I could find to it, but it looks like we also need the ability to set
Microsoft.DBforPostgreSQL/flexibleServers/configurationsas a part of the postgres deployment for many extensions (ex. citext) otherwise you can't useCREATE EXTENSIONat all.Is there any way to set this property currently?
EF Core can already do
CREATE EXTENSIONas a part of a migration with ngpsql, but you still have to enable it on the extensions on the DB server in azure.andrewbabbittdev commentedon May 2, 2024
More info on the azure postgres docs here: https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-extensions#how-to-use-postgresql-extensions
aaronpowell commentedon May 7, 2024
Yep, you need to have some additional Bicep run to enable the extension. I've got a sample of it, just need to clean it up a touch to contribute in.
davidfowl commentedon May 7, 2024
Not sure we want additonal bicep, I'd rather us expand the Azure.Provisioning libraries to support setting this .
aaronpowell commentedon May 7, 2024
Yes, that might be a better option, but presently (or at least, 4 weeks ago when I looked before going on leave 🤣) there isn't support for that in the SDK to do it.
Initial prototype for microsoft#3052
aaronpowell commentedon Jul 23, 2024
PR open on CDK to add support - Azure/azure-sdk-for-net#44315
aaronpowell commentedon Dec 19, 2024
With the update to the CDK, and thus Azure Provisioning, it looks like this is now possible, so we can likely close this issue.
davidfowl commentedon May 27, 2025
Based on investigation it looks like this is the required configuration to add the pgvector extension to Azure postgres.
To run the SQL that creates the extension we could use a deployment script that executes the SQL but that might be on the edge.
aaronpowell commentedon May 27, 2025
I wonder if we should add this to the Community Toolkit extensions pack to at least configure the extension - running the SQL is a bit more complicated as it really depends on how the database is being "provisioned"
dcuccia commentedon Feb 16, 2026
Agree, would be nice if this worked OOB for both
aspire runandaspire deploy- stumbled on this based on the exciting Microsoft.Extensions.DataInjestion that sits on top of Microsoft.Extensions.VectorData https://www.youtube.com/watch?v=pQivzi4n6jM