Skip to content

Commit

Permalink
Java: fixed minRelevance filtering in getNearestMatchesAsync. make ge…
Browse files Browse the repository at this point in the history
…tSearc… (#3059)

### Motivation and Context
While trying to use current AzureCognitiveSearchMemoryStore I think I
found a bug in getNearestMatchesAsynch.
I had to create my own implementation extending this class in order to
test it.
Furthermore It was hard to create a custom implementation as
getSearchClient is private and I could not reuse the cognitive search
client.
For my custom implementation look here:
https://github.com/Azure-Samples/azure-search-openai-demo-java/blob/main/app/backend/src/main/java/com/microsoft/openai/samples/rag/ask/approaches/semantickernel/memory/CustomAzureCognitiveSearchMemoryStore.java


### Description

- fixed minRelevance filtering in getNearestMatchesAsync. 
- make getSearchClient protected to improve extensibility

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
 - Maven build worked locally
- All unit tests passed locally. However I noticed the cognitive search
tests are skipped. However the same implementation has been tested in my
code repo:
https://github.com/Azure-Samples/azure-search-openai-demo-java
  • Loading branch information
dantelmomsft authored Oct 3, 2023
1 parent e972ee8 commit 6cad2f2
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public Mono<Collection<Tuple2<MemoryRecord, Float>>> getNearestMatchesAsync(
SearchOptions searchOptions = new SearchOptions().setVectors(searchVector);

return client.search(null, searchOptions)
.filter(result -> (double) minRelevanceScore >= result.getScore())
.filter(result -> (double) minRelevanceScore <= result.getScore())
.map(
result -> {
MemoryRecord memoryRecord =
Expand Down Expand Up @@ -418,7 +418,7 @@ record -> {
* @param indexName Index name
* @return Search client ready to read/write
*/
private SearchAsyncClient getSearchClient(@Nonnull String indexName) {
protected SearchAsyncClient getSearchClient(@Nonnull String indexName) {
String normalizedIndexName = normalizeIndexName(indexName);
return _clientsByIndex.computeIfAbsent(
normalizedIndexName, _adminClient::getSearchAsyncClient);
Expand Down

0 comments on commit 6cad2f2

Please sign in to comment.