Skip to content

Commit 816d844

Browse files
fix: fixed embedding issue for 3-large (#2061)
1 parent 8dbd708 commit 816d844

14 files changed

Lines changed: 206 additions & 228 deletions

File tree

.github/workflows/broken-links-checker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: lycheeverse/lychee-action@v2.7.0
3636
with:
3737
args: >
38-
--verbose --exclude-mail --no-progress --exclude ^https?://
38+
--verbose --no-progress --exclude ^https?://
3939
${{ steps.changed-markdown-files.outputs.all_changed_files }}
4040
failIfEmpty: false
4141
env:
@@ -48,7 +48,7 @@ jobs:
4848
uses: lycheeverse/lychee-action@v2.7.0
4949
with:
5050
args: >
51-
--verbose --exclude-mail --no-progress --exclude ^https?://
51+
--verbose --no-progress --exclude ^https?://
5252
'**/*.md'
5353
failIfEmpty: false
5454
env:

code/backend/batch/host.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"extensionBundle": {
1212
"id": "Microsoft.Azure.Functions.ExtensionBundle",
13-
"version": "[3.*, 4.0.0)"
13+
"version": "[4.*, 5.0.0)"
1414
}
15-
}
15+
}

code/backend/batch/utilities/helpers/llm_helper.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,37 @@ def get_streaming_llm(self):
9191
)
9292

9393
def get_embedding_model(self):
94+
dimensions = (
95+
int(self.env_helper.AZURE_SEARCH_DIMENSIONS)
96+
if self.env_helper.AZURE_SEARCH_DIMENSIONS
97+
else None
98+
)
9499
if self.auth_type_keys:
95100
return AzureOpenAIEmbeddings(
96101
azure_endpoint=self.env_helper.AZURE_OPENAI_ENDPOINT,
97102
api_key=self.env_helper.OPENAI_API_KEY,
98103
azure_deployment=self.embedding_model,
104+
dimensions=dimensions,
99105
chunk_size=1,
100106
)
101107
else:
102108
return AzureOpenAIEmbeddings(
103109
azure_endpoint=self.env_helper.AZURE_OPENAI_ENDPOINT,
104110
azure_deployment=self.embedding_model,
111+
dimensions=dimensions,
105112
chunk_size=1,
106113
azure_ad_token_provider=self.token_provider,
107114
)
108115

109116
def generate_embeddings(self, input: Union[str, list[int]]) -> List[float]:
117+
dimensions = (
118+
int(self.env_helper.AZURE_SEARCH_DIMENSIONS)
119+
if self.env_helper.AZURE_SEARCH_DIMENSIONS
120+
else None
121+
)
110122
return (
111123
self.openai_client.embeddings.create(
112-
input=[input], model=self.embedding_model
124+
input=[input], model=self.embedding_model, dimensions=dimensions
113125
)
114126
.data[0]
115127
.embedding

code/tests/functional/app_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AppConfig:
3838
"AZURE_SEARCH_CONVERSATIONS_LOG_INDEX": "some-log-index",
3939
"AZURE_SEARCH_CONTENT_COLUMN": "content",
4040
"AZURE_SEARCH_CONTENT_VECTOR_COLUMN": "some-search-content-vector-columns",
41-
"AZURE_SEARCH_DIMENSIONS": "some-search-dimensions",
41+
"AZURE_SEARCH_DIMENSIONS": "1536",
4242
"AZURE_SEARCH_ENABLE_IN_DOMAIN": "True",
4343
"AZURE_SEARCH_FIELDS_ID": "some-search-fields-id",
4444
"AZURE_SEARCH_FIELDS_METADATA": "some-search-fields-metadata",

code/tests/functional/tests/backend_api/default/test_conversation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def test_post_makes_correct_calls_to_openai_embeddings_to_get_vector_dimensions(
131131
json={
132132
"input": [[1199]],
133133
"model": "text-embedding-ada-002",
134+
"dimensions": 1536,
134135
"encoding_format": "base64",
135136
},
136137
headers={
@@ -164,6 +165,7 @@ def test_post_makes_correct_calls_to_openai_embeddings_to_embed_question_to_sear
164165
"model": app_config.get_from_json(
165166
"AZURE_OPENAI_EMBEDDING_MODEL_INFO", "model"
166167
),
168+
"dimensions": 1536,
167169
"encoding_format": "base64",
168170
},
169171
headers={
@@ -197,6 +199,7 @@ def test_post_makes_correct_calls_to_openai_embeddings_to_embed_question_to_stor
197199
[3923, 374, 279, 7438, 315, 2324, 30]
198200
], # Embedding of "What is the meaning of life?"
199201
"model": "text-embedding-ada-002", # this is hard coded in the langchain code base
202+
"dimensions": 1536,
200203
"encoding_format": "base64",
201204
},
202205
headers={

code/tests/functional/tests/backend_api/sk_orchestrator/test_response_without_tool_call.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_post_makes_correct_call_to_openai_embeddings(
7171
[3923, 374, 279, 7438, 315, 2324, 30]
7272
], # Embedding of "What is the meaning of life?"
7373
"model": "text-embedding-ada-002",
74+
"dimensions": 1536,
7475
"encoding_format": "base64",
7576
},
7677
headers={

code/tests/functional/tests/functions/advanced_image_processing/test_advanced_image_processing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def test_embeddings_generated_for_caption(
220220
"model": app_config.get_from_json(
221221
"AZURE_OPENAI_EMBEDDING_MODEL_INFO", "model"
222222
),
223+
"dimensions": 1536,
223224
"encoding_format": "base64",
224225
},
225226
headers={

code/tests/utilities/helpers/test_llm_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
PROMPT_FLOW_DEPLOYMENT_NAME = "mock-deployment-name"
2121

2222

23+
AZURE_SEARCH_DIMENSIONS = "1536"
24+
25+
2326
@pytest.fixture(autouse=True)
2427
def env_helper_mock():
2528
with patch("backend.batch.utilities.helpers.llm_helper.EnvHelper") as mock:
@@ -36,6 +39,7 @@ def env_helper_mock():
3639
env_helper.AZURE_ML_WORKSPACE_NAME = AZURE_ML_WORKSPACE_NAME
3740
env_helper.PROMPT_FLOW_ENDPOINT_NAME = PROMPT_FLOW_ENDPOINT_NAME
3841
env_helper.PROMPT_FLOW_DEPLOYMENT_NAME = PROMPT_FLOW_DEPLOYMENT_NAME
42+
env_helper.AZURE_SEARCH_DIMENSIONS = AZURE_SEARCH_DIMENSIONS
3943

4044
yield env_helper
4145

@@ -113,7 +117,7 @@ def test_generate_embeddings_embeds_input(azure_openai_mock):
113117

114118
# then
115119
azure_openai_mock.return_value.embeddings.create.assert_called_once_with(
116-
input=["some input"], model=AZURE_OPENAI_EMBEDDING_MODEL
120+
input=["some input"], model=AZURE_OPENAI_EMBEDDING_MODEL, dimensions=int(AZURE_SEARCH_DIMENSIONS)
117121
)
118122

119123

docs/customizing_azd_parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ By default this template will use the environment name as the prefix to prevent
4242
| `AZURE_OPENAI_EMBEDDING_MODEL_NAME` | string | `text-embedding-ada-002` | Actual embedding model name |
4343
| `AZURE_OPENAI_EMBEDDING_MODEL_VERSION` | string | `2` | Embedding model version |
4444
| `AZURE_OPENAI_EMBEDDING_MODEL_CAPACITY` | integer | `100` | Embedding model capacity (TPM in thousands) |
45+
| `AZURE_SEARCH_DIMENSIONS` | integer | `1536` | Azure Search vector dimensions(Update dimensions for CosmosDB) |
4546
| `USE_ADVANCED_IMAGE_PROCESSING` | boolean | `false` | Enable vision LLM and Computer Vision for images (must be false for PostgreSQL) |
4647
| `ADVANCED_IMAGE_PROCESSING_MAX_IMAGES` | integer | `1` | Maximum images per vision model request |
4748
| `AZURE_OPENAI_VISION_MODEL` | string | `gpt-4.1` | Vision model deployment name |
@@ -90,5 +91,6 @@ azd env set AZURE_OPENAI_EMBEDDING_MODEL_CAPACITY 150
9091
- `AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION=false`
9192
- `USE_ADVANCED_IMAGE_PROCESSING=false`
9293
- `ORCHESTRATION_STRATEGY=semantic_kernel` (recommended)
94+
- `AZURE_SEARCH_DIMENSIONS=1536` (recommended)
9395

9496
2. **Region Compatibility**: Not all services are available in all regions. Verify service availability in your chosen region before deployment.

infra/main.bicep

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,6 @@ param useAdvancedImageProcessing bool = false
150150
@description('Optional. The maximum number of images to pass to the vision model in a single request.')
151151
param advancedImageProcessingMaxImages int = 1
152152

153-
@description('Optional. Azure OpenAI Vision Model Deployment Name.')
154-
param azureOpenAIVisionModel string = 'gpt-4.1'
155-
156-
@description('Optional. Azure OpenAI Vision Model Name.')
157-
param azureOpenAIVisionModelName string = 'gpt-4.1'
158-
159-
@description('Optional. Azure OpenAI Vision Model Version.')
160-
param azureOpenAIVisionModelVersion string = '2025-04-14'
161-
162-
@description('Optional. Azure OpenAI Vision Model Capacity - See here for more info https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/quota.')
163-
param azureOpenAIVisionModelCapacity int = 10
164-
165153
@description('Optional. Orchestration strategy: openai_function or semantic_kernel or langchain str. If you use a old version of turbo (0301), please select langchain. If the database type is PostgreSQL, set this to sementic_kernel.')
166154
@allowed([
167155
'openai_function'
@@ -210,6 +198,9 @@ param azureOpenAIEmbeddingModelVersion string = '2'
210198
@description('Optional. Azure OpenAI Embedding Model Capacity - See here for more info https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/quota .')
211199
param azureOpenAIEmbeddingModelCapacity int = 100
212200

201+
@description('Optional. Azure Search vector field dimensions. Must match the embedding model dimensions. 1536 for text-embedding-ada-002, 3072 for text-embedding-3-large. See https://learn.microsoft.com/en-us/azure/search/cognitive-search-skill-azure-openai-embedding#supported-dimensions-by-modelname.(Only for databaseType=CosmosDB)')
202+
param azureSearchDimensions string = '1536'
203+
213204
@description('Optional. Name of Computer Vision Resource (if useAdvancedImageProcessing=true).')
214205
var computerVisionName string = 'cv-${solutionSuffix}'
215206

@@ -858,7 +849,7 @@ module pgSqlDelayScript 'br/public:avm/res/resources/deployment-script:0.5.1' =
858849
tags: tags
859850
kind: 'AzurePowerShell'
860851
enableTelemetry: enableTelemetry
861-
scriptContent: 'start-sleep -Seconds 300'
852+
scriptContent: 'start-sleep -Seconds 600'
862853
azPowerShellVersion: '11.0'
863854
timeout: 'PT15M'
864855
cleanupPreference: 'Always'
@@ -1285,6 +1276,7 @@ module web 'modules/app/web.bicep' = {
12851276
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.resourceId
12861277
AZURE_CLIENT_ID: managedIdentityModule.outputs.clientId // Required so LangChain AzureSearch vector store authenticates with this user-assigned managed identity
12871278
APP_ENV: appEnvironment
1279+
AZURE_SEARCH_DIMENSIONS: azureSearchDimensions
12881280
},
12891281
databaseType == 'CosmosDB'
12901282
? {
@@ -1383,6 +1375,7 @@ module adminweb 'modules/app/adminweb.bicep' = {
13831375
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.clientId
13841376
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.resourceId
13851377
APP_ENV: appEnvironment
1378+
AZURE_SEARCH_DIMENSIONS: azureSearchDimensions
13861379
},
13871380
databaseType == 'CosmosDB'
13881381
? {
@@ -1482,6 +1475,7 @@ module function 'modules/app/function.bicep' = {
14821475
AZURE_CLIENT_ID: managedIdentityModule.outputs.clientId // Required so LangChain AzureSearch vector store authenticates with this user-assigned managed identity
14831476
APP_ENV: appEnvironment
14841477
BACKEND_URL: backendUrl
1478+
AZURE_SEARCH_DIMENSIONS: azureSearchDimensions
14851479
},
14861480
databaseType == 'CosmosDB'
14871481
? {

0 commit comments

Comments
 (0)