17
17
import os
18
18
import platform
19
19
from objectbox .version import Version
20
+ from typing import *
20
21
21
22
# This file contains C-API bindings based on lib/objectbox.h, linking to the 'objectbox' shared library.
22
23
# The bindings are implementing using ctypes, see https://docs.python.org/dev/library/ctypes.html for introduction.
@@ -72,6 +73,8 @@ def shlib_name(library: str) -> str:
72
73
OBXDebugFlags = ctypes .c_int
73
74
OBXPutMode = ctypes .c_int
74
75
OBXOrderFlags = ctypes .c_int
76
+ OBXHnswFlags = ctypes .c_int
77
+ OBXHnswDistanceType = ctypes .c_int
75
78
76
79
77
80
class OBX_model (ctypes .Structure ):
@@ -115,6 +118,27 @@ class OBX_bytes_array(ctypes.Structure):
115
118
OBX_bytes_array_p = ctypes .POINTER (OBX_bytes_array )
116
119
117
120
121
+ class OBX_bytes_score (ctypes .Structure ):
122
+ _fields_ = [
123
+ ('data' , ctypes .c_void_p ),
124
+ ('size' , ctypes .c_size_t ),
125
+ ('score' , ctypes .c_double ),
126
+ ]
127
+
128
+
129
+ OBX_bytes_score_p = ctypes .POINTER (OBX_bytes_score )
130
+
131
+
132
+ class OBX_bytes_score_array (ctypes .Structure ):
133
+ _fields_ = [
134
+ ('bytes_scores' , OBX_bytes_score_p ),
135
+ ('count' , ctypes .c_size_t ),
136
+ ]
137
+
138
+
139
+ OBX_bytes_score_array_p = ctypes .POINTER (OBX_bytes_score_array )
140
+
141
+
118
142
class OBX_id_array (ctypes .Structure ):
119
143
_fields_ = [
120
144
('ids' , ctypes .POINTER (obx_id )),
@@ -125,6 +149,26 @@ class OBX_id_array(ctypes.Structure):
125
149
OBX_id_array_p = ctypes .POINTER (OBX_id_array )
126
150
127
151
152
+ class OBX_id_score (ctypes .Structure ):
153
+ _fields_ = [
154
+ ('id' , obx_id ),
155
+ ('score' , ctypes .c_double )
156
+ ]
157
+
158
+
159
+ OBX_id_score_p = ctypes .POINTER (OBX_id_score )
160
+
161
+
162
+ class OBX_id_score_array (ctypes .Structure ):
163
+ _fields_ = [
164
+ ('ids_scores' , ctypes .POINTER (OBX_id_score )),
165
+ ('count' , ctypes .c_size_t )
166
+ ]
167
+
168
+
169
+ OBX_id_score_array_p = ctypes .POINTER (OBX_id_score_array )
170
+
171
+
128
172
class OBX_txn (ctypes .Structure ):
129
173
pass
130
174
@@ -223,7 +267,7 @@ def check_result(result, func, args):
223
267
224
268
# creates a global function "name" with the given restype & argtypes, calling C function with the same name.
225
269
# restype is used for error checking: if not None, check_result will throw an exception if the result is empty.
226
- def c_fn (name : str , restype : type , argtypes ):
270
+ def c_fn (name : str , restype : Optional [ type ] , argtypes ):
227
271
func = C .__getattr__ (name )
228
272
func .argtypes = argtypes
229
273
func .restype = restype
@@ -272,8 +316,38 @@ def c_voidp_as_bytes(voidp, size):
272
316
[OBX_model_p , ctypes .c_char_p , OBXPropertyType , obx_schema_id , obx_uid ])
273
317
274
318
# obx_err (OBX_model* model, OBXPropertyFlags flags);
275
- obx_model_property_flags = c_fn_rc ('obx_model_property_flags' , [
276
- OBX_model_p , OBXPropertyFlags ])
319
+ obx_model_property_flags = c_fn_rc ('obx_model_property_flags' , [OBX_model_p , OBXPropertyFlags ])
320
+
321
+ # obx_err obx_model_property_index_id(OBX_model* model, obx_schema_id index_id, obx_uid index_uid)
322
+ obx_model_property_index_id = c_fn_rc ('obx_model_property_index_id' , [OBX_model_p , obx_schema_id , obx_uid ])
323
+
324
+ # obx_err obx_model_property_index_hnsw_dimensions(OBX_model* model, size_t value)
325
+ obx_model_property_index_hnsw_dimensions = \
326
+ c_fn_rc ('obx_model_property_index_hnsw_dimensions' , [OBX_model_p , ctypes .c_size_t ])
327
+
328
+ # obx_err obx_model_property_index_hnsw_neighbors_per_node(OBX_model* model, uint32_t value)
329
+ obx_model_property_index_hnsw_neighbors_per_node = \
330
+ c_fn_rc ('obx_model_property_index_hnsw_neighbors_per_node' , [OBX_model_p , ctypes .c_uint32 ])
331
+
332
+ # obx_err obx_model_property_index_hnsw_indexing_search_count(OBX_model* model, uint32_t value)
333
+ obx_model_property_index_hnsw_indexing_search_count = \
334
+ c_fn_rc ('obx_model_property_index_hnsw_indexing_search_count' , [OBX_model_p , ctypes .c_uint32 ])
335
+
336
+ # obx_err obx_model_property_index_hnsw_flags(OBX_model* model, OBXHnswFlags value)
337
+ obx_model_property_index_hnsw_flags = \
338
+ c_fn_rc ('obx_model_property_index_hnsw_flags' , [OBX_model_p , OBXHnswFlags ])
339
+
340
+ # obx_err obx_model_property_index_hnsw_distance_type(OBX_model* model, OBXHnswDistanceType value)
341
+ obx_model_property_index_hnsw_distance_type = \
342
+ c_fn_rc ('obx_model_property_index_hnsw_distance_type' , [OBX_model_p , OBXHnswDistanceType ])
343
+
344
+ # obx_err obx_model_property_index_hnsw_reparation_backlink_probability(OBX_model* model, float value)
345
+ obx_model_property_index_hnsw_reparation_backlink_probability = \
346
+ c_fn_rc ('obx_model_property_index_hnsw_reparation_backlink_probability' , [OBX_model_p , ctypes .c_float ])
347
+
348
+ # obx_err obx_model_property_index_hnsw_vector_cache_hint_size_kb(OBX_model* model, size_t value)
349
+ obx_model_property_index_hnsw_vector_cache_hint_size_kb = \
350
+ c_fn_rc ('obx_model_property_index_hnsw_vector_cache_hint_size_kb' , [OBX_model_p , ctypes .c_size_t ])
277
351
278
352
# obx_err (OBX_model*, obx_schema_id entity_id, obx_uid entity_uid);
279
353
obx_model_last_entity_id = c_fn ('obx_model_last_entity_id' , None , [
@@ -536,9 +610,20 @@ def c_voidp_as_bytes(voidp, size):
536
610
# OBX_C_API obx_err obx_qb_param_alias(OBX_query_builder* builder, const char* alias);
537
611
obx_qb_param_alias = c_fn_rc ('obx_qb_param_alias' , [OBX_query_builder_p , ctypes .c_char_p ])
538
612
613
+ # OBX_C_API obx_err obx_query_param_vector_float32(OBX_query* query, obx_schema_id entity_id, obx_schema_id property_id, const float* value, size_t element_count);
614
+ # TODO
615
+
616
+ # OBX_C_API obx_err obx_query_param_alias_vector_float32(OBX_query* query, const char* alias, const float* value, size_t element_count);
617
+ # TODO
618
+
539
619
# OBX_C_API obx_err obx_qb_order(OBX_query_builder* builder, obx_schema_id property_id, OBXOrderFlags flags);
540
620
obx_qb_order = c_fn_rc ('obx_qb_order' , [OBX_query_builder_p , obx_schema_id , OBXOrderFlags ])
541
621
622
+ # OBX_C_API obx_qb_cond obx_qb_nearest_neighbors_f32(OBX_query_builder* builder, obx_schema_id vector_property_id, const float* query_vector, size_t max_result_count)
623
+ obx_qb_nearest_neighbors_f32 = \
624
+ c_fn ('obx_qb_nearest_neighbors_f32' , obx_qb_cond , [OBX_query_builder_p , obx_schema_id ,
625
+ ctypes .pointer (ctypes .c_float ), ctypes .c_size_t ])
626
+
542
627
# OBX_C_API OBX_query* obx_query(OBX_query_builder* builder);
543
628
obx_query = c_fn ('obx_query' , OBX_query_p , [OBX_query_builder_p ])
544
629
@@ -566,6 +651,9 @@ def c_voidp_as_bytes(voidp, size):
566
651
# OBX_C_API obx_err obx_query_find_unique(OBX_query* query, const void** data, size_t* size);
567
652
obx_query_find_unique = c_fn_rc ('obx_query_find_unique' , [OBX_query_p , ctypes .POINTER (ctypes .c_void_p ), ctypes .POINTER (ctypes .c_size_t )])
568
653
654
+ # OBX_C_API OBX_bytes_score_array* obx_query_find_with_scores(OBX_query* query);
655
+ obx_query_find_with_scores = c_fn ('obx_query_find_with_scores' , OBX_bytes_score_array_p , [OBX_query_p ]) # TODO
656
+
569
657
# typedef bool obx_data_visitor(void* user_data, const void* data, size_t size);
570
658
571
659
# OBX_C_API obx_err obx_query_visit(OBX_query* query, obx_data_visitor* visitor, void* user_data);
@@ -574,6 +662,9 @@ def c_voidp_as_bytes(voidp, size):
574
662
# OBX_C_API OBX_id_array* obx_query_find_ids(OBX_query* query);
575
663
obx_query_find_ids = c_fn ('obx_query_find_ids' , OBX_id_array_p , [OBX_query_p ])
576
664
665
+ # OBX_C_API OBX_id_score_array* obx_query_find_ids_with_scores(OBX_query* query);
666
+ obx_query_find_ids_with_scores = c_fn ('obx_query_find_ids_with_scores' , OBX_id_score_array_p , [OBX_query_p ]) # TODO
667
+
577
668
# OBX_C_API obx_err obx_query_count(OBX_query* query, uint64_t* out_count);
578
669
obx_query_count = c_fn_rc ('obx_query_count' , [OBX_query_p , ctypes .POINTER (ctypes .c_uint64 )])
579
670
@@ -596,6 +687,12 @@ def c_voidp_as_bytes(voidp, size):
596
687
# void (OBX_bytes_array * array);
597
688
obx_bytes_array_free = c_fn ('obx_bytes_array_free' , None , [OBX_bytes_array_p ])
598
689
690
+ # OBX_C_API void obx_bytes_score_array_free(OBX_bytes_score_array* array)
691
+ obx_bytes_score_array_free = c_fn ('obx_bytes_score_array_free' , None , [OBX_bytes_score_array_p ])
692
+
693
+ # OBX_C_API void obx_id_score_array_free(OBX_id_score_array* array)
694
+ obx_id_score_array_free = c_fn ('obx_id_score_array_free' , None , [OBX_id_score_array_p ])
695
+
599
696
OBXPropertyType_Bool = 1
600
697
OBXPropertyType_Byte = 2
601
698
OBXPropertyType_Short = 3
@@ -669,3 +766,12 @@ def c_voidp_as_bytes(voidp, size):
669
766
670
767
# null values should be treated equal to zero (scalars only).
671
768
OBXOrderFlags_NULLS_ZERO = 16
769
+
770
+ OBXHnswFlags_NONE = 0
771
+ OBXHnswFlags_DEBUG_LOGS = 1
772
+ OBXHnswFlags_DEBUG_LOGS_DETAILED = 2
773
+ OBXHnswFlags_VECTOR_CACHE_SIMD_PADDING_OFF = 4
774
+ OBXHnswFlags_REPARATION_LIMIT_CANDIDATES = 8
775
+
776
+ OBXHnswDistanceType_UNKNOWN = 0
777
+ OBXHnswDistanceType_EUCLIDEAN = 1
0 commit comments