objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

Docs: explain how to use Vector Search maxResultCount combined with additional criteria

Open jonny07 opened this issue 7 months ago • 2 comments

Is there an existing issue?

Build info

  • objectbox version: [4.0.1]
  • Flutter/Dart version: [Flutter 3.22.3, Dart 3.4.4]
  • Build OS: [Windows 11]
  • Deployment OS or device: [Android 10, API29, Huawei P30 Pro]

Steps to reproduce

TODO Tell us exactly how to reproduce the problem.

  1. create a query for vector search, I did with embeddings, want to have 2 results: final query = box .query(Message_.embedding.nearestNeighborsF32(search_embedding, 2)) .build(); => Works fine

  2. combine the search with a second criteria. final query = box .query( Message_.embedding.nearestNeighborsF32(search_embedding, 2) .and( Message_.chatid.equals(character)) ).build();

=> Results given are 0 or 1 or 2 results. Expected are 2 results.

I assume that the first condition is fulfilled, it searches for 2 results independent of the second criteria. Then second criteria is applied and from 2 results only 1 or 0 or 2 remain.

Expected behavior

Find 2 results with vector search also with additional conditions.

Actual behavior

Amount of results vary, depending on if the found results of step 1 fulfill the second criteria or not.

Note after analysis

In your documentation the following I assume will also not work as expected: https://docs.objectbox.io/on-device-vector-search final query = box .query(City_.location.nearestNeighborsF32(madrid, 2) .and(City_.name.startsWith("B"))) .build();

Just figured out that I could probably use "limit" from here https://docs.objectbox.io/queries in the "query" and leave the limit out in the "vector search" (leave it out is not possible, I just set it to several million). Would just be a question to you how this will work regarding ressources, how the vector search is implemented, but assume that will work. Another workaround for me might be to work with a stream and interrupt the stream after 2 results.

So it might not be a bug, maybe just the documentation above needs to be adopted.

jonny07 avatar Aug 02 '24 14:08 jonny07