|
20 | 20 | import numpy as np
|
21 | 21 | from dataclasses import dataclass
|
22 | 22 |
|
23 |
| - |
24 | 23 | class PropertyType(IntEnum):
|
25 | 24 | bool = OBXPropertyType_Bool
|
26 | 25 | byte = OBXPropertyType_Byte
|
@@ -101,6 +100,26 @@ class HnswDistanceType(IntEnum):
|
101 | 100 | DOT_PRODUCT = OBXHnswDistanceType_DOT_PRODUCT
|
102 | 101 | DOT_PRODUCT_NON_NORMALIZED = OBXHnswDistanceType_DOT_PRODUCT_NON_NORMALIZED
|
103 | 102 |
|
| 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 | +""" |
104 | 123 |
|
105 | 124 | @dataclass
|
106 | 125 | class HnswIndex:
|
|
0 commit comments