Skip to content

Commit

Permalink
Enable hybrid search on the BYOD endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
superhindupur committed May 13, 2024
1 parent cacb7c3 commit 1c61ee9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions code/backend/batch/utilities/search/AzureSearchHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _hybrid_search(self, question: str, tokenised_question: list[int]):
fields=self._VECTOR_FIELD,
)
],
query_type="simple", # this is the default value
filter=self.env_helper.AZURE_SEARCH_FILTER,
top=self.env_helper.AZURE_SEARCH_TOP_K,
)
Expand Down
8 changes: 6 additions & 2 deletions code/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ def conversation_with_data(request: Request, env_helper: EnvHelper):
"filter": env_helper.AZURE_SEARCH_FILTER,
"in_scope": env_helper.AZURE_SEARCH_ENABLE_IN_DOMAIN,
"top_n_documents": env_helper.AZURE_SEARCH_TOP_K,
"embedding_dependency": {
"type": "deployment_name",
"deployment_name": env_helper.AZURE_OPENAI_EMBEDDING_MODEL,
},
"query_type": (
"semantic"
"vector_semantic_hybrid"
if env_helper.AZURE_SEARCH_USE_SEMANTIC_SEARCH
else "simple"
else "vector_simple_hybrid"
),
"semantic_configuration": (
env_helper.AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def test_post_makes_correct_call_to_azure_openai(
"filter": app_config.get("AZURE_SEARCH_FILTER"),
"in_scope": True,
"top_n_documents": 5,
"query_type": "simple",
"embedding_dependency": {
"type": "deployment_name",
"deployment_name": "some-embedding-model",
},
"query_type": "vector_simple_hybrid",
"semantic_configuration": "",
"role_information": "You are an AI assistant that helps people find information.",
"authentication": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def test_post_makes_correct_call_to_search_documents_search_index(
method="POST",
json={
"filter": app_config.get("AZURE_SEARCH_FILTER"),
"queryType": "simple",
"search": "What is the meaning of life?",
"top": int(app_config.get("AZURE_SEARCH_TOP_K")),
"vectorQueries": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def test_post_makes_correct_call_to_get_search_documents(
method="POST",
json={
"filter": app_config.get("AZURE_SEARCH_FILTER"),
"queryType": "simple",
"search": "What is the meaning of life?",
"top": int(app_config.get("AZURE_SEARCH_TOP_K")),
"vectorQueries": [
Expand Down
1 change: 1 addition & 0 deletions code/tests/search_utilities/test_AzureSearchHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def test_query_search_performs_hybrid_search(handler, mock_llm_helper):
fields="content_vector",
)
],
query_type="simple",
filter=handler.env_helper.AZURE_SEARCH_FILTER,
top=handler.env_helper.AZURE_SEARCH_TOP_K,
)
Expand Down
10 changes: 8 additions & 2 deletions code/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
AZURE_SPEECH_REGION_ENDPOINT = "mock-speech-region-endpoint"
AZURE_OPENAI_ENDPOINT = "mock-openai-endpoint"
AZURE_OPENAI_MODEL = "mock-openai-model"
AZURE_OPENAI_EMBEDDING_MODEL = "mock-openai-embedding-model"
AZURE_OPENAI_SYSTEM_MESSAGE = "system-message"
AZURE_OPENAI_API_VERSION = "mock-version"
AZURE_OPENAI_API_KEY = "mock-api-key"
Expand Down Expand Up @@ -47,6 +48,7 @@ def env_helper_mock():
env_helper.AZURE_SPEECH_REGION_ENDPOINT = AZURE_SPEECH_REGION_ENDPOINT
env_helper.AZURE_OPENAI_ENDPOINT = AZURE_OPENAI_ENDPOINT
env_helper.AZURE_OPENAI_MODEL = AZURE_OPENAI_MODEL
env_helper.AZURE_OPENAI_EMBEDDING_MODEL = AZURE_OPENAI_EMBEDDING_MODEL
env_helper.AZURE_OPENAI_SYSTEM_MESSAGE = AZURE_OPENAI_SYSTEM_MESSAGE
env_helper.AZURE_OPENAI_API_VERSION = AZURE_OPENAI_API_VERSION
env_helper.AZURE_OPENAI_API_KEY = AZURE_OPENAI_API_KEY
Expand Down Expand Up @@ -499,7 +501,11 @@ def test_converstation_azure_byod_returns_correct_response_when_streaming_with_d
"filter": AZURE_SEARCH_FILTER,
"in_scope": AZURE_SEARCH_ENABLE_IN_DOMAIN,
"top_n_documents": AZURE_SEARCH_TOP_K,
"query_type": "semantic",
"embedding_dependency": {
"type": "deployment_name",
"deployment_name": AZURE_OPENAI_EMBEDDING_MODEL,
},
"query_type": "vector_semantic_hybrid",
"semantic_configuration": AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG,
"role_information": AZURE_OPENAI_SYSTEM_MESSAGE,
},
Expand Down Expand Up @@ -809,7 +815,7 @@ def test_converstation_azure_byod_uses_semantic_config(

assert (
kwargs["extra_body"]["data_sources"][0]["parameters"]["query_type"]
== "semantic"
== "vector_semantic_hybrid"
)
assert (
kwargs["extra_body"]["data_sources"][0]["parameters"][
Expand Down

0 comments on commit 1c61ee9

Please sign in to comment.