Skip to content

Commit 5c74a89

Browse files
committed
Temp update of code
1 parent 666203e commit 5c74a89

File tree

3 files changed

+51
-82
lines changed

3 files changed

+51
-82
lines changed

ai_search_with_adi/ai_search/ai_search.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ def get_key_phrase_extraction_skill(self, context, source) -> WebApiSkill:
362362
batch_size = 16
363363
degree_of_parallelism = 16
364364

365-
keyphrase_extraction_skill_inputs = [
365+
key_phrase_extraction_skill_inputs = [
366366
InputFieldMappingEntry(name="text", source=source),
367367
]
368-
keyphrase_extraction__skill_outputs = [
368+
key_phrase_extraction__skill_outputs = [
369369
OutputFieldMappingEntry(name="keyPhrases", target_name="keywords")
370370
]
371371
key_phrase_extraction_skill = WebApiSkill(
@@ -377,8 +377,8 @@ def get_key_phrase_extraction_skill(self, context, source) -> WebApiSkill:
377377
batch_size=batch_size,
378378
degree_of_parallelism=degree_of_parallelism,
379379
http_method="POST",
380-
inputs=keyphrase_extraction_skill_inputs,
381-
outputs=keyphrase_extraction__skill_outputs,
380+
inputs=key_phrase_extraction_skill_inputs,
381+
outputs=key_phrase_extraction__skill_outputs,
382382
)
383383

384384
if self.environment.identity_type != IdentityType.KEY:

ai_search_with_adi/ai_search/environment.py

+46-77
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from enum import Enum
66
from azure.identity import DefaultAzureCredential
77
from azure.core.credentials import AzureKeyCredential
8+
from azure.search.documents.indexes.models import SearchIndexerDataUserAssignedIdentity
89

910
class IndexerType(Enum):
1011
"""The type of the indexer"""
@@ -68,6 +69,26 @@ def ai_search_endpoint(self) -> str:
6869
str: The ai search endpoint
6970
"""
7071
return os.environ.get("AIService__AzureSearchOptions__Endpoint")
72+
73+
@property
74+
def ai_search_identity_id(self) -> str:
75+
"""This function returns the ai search identity id.
76+
77+
Returns:
78+
str: The ai search identity id
79+
"""
80+
return os.environ.get("AIService__AzureSearchOptions__Identity__ClientId")
81+
82+
@property
83+
def ai_search_user_assigned_identity(self) -> SearchIndexerDataUserAssignedIdentity:
84+
"""This function returns the ai search user assigned identity.
85+
86+
Returns:
87+
SearchIndexerDataUserAssignedIdentity: The ai search user assigned identity"""
88+
user_assigned_identity = SearchIndexerDataUserAssignedIdentity(
89+
user_assigned_identity=os.environ.get("AIService__AzureSearchOptions__Identity__FQName")
90+
)
91+
return user_assigned_identity
7192

7293
@property
7394
def ai_search_credential(self) -> DefaultAzureCredential | AzureKeyCredential:
@@ -79,9 +100,9 @@ def ai_search_credential(self) -> DefaultAzureCredential | AzureKeyCredential:
79100
if self.identity_type in IdentityType.SYSTEM_ASSIGNED:
80101
return DefaultAzureCredential()
81102
elif self.identity_type in IdentityType.USER_ASSIGNED:
82-
return DefaultAzureCredential(managed_identity_client_id =os.environ.get("AIService__AzureSearchOptions__ManagedIdentity__FQName"))
103+
return DefaultAzureCredential(managed_identity_client_id=self.ai_search_identity_id)
83104
else:
84-
return AzureKeyCredential(os.environ.get("AIService__AzureSearchOptions__Key__Secret"))
105+
return AzureKeyCredential(os.environ.get("AIService__AzureSearchOptions__Key"))
85106

86107
@property
87108
def storage_account_connection_string(self) -> str:
@@ -125,15 +146,35 @@ def function_app_adi_route(self) -> str:
125146
"""
126147
This function returns function app adi name
127148
"""
128-
return os.environ.get("FunctionApp__DocumentIntelligence__FunctionName")
149+
return os.environ.get("FunctionApp__ADI__FunctionName")
129150

130151
@property
131152
def function_app_key_phrase_extractor_route(self) -> str:
132153
"""
133154
This function returns function app keyphrase extractor name
134155
"""
135-
return os.environ.get("FunctionApp__KeyphraseExtractor__FunctionName")
156+
return os.environ.get("FunctionApp__KeyPhraseExtractor__FunctionName")
157+
158+
@property
159+
def ai_search_embedding_model_dimensions(self) -> str:
160+
"""
161+
This function returns dimensions for embedding model.
162+
163+
Returns:
164+
str: The dimensions for embedding model
165+
"""
166+
167+
return os.environ.get(
168+
f"AIService__AzureSearchOptions__{self.normalised_indexer_type}__EmbeddingDimensions"
169+
)
136170

171+
@property
172+
def use_private_endpoint(self) -> bool:
173+
"""
174+
This function returns true if private endpoint is used
175+
"""
176+
return os.environ.get("AIService__AzureSearchOptions__UsePrivateEndpoint") == "true"
177+
137178
def get_custom_skill_function_url(self, skill_type: str):
138179
"""
139180
Get the function app url that is hosting the custom skill
@@ -152,81 +193,9 @@ def get_custom_skill_function_url(self, skill_type: str):
152193
return full_url
153194

154195

155-
156-
# managed identity id
157-
def get_managed_identity_id() -> str:
158-
"""
159-
This function returns maanged identity id
160-
"""
161-
return os.environ.get("AIService__AzureSearchOptions__ManagedIdentity__ClientId")
162-
163-
164-
def get_managed_identity_fqname() -> str:
165-
"""
166-
This function returns maanged identity name
167-
"""
168-
return os.environ.get("AIService__AzureSearchOptions__ManagedIdentity__FQName")
169-
170-
171196
# function app details
172197
def get_function_app_authresourceid() -> str:
173198
"""
174199
This function returns apps registration in microsoft entra id
175200
"""
176-
return os.environ.get("FunctionApp__AuthResourceId")
177-
178-
# search
179-
def get_search_endpoint() -> str:
180-
"""
181-
This function returns azure ai search service endpoint
182-
"""
183-
return os.environ.get("AIService__AzureSearchOptions__Endpoint")
184-
185-
186-
def get_search_user_assigned_identity() -> str:
187-
"""
188-
This function returns azure ai search service endpoint
189-
"""
190-
return os.environ.get("AIService__AzureSearchOptions__UserAssignedIdentity")
191-
192-
193-
def get_search_key(client) -> str:
194-
"""
195-
This function returns azure ai search service admin key
196-
"""
197-
search_service_key_secret_name = (
198-
str(os.environ.get("AIService__AzureSearchOptions__name")) + "-PrimaryKey"
199-
)
200-
retrieved_secret = client.get_secret(search_service_key_secret_name)
201-
return retrieved_secret.value
202-
203-
204-
def get_search_key_secret() -> str:
205-
"""
206-
This function returns azure ai search service admin key
207-
"""
208-
return os.environ.get("AIService__AzureSearchOptions__Key__Secret")
209-
210-
211-
def get_search_embedding_model_dimensions(indexer_type: IndexerType) -> str:
212-
"""
213-
This function returns dimensions for embedding model
214-
"""
215-
216-
normalised_indexer_type = (
217-
indexer_type.value.replace("-", " ").title().replace(" ", "")
218-
)
219-
220-
return os.environ.get(
221-
f"AIService__AzureSearchOptions__{normalised_indexer_type}__EmbeddingDimensions"
222-
)
223-
224-
225-
def get_blob_container_name(indexer_type: str) -> str:
226-
"""
227-
This function returns azure blob container name
228-
"""
229-
normalised_indexer_type = (
230-
indexer_type.value.replace("-", " ").title().replace(" ", "")
231-
)
232-
return os.environ.get(f"StorageAccount__{normalised_indexer_type}__Container")
201+
return os.environ.get("FunctionApp__AuthResourceId")

ai_search_with_adi/ai_search/rag_documents.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_index_fields(self) -> list[SearchableField]:
8383
SearchField(
8484
name="ChunkEmbedding",
8585
type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
86-
vector_search_dimensions=self.environment.embedding_model_dimensions,
86+
vector_search_dimensions=self.environment.ai_search_embedding_model_dimensions,
8787
vector_search_profile_name=self.vector_search_profile_name,
8888
),
8989
SearchableField(

0 commit comments

Comments
 (0)