Skip to content

Java: searchAsync does not limit the number of results #2572

@dsanchor

Description

@dsanchor

Describe the bug

When running a search in memory and limiting the results to certain number, I have noticed that this limit is not taken into account.

For instance, if I set a limit of 4 results, I am getting result entries above that number.

To Reproduce

  1. Create a Kernel with Memory (AzureCognitiveSearchMemory in this case)

     String modelId="gpt-35-turbo";
     String acsEndpoint="yourAcsEndpoint";
     String acsApiKey="yourAcsApiKey";
     Kernel kernel = SKBuilders.kernel()
             .withDefaultAIService(SKBuilders.chatCompletion()
                     .setModelId(modelId)
                     .withOpenAIClient(client)
                     .build())
             .withMemory(new AzureCognitiveSearchMemory(acsEndpoint, acsApiKey))
             .build();
    
  2. Perform a search using this kernel:

     String collection = "yourcollection";
     String query = "yourquery";
     int limit= 10;
     System.out.println("Limit is " + limit);
     List<MemoryQueryResult> result = kernel.
                                         .getMemory()
                                         .searchAsync(collection, 
                                             query, limit, 0.7, false)
                                         .block();
     System.out.println("Returning " + result.size() + " results");
    

Expected behavior
The search should return an amount of result entries below or equals than the limit set.

Screenshots
image

Platform

  • OS: Linux
  • IDE: VS Code
  • Language: Java
  • Source: 0.2.8-alpha

Metadata

Metadata

Assignees

Labels

javaIssue or PR regarding Java code

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions