Skip to content

Commit cd065c1

Browse files
committed
Use boolean parameters in the backend as well, for vector fields
1 parent 8c17ca5 commit cd065c1

File tree

12 files changed

+50
-59
lines changed

12 files changed

+50
-59
lines changed

.azdo/pipelines/azure-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ steps:
122122
USE_CHAT_HISTORY_BROWSER: $(USE_CHAT_HISTORY_BROWSER)
123123
USE_MEDIA_DESCRIBER_AZURE_CU: $(USE_MEDIA_DESCRIBER_AZURE_CU)
124124
RAG_LLM_INPUTS_OVERRIDE: $(RAG_LLM_INPUTS_OVERRIDE)
125-
RAG_VECTOR_FIELDS_DEFAULT: $(RAG_VECTOR_FIELDS_DEFAULT)
125+
RAG_SEARCH_TEXT_EMBEDDINGS: $(RAG_SEARCH_TEXT_EMBEDDINGS)
126+
RAG_SEARCH_IMAGE_EMBEDDINGS: $(RAG_SEARCH_IMAGE_EMBEDDINGS)
126127
- task: AzureCLI@2
127128
displayName: Deploy Application
128129
inputs:

.github/workflows/azure-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ jobs:
112112
USE_MEDIA_DESCRIBER_AZURE_CU: ${{ vars.USE_MEDIA_DESCRIBER_AZURE_CU }}
113113
USE_AI_PROJECT: ${{ vars.USE_AI_PROJECT }}
114114
RAG_LLM_INPUTS_OVERRIDE: ${{ vars.RAG_LLM_INPUTS_OVERRIDE }}
115-
RAG_VECTOR_FIELDS_DEFAULT: ${{ vars.RAG_VECTOR_FIELDS_DEFAULT }}
115+
RAG_SEARCH_TEXT_EMBEDDINGS: ${{ vars.RAG_SEARCH_TEXT_EMBEDDINGS }}
116+
RAG_SEARCH_IMAGE_EMBEDDINGS: ${{ vars.RAG_SEARCH_IMAGE_EMBEDDINGS }}
116117
steps:
117118
- name: Checkout
118119
uses: actions/checkout@v4

app/backend/app.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
CONFIG_OPENAI_CLIENT,
7474
CONFIG_QUERY_REWRITING_ENABLED,
7575
CONFIG_RAG_LLM_INPUTS_OVERRIDE,
76-
CONFIG_RAG_VECTOR_FIELDS_DEFAULT,
76+
CONFIG_RAG_SEARCH_IMAGE_EMBEDDINGS,
77+
CONFIG_RAG_SEARCH_TEXT_EMBEDDINGS,
7778
CONFIG_REASONING_EFFORT_ENABLED,
7879
CONFIG_SEARCH_CLIENT,
7980
CONFIG_SEMANTIC_RANKER_DEPLOYED,
@@ -302,7 +303,8 @@ def config():
302303
"showChatHistoryCosmos": current_app.config[CONFIG_CHAT_HISTORY_COSMOS_ENABLED],
303304
"showAgenticRetrievalOption": current_app.config[CONFIG_AGENTIC_RETRIEVAL_ENABLED],
304305
"ragLlmInputsOverride": current_app.config[CONFIG_RAG_LLM_INPUTS_OVERRIDE],
305-
"ragVectorFieldsDefault": current_app.config[CONFIG_RAG_VECTOR_FIELDS_DEFAULT],
306+
"ragSearchImageEmbeddings": current_app.config[CONFIG_RAG_SEARCH_IMAGE_EMBEDDINGS],
307+
"ragSearchTextEmbeddings": current_app.config[CONFIG_RAG_SEARCH_TEXT_EMBEDDINGS],
306308
}
307309
)
308310

@@ -453,7 +455,8 @@ async def setup_clients():
453455

454456
USE_MULTIMODAL = os.getenv("USE_MULTIMODAL", "").lower() == "true"
455457
RAG_LLM_INPUTS_OVERRIDE = os.getenv("RAG_LLM_INPUTS_OVERRIDE", "")
456-
RAG_VECTOR_FIELDS_DEFAULT = os.getenv("RAG_VECTOR_FIELDS_DEFAULT", "")
458+
RAG_SEARCH_TEXT_EMBEDDINGS = os.getenv("RAG_SEARCH_TEXT_EMBEDDINGS", "true").lower() == "true"
459+
RAG_SEARCH_IMAGE_EMBEDDINGS = os.getenv("RAG_SEARCH_IMAGE_EMBEDDINGS", "true").lower() == "true"
457460
USE_USER_UPLOAD = os.getenv("USE_USER_UPLOAD", "").lower() == "true"
458461
ENABLE_LANGUAGE_PICKER = os.getenv("ENABLE_LANGUAGE_PICKER", "").lower() == "true"
459462
USE_SPEECH_INPUT_BROWSER = os.getenv("USE_SPEECH_INPUT_BROWSER", "").lower() == "true"
@@ -658,7 +661,8 @@ async def setup_clients():
658661
current_app.config[CONFIG_AGENTIC_RETRIEVAL_ENABLED] = USE_AGENTIC_RETRIEVAL
659662
current_app.config[CONFIG_MULTIMODAL_ENABLED] = USE_MULTIMODAL
660663
current_app.config[CONFIG_RAG_LLM_INPUTS_OVERRIDE] = RAG_LLM_INPUTS_OVERRIDE
661-
current_app.config[CONFIG_RAG_VECTOR_FIELDS_DEFAULT] = RAG_VECTOR_FIELDS_DEFAULT
664+
current_app.config[CONFIG_RAG_SEARCH_TEXT_EMBEDDINGS] = RAG_SEARCH_TEXT_EMBEDDINGS
665+
current_app.config[CONFIG_RAG_SEARCH_IMAGE_EMBEDDINGS] = RAG_SEARCH_IMAGE_EMBEDDINGS
662666

663667
prompt_manager = PromptyManager()
664668

app/backend/approaches/approach.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ class LLMInputType(str, Enum):
4545
TEXTS = "texts"
4646

4747

48-
class VectorFieldType(str, Enum):
49-
EMBEDDING = "textEmbeddingOnly"
50-
IMAGE_EMBEDDING = "imageEmbeddingOnly"
51-
TEXT_AND_IMAGE_EMBEDDINGS = "textAndImageEmbeddings"
52-
53-
5448
@dataclass
5549
class Document:
5650
id: Optional[str] = None
@@ -219,15 +213,6 @@ def get_default_llm_inputs(self) -> str:
219213
else:
220214
return LLMInputType.TEXTS
221215

222-
def get_default_vector_fields(self) -> str:
223-
"""
224-
Returns the default vector fields based on whether multimodal is enabled
225-
"""
226-
if self.multimodal_enabled:
227-
return VectorFieldType.TEXT_AND_IMAGE_EMBEDDINGS
228-
else:
229-
return VectorFieldType.EMBEDDING
230-
231216
def build_filter(self, overrides: dict[str, Any], auth_claims: dict[str, Any]) -> Optional[str]:
232217
include_category = overrides.get("include_category")
233218
exclude_category = overrides.get("exclude_category")

app/backend/approaches/chatreadretrieveread.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
ExtraInfo,
2323
LLMInputType,
2424
ThoughtStep,
25-
VectorFieldType,
2625
)
2726
from approaches.promptmanager import PromptManager
2827
from core.authentication import AuthenticationHelper
@@ -287,24 +286,16 @@ async def run_search_approach(
287286
search_index_filter = self.build_filter(overrides, auth_claims)
288287

289288
llm_inputs = overrides.get("llm_inputs")
290-
vector_fields = overrides.get("vector_fields")
291-
292289
# Use default values based on multimodal_enabled if not provided in overrides
293290
if llm_inputs is None:
294291
llm_inputs = self.get_default_llm_inputs()
295-
if vector_fields is None:
296-
vector_fields = self.get_default_vector_fields()
297-
298292
llm_inputs_enum = LLMInputType(llm_inputs) if llm_inputs is not None else None
299-
vector_fields_enum = VectorFieldType(vector_fields) if vector_fields is not None else None
300-
# Use multimodal/image logic based on enums
301-
use_image_embeddings = vector_fields_enum in [
302-
VectorFieldType.IMAGE_EMBEDDING,
303-
VectorFieldType.TEXT_AND_IMAGE_EMBEDDINGS,
304-
]
305293
use_image_sources = llm_inputs_enum in [LLMInputType.TEXT_AND_IMAGES, LLMInputType.IMAGES]
306294
use_text_sources = llm_inputs_enum in [LLMInputType.TEXT_AND_IMAGES, LLMInputType.TEXTS]
307295

296+
use_image_embeddings = overrides.get("use_image_embeddings", self.multimodal_enabled)
297+
use_text_embeddings = overrides.get("use_text_embeddings", True)
298+
308299
original_user_query = messages[-1]["content"]
309300
if not isinstance(original_user_query, str):
310301
raise ValueError("The most recent message content must be a string.")
@@ -338,7 +329,8 @@ async def run_search_approach(
338329

339330
vectors: list[VectorQuery] = []
340331
if use_vector_search:
341-
vectors.append(await self.compute_text_embedding(query_text))
332+
if use_text_embeddings:
333+
vectors.append(await self.compute_text_embedding(query_text))
342334
if use_image_embeddings:
343335
vectors.append(await self.compute_multimodal_embedding(query_text))
344336

app/backend/approaches/retrievethenread.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
ExtraInfo,
1515
LLMInputType,
1616
ThoughtStep,
17-
VectorFieldType,
1817
)
1918
from approaches.promptmanager import PromptManager
2019
from core.authentication import AuthenticationHelper
@@ -163,25 +162,18 @@ async def run_search_approach(
163162
q = str(messages[-1]["content"])
164163

165164
llm_inputs = overrides.get("llm_inputs")
166-
vector_fields = overrides.get("vector_fields")
167-
168165
# Use default values based on multimodal_enabled if not provided in overrides
169166
if llm_inputs is None:
170167
llm_inputs = self.get_default_llm_inputs()
171-
if vector_fields is None:
172-
vector_fields = self.get_default_vector_fields()
173-
174168
llm_inputs_enum = LLMInputType(llm_inputs) if llm_inputs is not None else None
175-
vector_fields_enum = VectorFieldType(vector_fields) if vector_fields is not None else None
176-
use_image_embeddings = vector_fields_enum in [
177-
VectorFieldType.IMAGE_EMBEDDING,
178-
VectorFieldType.TEXT_AND_IMAGE_EMBEDDINGS,
179-
]
180169
use_image_sources = llm_inputs_enum in [LLMInputType.TEXT_AND_IMAGES, LLMInputType.IMAGES]
181170

171+
use_image_embeddings = overrides.get("use_image_embeddings", self.multimodal_enabled)
172+
use_text_embeddings = overrides.get("use_text_embeddings", True)
173+
182174
vectors: list[VectorQuery] = []
183175
if use_vector_search:
184-
if vector_fields_enum != VectorFieldType.IMAGE_EMBEDDING:
176+
if use_text_embeddings:
185177
vectors.append(await self.compute_text_embedding(q))
186178
if use_image_embeddings:
187179
vectors.append(await self.compute_multimodal_embedding(q))

app/backend/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
CONFIG_COSMOS_HISTORY_VERSION = "cosmos_history_version"
3535
CONFIG_MULTIMODAL_ENABLED = "multimodal_enabled"
3636
CONFIG_RAG_LLM_INPUTS_OVERRIDE = "rag_llm_inputs_override"
37-
CONFIG_RAG_VECTOR_FIELDS_DEFAULT = "rag_vector_fields_default"
37+
CONFIG_RAG_SEARCH_TEXT_EMBEDDINGS = "rag_search_text_embeddings"
38+
CONFIG_RAG_SEARCH_IMAGE_EMBEDDINGS = "rag_search_image_embeddings"

app/frontend/src/locales/en/translation.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@
160160
"useSemanticCaptions":
161161
"Sends semantic captions to the LLM instead of the full search result. A semantic caption is extracted from a search result during the process of semantic ranking.",
162162
"suggestFollowupQuestions": "Asks the LLM to suggest follow-up questions based on the user's query.",
163-
"vectorFields":
164-
"Specifies which embedding fields in the Azure AI Search Index will be searched, both the 'Images and text' embeddings, 'Images' only, or 'Text' only.",
165163
"textEmbeddings": "When selected, search will use embeddings from the text-only embeddings model of extracted text chunks.",
166164
"imageEmbeddings": "When selected, search will use embeddings from the multimodal embeddings model of extracted images.",
167165
"llmInputs":

azure.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ pipeline:
123123
- USE_MEDIA_DESCRIBER_AZURE_CU
124124
- USE_AI_PROJECT
125125
- RAG_LLM_INPUTS_OVERRIDE
126-
- RAG_VECTOR_FIELDS_DEFAULT
126+
- RAG_SEARCH_TEXT_EMBEDDINGS
127+
- RAG_SEARCH_IMAGE_EMBEDDINGS
127128
secrets:
128129
- AZURE_SERVER_APP_SECRET
129130
- AZURE_CLIENT_APP_SECRET

docs/multimodal.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,26 @@ For more details on how this feature works, read [this blog post](https://techco
8383

8484
You can customize the RAG flow approach with a few additional environment variables.
8585

86-
To only use the text embeddings for the search step (no image embeddings), run:
86+
The following variables can be set to either true or false,
87+
to control whether Azure AI Search will use text embeddings, image embeddings, or both:
8788

8889
```shell
89-
azd env set RAG_VECTOR_FIELDS_DEFAULT "textEmbeddingOnly"
90+
azd env set RAG_SEARCH_TEXT_EMBEDDINGS true
9091
```
9192

92-
To only send text sources to the chat completion model (no images), run:
93+
```shell
94+
azd env set RAG_SEARCH_IMAGE_EMBEDDINGS true
95+
```
96+
97+
The following variable can be set to either true or false,
98+
to control whether the chat completion model will use text inputs, image inputs, or both:
99+
100+
```shell
101+
azd env set RAG_CHAT_TEXT_INPUTS true
102+
```
93103

94104
```shell
95-
azd env set RAG_LLM_INPUTS_OVERRIDE "texts"
105+
azd env set RAG_CHAT_IMAGE_INPUTS true
96106
```
97107

98108
You can also modify those settings in the "Developer Settings" in the chat UI,

0 commit comments

Comments
 (0)