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
UseSessionId
property on theSearchOptions
can 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.GetListAsync
method. Without anorderby
parameter 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
AzureAISearchConfig
class with a newUseSessionId
property:false
to avoid any change in behaviour for existing users and to make its use an explicit choice likeUseHybridSearch
DefineFieldsToSelect
method inAzureAISearchMemory
toApplyCommonSearchOptions
as it will be used to also apply theUseSessionId
settingtrue
set theSessionId
property on theSearchOptions
toGuid.NewGuid().ToString("N")
ensuring the same session ID is used while paging results but is not reused for subsequent method callsSearchOptions.Filter
property by passing theICollection<MemoryFilter>?
to theApplyCommonSearchOptions
methodUseSessionId
propertyappsettings.json
files in the solution