25
25
26
26
class Vector (ABC ):
27
27
"""
28
- Base class that represents a Vector
28
+ Base class that represents a Vector.
29
+
30
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
29
31
"""
30
32
31
33
def __init__ (self ) -> None :
@@ -38,7 +40,9 @@ def __init__(self) -> None:
38
40
@proxy ("ai.BitVector" )
39
41
class BitVector (Vector ):
40
42
"""
41
- Class that represents a Vector of Bits
43
+ Class that represents a Vector of Bits.
44
+
45
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
42
46
"""
43
47
44
48
def __init__ (
@@ -48,11 +52,11 @@ def __init__(
48
52
int_array : Optional [List [int ]] = None ,
49
53
):
50
54
"""
51
- Creates an instance of BitVector
55
+ Creates an instance of BitVector.
52
56
53
- :param hex_string: hexadecimal string used to create the BitVector
54
- :param byte_array: optional byte array used to create the BitVector
55
- :param int_array: optional int array used to create the BitVector
57
+ :param hex_string: hexadecimal string used to create the BitVector.
58
+ :param byte_array: optional byte array used to create the BitVector.
59
+ :param int_array: optional int array used to create the BitVector.
56
60
"""
57
61
super ().__init__ ()
58
62
if hex_string is not None :
@@ -72,14 +76,16 @@ def __init__(
72
76
@proxy ("ai.Int8Vector" )
73
77
class ByteVector (Vector ):
74
78
"""
75
- Class that represents Vector of bytes
79
+ Class that represents Vector of bytes.
80
+
81
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
76
82
"""
77
83
78
84
def __init__ (self , byte_array : bytes ):
79
85
"""
80
- Creates an instance of ByteVector
86
+ Creates an instance of ByteVector.
81
87
82
- :param byte_array: byte array used to create a ByteVector
88
+ :param byte_array: byte array used to create a ByteVector.
83
89
"""
84
90
super ().__init__ ()
85
91
self .array = base64 .b64encode (byte_array ).decode ("UTF-8" )
@@ -88,14 +94,16 @@ def __init__(self, byte_array: bytes):
88
94
@proxy ("ai.Float32Vector" )
89
95
class FloatVector (Vector ):
90
96
"""
91
- Class that represents Vector of floats
97
+ Class that represents Vector of floats.
98
+
99
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
92
100
"""
93
101
94
102
def __init__ (self , float_array : List [float ]):
95
103
"""
96
- Creates an instance of FloatVector
104
+ Creates an instance of FloatVector.
97
105
98
- :param float_array: array of floats used to create a FloatVector
106
+ :param float_array: array of floats used to create a FloatVector.
99
107
"""
100
108
super ().__init__ ()
101
109
self .array = float_array
@@ -111,20 +119,22 @@ def __init__(self, data_version: int = 0, bin_future: Optional[Any] = None):
111
119
class DocumentChunk (AbstractEvolvable ):
112
120
"""
113
121
Class that represents a chunk of text extracted from a document.
122
+
123
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
114
124
"""
115
125
116
126
def __init__ (
117
127
self ,
118
128
text : str ,
119
- metadata : Optional [Dict [str , Any ] | OrderedDict [str , Any ]] = None ,
129
+ metadata : Optional [Union [ Dict [str , Any ], OrderedDict [str , Any ] ]] = None ,
120
130
vector : Optional [Vector ] = None ,
121
131
):
122
132
"""
123
- Creates an instance of DocumentChunk class
133
+ Creates an instance of DocumentChunk class.
124
134
125
- :param text: the chunk of text extracted from a document
126
- :param metadata: optional document metadata
127
- :param vector: the vector associated with the document chunk
135
+ :param text: the chunk of text extracted from a document.
136
+ :param metadata: optional document metadata.
137
+ :param vector: the vector associated with the document chunk.
128
138
"""
129
139
super ().__init__ ()
130
140
self .text = text
@@ -182,7 +192,9 @@ def restore(self, obj: Dict[str, Any]) -> DocumentChunk:
182
192
183
193
class DistanceAlgorithm (ABC ):
184
194
"""
185
- Base class that represents algorithm that can calculate distance to a given vector
195
+ Base class that represents algorithm that can calculate distance to a given vector.
196
+
197
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
186
198
"""
187
199
188
200
def __init__ (self ) -> None :
@@ -198,6 +210,8 @@ class CosineDistance(DistanceAlgorithm):
198
210
between two vectors and determines whether two vectors are pointing in
199
211
roughly the same direction. It is often used to measure document similarity
200
212
in text analysis.
213
+
214
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
201
215
"""
202
216
203
217
def __init__ (self ) -> None :
@@ -209,6 +223,8 @@ class InnerProductDistance(DistanceAlgorithm):
209
223
"""
210
224
Represents a DistanceAlgorithm that performs inner product distance
211
225
calculation between two vectors.
226
+
227
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
212
228
"""
213
229
214
230
def __init__ (self ) -> None :
@@ -220,6 +236,8 @@ class L2SquaredDistance(DistanceAlgorithm):
220
236
"""
221
237
Represents a DistanceAlgorithm that performs an L2 squared distance
222
238
calculation between two vectors.
239
+
240
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
223
241
"""
224
242
225
243
def __init__ (self ) -> None :
@@ -230,6 +248,8 @@ def __init__(self) -> None:
230
248
class SimilaritySearch (EntryAggregator ):
231
249
"""
232
250
This class represents an aggregator to execute a similarity query.
251
+
252
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
233
253
"""
234
254
235
255
def __init__ (
@@ -247,10 +267,10 @@ def __init__(
247
267
specified `vector`.
248
268
249
269
:param extractor_or_property: the ValueExtractor to extract the vector
250
- from the cache value
251
- :param vector: the vector to calculate similarity with
252
- :param max_results: the maximum number of results to return
253
- :param algorithm: the distance algorithm to use
270
+ from the cache value.
271
+ :param vector: the vector to calculate similarity with.
272
+ :param max_results: the maximum number of results to return.
273
+ :param algorithm: the distance algorithm to use.
254
274
:param filter: filter to use to limit the set of entries to search.
255
275
:param brute_force: Force brute force search, ignoring any available indexes.
256
276
"""
@@ -264,7 +284,9 @@ def __init__(
264
284
265
285
class BaseQueryResult (ABC ):
266
286
"""
267
- A base class for QueryResult implementation
287
+ A base class for QueryResult implementation.
288
+
289
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
268
290
"""
269
291
270
292
def __init__ (self , result : float , key : K , value : V ) -> None :
@@ -276,16 +298,18 @@ def __init__(self, result: float, key: K, value: V) -> None:
276
298
@proxy ("ai.results.QueryResult" )
277
299
class QueryResult (BaseQueryResult ):
278
300
"""
279
- QueryResult class
301
+ QueryResult class.
302
+
303
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
280
304
"""
281
305
282
306
def __init__ (self , result : float , key : K , value : V ) -> None :
283
307
"""
284
- Creates an instance of the QueryResult class
308
+ Creates an instance of the QueryResult class.
285
309
286
- :param result: the query result
287
- :param key: the key of the vector the result applies to
288
- :param value: the optional result value
310
+ :param result: the query result.
311
+ :param key: the key of the vector the result applies to.
312
+ :param value: the optional result value.
289
313
"""
290
314
super ().__init__ (result , key , value )
291
315
@@ -296,15 +320,17 @@ def __str__(self) -> str:
296
320
@proxy ("ai.index.BinaryQuantIndex" )
297
321
class BinaryQuantIndex (AbstractEvolvable ):
298
322
"""
299
- This class represents a custom index using binary quantization of vectors
323
+ This class represents a custom index using binary quantization of vectors.
324
+
325
+ **NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
300
326
"""
301
327
302
328
def __init__ (self , extractor : Union [ValueExtractor [T , E ], str ], over_sampling_factor : int = 3 ) -> None :
303
329
"""
304
- Creates an instance of BinaryQuantIndex class
330
+ Creates an instance of BinaryQuantIndex class.
305
331
306
- :param extractor: the ValueExtractor to use to extract the Vector
307
- :param over_sampling_factor: the oversampling factor
332
+ :param extractor: the ValueExtractor to use to extract the Vector.
333
+ :param over_sampling_factor: the oversampling factor.
308
334
"""
309
335
super ().__init__ ()
310
336
self .extractor = extractor
0 commit comments