mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 11:49:53 -05:00
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactoring
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
pgmongo.enableEmbeddingGeneration, default is false(feature disabled)
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
The goal of this feature is enable an inline embedding generation in vCore based on [azure_ai extension]
(https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/generative-ai-azure-openai)
Related design doc [Inline embedding generation in vCore ](https://microsoftapc-my.sharepoint.com/:w:/g/personal/zhli2_microsoft_com/Ea2uDc0c0FBNr-fpoMdHIPUBJiA5yXZ-xRRNWGYEBqZ38Q?e=dQdU7i&ovuser=72f988bf-86f1-41af-91ab-2d7cd011db47%2Crongwa%40microsoft.com&clickparams=eyJBcHBOYW1lIjoiVGVhbXMtRGVza3RvcCIsIkFwcFZlcnNpb24iOiI0OS8yNDAzMTQxNDcxMiIsIkhhc0ZlZGVyYXRlZFVzZXIiOmZhbHNlfQ%3D%3D)

- Feature Flag
**pgmongo.enableEmbeddingGeneration**
- Feature counter
**update_operator_vector_gen_embeddings**
**search_vector_gen_embeddings**
- Onboard AOAI resource([Part 3 PR](https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/pullrequest/1478366))
```
SELECT create_distributed_table('azure_ai.settings','key');
SELECT azure_ai.set_setting('azure_openai.endpoint','https://localhost.openai.azure.com');
SELECT azure_ai.set_setting('azure_openai.subscription_key','<api-key-placeholder>');
ALTER SYSTEM SET pgmongo.azureOpenAIEmbeddingDeploymentName = 'text-embedding-ada-002';
SELECT pg_reload_conf();
SELECT run_command_on_workers('ALTER SYSTEM SET pgmongo.azureOpenAIEmbeddingDeploymentName = ''text-embedding-ada-002''');
SELECT run_command_on_workers('SELECT pg_reload_conf()');
```
- Update command
```
SELECT mongo_api_v1.update('db',
'{"update":"generate_embedding_pipeline",
"updates":[
{"q":{},"u":{"**$generateEmbeddings**":{"a":"embeddings"}}, "multi":true}
]}'
);
```
- Vector search
```
SELECT document FROM bson_aggregation_pipeline('db',
'{ "aggregate": "generate_embedding_pipeline",
"pipeline": [
{ "$search": {
"cosmosSearch": { "query": "some sentence", "k": 4, "path": "embeddings", "efSearch": 2 } }
} ,
{ "$count": "_id" }
],
"cursor": {}
}'
);
```
----
#### AI description (iteration 1)
#### PR Classification
Refactor to support non-OSS embedding generation and vector search.
#### PR Summary
This pull request refactors update operations and search specifications to support embedding generation in non-OSS environments.
- Added `vector_g...