|
1 | 1 | /*
|
2 |
| - * Copyright 2017-2019 ObjectBox Ltd. All rights reserved. |
| 2 | + * Copyright 2017-2024 ObjectBox Ltd. All rights reserved. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
22 | 22 |
|
23 | 23 | import javax.annotation.Nullable;
|
24 | 24 |
|
| 25 | +import io.objectbox.annotation.HnswIndex; |
25 | 26 | import io.objectbox.annotation.apihint.Internal;
|
26 | 27 | import io.objectbox.converter.PropertyConverter;
|
27 | 28 | import io.objectbox.exception.DbException;
|
|
33 | 34 | import io.objectbox.query.PropertyQueryConditionImpl.LongArrayCondition;
|
34 | 35 | import io.objectbox.query.PropertyQueryConditionImpl.LongCondition;
|
35 | 36 | import io.objectbox.query.PropertyQueryConditionImpl.LongLongCondition;
|
| 37 | +import io.objectbox.query.PropertyQueryConditionImpl.NearestNeighborCondition; |
36 | 38 | import io.objectbox.query.PropertyQueryConditionImpl.NullCondition;
|
37 | 39 | import io.objectbox.query.PropertyQueryConditionImpl.StringArrayCondition;
|
38 | 40 | import io.objectbox.query.PropertyQueryConditionImpl.StringCondition;
|
@@ -302,6 +304,22 @@ public PropertyQueryCondition<ENTITY> between(double lowerBoundary, double upper
|
302 | 304 | lowerBoundary, upperBoundary);
|
303 | 305 | }
|
304 | 306 |
|
| 307 | + /** |
| 308 | + * Performs an approximate nearest neighbor (ANN) search to find objects near to the given {@code queryVector}. |
| 309 | + * <p> |
| 310 | + * This requires the vector property to have an {@link HnswIndex}. |
| 311 | + * <p> |
| 312 | + * The dimensions of the query vector should be at least the dimensions of this vector property. |
| 313 | + * <p> |
| 314 | + * Use {@code maxResultCount} to set the maximum number of objects to return by the ANN condition. Hint: it can also |
| 315 | + * be used as the "ef" HNSW parameter to increase the search quality in combination with a query limit. For example, |
| 316 | + * use maxResultCount of 100 with a Query limit of 10 to have 10 results that are of potentially better quality than |
| 317 | + * just passing in 10 for maxResultCount (quality/performance tradeoff). |
| 318 | + */ |
| 319 | + public PropertyQueryCondition<ENTITY> nearestNeighborsF32(float[] queryVector, int maxResultCount) { |
| 320 | + return new NearestNeighborCondition<>(this, queryVector, maxResultCount); |
| 321 | + } |
| 322 | + |
305 | 323 | /** Creates an "equal ('=')" condition for this property. */
|
306 | 324 | public PropertyQueryCondition<ENTITY> equal(Date value) {
|
307 | 325 | return new LongCondition<>(this, LongCondition.Operation.EQUAL, value);
|
|
0 commit comments