Skip to content

Commit 308210d

Browse files
Merge branch '246-add-geo-vector-distance-type' into 'dev'
Add 'Geo' vector distance type #246 See merge request objectbox/objectbox-java!149
2 parents b5ad1d7 + 665f3d1 commit 308210d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ For more insights into what changed in the ObjectBox C++ core, [check the Object
99
- Android: require Android 5.0 (API level 21) or higher.
1010
- JVM: ObjectBox might crash on Windows when creating a BoxStore. To resolve this, make sure to update your JDK to the
1111
latest patch release (8.0.432+6, 11.0.25+9, 17.0.13+11 and 21.0.5+11-LTS are known to work).
12+
- Vector Search: add new `VectorDistanceType.GEO` distance type to perform vector searches on geographical coordinates.
13+
This is particularly useful for location-based applications.
1214

1315
## 4.0.3 - 2024-10-15
1416

objectbox-java-api/src/main/java/io/objectbox/annotation/VectorDistanceType.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2024-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,6 +49,19 @@ public enum VectorDistanceType {
4949
*/
5050
DOT_PRODUCT,
5151

52+
/**
53+
* For geospatial coordinates, more specifically latitude and longitude pairs.
54+
* <p>
55+
* Note, the vector dimension should be 2, with the latitude being the first element and longitude the second.
56+
* If the vector has more than 2 dimensions, only the first 2 dimensions are used.
57+
* If the vector has fewer than 2 dimensions, the distance is always zero.
58+
* <p>
59+
* Internally, this uses haversine distance.
60+
* <p>
61+
* Value range: 0 km - 6371 * π km (approx. 20015.09 km; half the Earth's circumference)
62+
*/
63+
GEO,
64+
5265
/**
5366
* A custom dot product similarity measure that does not require the vectors to be normalized.
5467
* <p>

objectbox-java/src/main/java/io/objectbox/model/HnswDistanceType.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ private HnswDistanceType() { }
4444
* Value range (normalized vectors): 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
4545
*/
4646
public static final short DotProduct = 3;
47+
/**
48+
* For geospatial coordinates aka latitude/longitude pairs.
49+
* Note, that the vector dimension must be 2, with the latitude being the first element and longitude the second.
50+
* Internally, this uses haversine distance.
51+
*/
52+
public static final short Geo = 6;
4753
/**
4854
* A custom dot product similarity measure that does not require the vectors to be normalized.
4955
* Note: this is no replacement for cosine similarity (like DotProduct for normalized vectors is).
@@ -54,7 +60,7 @@ private HnswDistanceType() { }
5460
*/
5561
public static final short DotProductNonNormalized = 10;
5662

57-
public static final String[] names = { "Unknown", "Euclidean", "Cosine", "DotProduct", "", "", "", "", "", "", "DotProductNonNormalized", };
63+
public static final String[] names = { "Unknown", "Euclidean", "Cosine", "DotProduct", "", "", "Geo", "", "", "", "DotProductNonNormalized", };
5864

5965
public static String name(int e) { return names[e]; }
6066
}

0 commit comments

Comments
 (0)