Support Azure AI Search Sticky Sessions #877
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context (Why the change? What's the scenario?)
The
UseSessionIdproperty on theSearchOptionscan help improve the relevance of search results when multiple replicas are configured. This should be the case in any production deployment as two replicas are required for high availability of read-only workloads (queries), and three or more for high availability of read-write workloads (queries and indexing).https://learn.microsoft.com/en-us/rest/api/searchservice/documents/search-post?view=rest-searchservice-2024-07-01&tabs=HTTP#request-body
Using this setting should also provide more consistent results from the
AzureAISearchMemory.GetListAsyncmethod. Without anorderbyparameter results are sorted by score, and when*is used as the search query, all results have the same score of1. This increases the likelihood of getting inconsistent results when the search query hits different replicas.High level description (Approach, Design)
Extend the
AzureAISearchConfigclass with a newUseSessionIdproperty:falseto avoid any change in behaviour for existing users and to make its use an explicit choice likeUseHybridSearchDefineFieldsToSelectmethod inAzureAISearchMemorytoApplyCommonSearchOptionsas it will be used to also apply theUseSessionIdsettingtrueset theSessionIdproperty on theSearchOptionstoGuid.NewGuid().ToString("N")ensuring the same session ID is used while paging results but is not reused for subsequent method callsSearchOptions.Filterproperty by passing theICollection<MemoryFilter>?to theApplyCommonSearchOptionsmethodUseSessionIdpropertyappsettings.jsonfiles in the solution