Skip to content

Commit 14fbc80

Browse files
committed
HnswDistanceType Enum docs #30
1 parent e94ea03 commit 14fbc80

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

objectbox/model/properties.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import numpy as np
2121
from dataclasses import dataclass
2222

23-
2423
class PropertyType(IntEnum):
2524
bool = OBXPropertyType_Bool
2625
byte = OBXPropertyType_Byte
@@ -101,6 +100,26 @@ class HnswDistanceType(IntEnum):
101100
DOT_PRODUCT = OBXHnswDistanceType_DOT_PRODUCT
102101
DOT_PRODUCT_NON_NORMALIZED = OBXHnswDistanceType_DOT_PRODUCT_NON_NORMALIZED
103102

103+
HnswDistanceType.UNKNOWN.__doc__ = "Not a real type, just best practice (e.g. forward compatibility)"
104+
HnswDistanceType.EUCLIDEAN.__doc__ = "The default; typically 'euclidean squared' internally."
105+
HnswDistanceType.COSINE.__doc__ = """
106+
Cosine similarity compares two vectors irrespective of their magnitude (compares the angle of two vectors).
107+
Often used for document or semantic similarity.
108+
Value range: 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
109+
"""
110+
HnswDistanceType.DOT_PRODUCT.__doc__ = """
111+
For normalized vectors (vector length == 1.0), the dot product is equivalent to the cosine similarity.
112+
Because of this, the dot product is often preferred as it performs better.
113+
Value range (normalized vectors): 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
114+
"""
115+
HnswDistanceType.DOT_PRODUCT_NON_NORMALIZED.__doc__ = """
116+
A custom dot product similarity measure that does not require the vectors to be normalized.
117+
Note: this is no replacement for cosine similarity (like DotProduct for normalized vectors is).
118+
The non-linear conversion provides a high precision over the entire float range (for the raw dot product).
119+
The higher the dot product, the lower the distance is (the nearer the vectors are).
120+
The more negative the dot product, the higher the distance is (the farther the vectors are).
121+
Value range: 0.0 - 2.0 (nonlinear; 0.0: nearest, 1.0: orthogonal, 2.0: farthest)
122+
"""
104123

105124
@dataclass
106125
class HnswIndex:

0 commit comments

Comments
 (0)