Skip to content

Commit b8e9ae6

Browse files
committed
Fix
1 parent 0284039 commit b8e9ae6

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

infra/core/ai/hub-dependencies.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ module searchService '../search/search-services.bicep' =
142142
location: location
143143
tags: tags
144144
name: searchServiceName
145+
semanticSearch: 'free'
145146
authOptions: { aadOrApiKey: { aadAuthFailureMode: 'http401WithBearerChallenge'}}
146147
}
147148
}

src/api/search_index_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ async def semantic_search(self, message: str) -> str:
167167
response = await self._get_client().search(
168168
search_text=message,
169169
query_type="semantic",
170+
search_fields=['token', 'document_reference'],
170171
semantic_configuration_name=SearchIndexManager._SEMANTIC_CONFIG,
171172
)
172173
return await self._format_search_results(response)
@@ -277,8 +278,10 @@ async def _index_create(self, vector_index_dimensions: int) -> SearchIndex:
277278
SemanticConfiguration(
278279
name=SearchIndexManager._SEMANTIC_CONFIG,
279280
prioritized_fields=SemanticPrioritizedFields(
280-
title_field=SemanticField(field_name="embedId"),
281-
content_fields=[SemanticField(field_name="token")]
281+
title_field=SemanticField(field_name="document_reference"),
282+
content_fields=[
283+
SemanticField(field_name="token"),
284+
]
282285
)
283286
)
284287
]

src/gunicorn.conf.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ async def get_available_toolset(
124124
:param creds: The credentials, used for the index.
125125
:return: The tool set, available based on the environment.
126126
"""
127-
# File name -> {"id": file_id, "path": file_path}
128-
files: Dict[str, Dict[str, str]] = {}
129127
# First try to get an index search.
130128
conn_id = ""
131129
if os.environ.get('AZURE_AI_SEARCH_INDEX_NAME'):
@@ -145,20 +143,11 @@ async def get_available_toolset(
145143

146144
toolset.add(ai_search)
147145
logger.info("agent: initialized index")
148-
# Populate file links.
149-
embeddings_path = os.path.join(
150-
os.path.dirname(__file__), 'data', 'embeddings.csv')
151-
with open(embeddings_path, newline='') as fp:
152-
reader = csv.DictReader(fp)
153-
for row in reader:
154-
if row['document_reference'] in FILES_NAMES:
155-
files[row['document_reference']] = {
156-
"id": row['document_reference'],
157-
"path": _get_file_path(row['document_reference'])
158-
}
159146
else:
160147
logger.info(
161148
"agent: index was not initialized, falling back to file search.")
149+
# File name -> {"id": file_id, "path": file_path}
150+
files: Dict[str, Dict[str, str]] = {}
162151
# Upload files for file search
163152
for file_name in FILES_NAMES:
164153
file_path = _get_file_path(file_name)
@@ -167,6 +156,9 @@ async def get_available_toolset(
167156
# Store both file id and the file path using the file name as key.
168157
files[file_name] = {"id": file.id, "path": file_path}
169158

159+
# Serialize and store files information in the environment variable (so
160+
# workers see it)
161+
os.environ["UPLOADED_FILE_MAP"] = json.dumps(files)
170162
logger.info(
171163
f"Set env UPLOADED_FILE_MAP = {os.environ['UPLOADED_FILE_MAP']}")
172164

@@ -179,9 +171,7 @@ async def get_available_toolset(
179171

180172
file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
181173
toolset.add(file_search_tool)
182-
# Serialize and store files information in the environment variable (so
183-
# workers see it)
184-
os.environ["UPLOADED_FILE_MAP"] = json.dumps(files)
174+
185175
return toolset
186176

187177

tests/test_search_index_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def test_exception_different_dimmensions(self):
121121
"from dimensions provided to constructor."):
122122
await rag.create_index(vector_index_dimensions=42)
123123

124-
@unittest.skip("Only for live tests.")
124+
#@unittest.skip("Only for live tests.")
125125
async def test_e2e(self):
126126
"""Run search end to end."""
127127
async with DefaultAzureCredential() as creds:
@@ -153,9 +153,13 @@ async def test_e2e(self):
153153
result = await rag.search(
154154
"What is the temperature rating "
155155
"of the cozynights sleeping bag?")
156+
result_semantic = await rag.semantic_search(
157+
"What is the temperature rating "
158+
"of the cozynights sleeping bag?")
156159
await rag.delete_index()
157160
await rag.close()
158-
self.assertTrue(bool(result))
161+
self.assertTrue(bool(result), "The regular search is empty.")
162+
self.assertTrue(bool(result_semantic), "The semantic search is empty.")
159163

160164
async def test_life_cycle_mock(self):
161165
"""Test create, upload, search and delete"""

0 commit comments

Comments
 (0)