Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement hybrid search on BYOD endpoint. #891

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
superhindupur marked this conversation as resolved.
Show resolved Hide resolved
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,
},
superhindupur marked this conversation as resolved.
Show resolved Hide resolved
"query_type": (
"semantic"
"vector_semantic_hybrid"
superhindupur marked this conversation as resolved.
Show resolved Hide resolved
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
Loading