@taladb/react-native 0.11.3 → 0.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -643,6 +643,24 @@ Value TalaDBHostObject::get(Runtime &rt, const PropNameID &propName) {
643
643
  });
644
644
  }
645
645
 
646
+ // ------------------------------------------------------------------
647
+ // rebuildVectorIndexes(): void
648
+ //
649
+ // Warms every HNSW graph in the database. The graphs are memory-only, so
650
+ // without this findNearest silently degrades to an exact linear scan for
651
+ // the whole process lifetime. Scans every indexed vector — call it once at
652
+ // startup, off the first frame.
653
+ // ------------------------------------------------------------------
654
+ if (name == "rebuildVectorIndexes") {
655
+ return Function::createFromHostFunction(
656
+ rt, PropNameID::forAscii(rt, "rebuildVectorIndexes"), 0,
657
+ [this](Runtime &rt, const Value &, const Value *, size_t) -> Value {
658
+ int32_t res = taladb_rebuild_hnsw_indexes(db_);
659
+ if (res < 0) throw ffiError(rt, "taladb_rebuild_hnsw_indexes failed");
660
+ return Value::undefined();
661
+ });
662
+ }
663
+
646
664
  // ------------------------------------------------------------------
647
665
  // findNearest(collection, field, query, topK, filter?): { document, score }[]
648
666
  // query — Float32Array (preferred, zero-copy) or number[]
@@ -799,7 +817,7 @@ Value TalaDBHostObject::get(Runtime &rt, const PropNameID &propName) {
799
817
  if (name == "close") {
800
818
  return Function::createFromHostFunction(
801
819
  rt, PropNameID::forAscii(rt, "close"), 0,
802
- [this](Runtime &rt, const Value &, const Value *, size_t) -> Value {
820
+ [this](Runtime &, const Value &, const Value *, size_t) -> Value {
803
821
  if (db_) {
804
822
  taladb_close(db_);
805
823
  db_ = nullptr;
package/cpp/taladb.h CHANGED
@@ -1,13 +1,13 @@
1
- #pragma once
2
- #ifndef TALADB_FFI_H
3
- #define TALADB_FFI_H
4
-
5
1
  /*
6
2
  * TalaDB C FFI header.
7
3
  *
8
- * This file is the stable C interface between the Rust taladb-ffi crate and
9
- * the C++ JSI HostObject. It is kept in sync with rust/src/lib.rs manually
10
- * (or regenerated with cbindgen — see rust/cbindgen.toml).
4
+ * GENERATED FILE — do not edit. Regenerate with:
5
+ * pnpm --filter @taladb/react-native build:cbindgen
6
+ * CI fails if this file and rust/src/lib.rs disagree.
7
+ *
8
+ * This is the stable C interface between the Rust taladb-ffi crate and the C++
9
+ * JSI HostObject (cpp/TalaDBHostObject.cpp, cpp/TalaDBJni.cpp) and the iOS
10
+ * TurboModule (ios/TalaDB.mm).
11
11
  *
12
12
  * Ownership rules
13
13
  * ---------------
@@ -15,293 +15,383 @@
15
15
  * - Strings OUT : heap-allocated by Rust; caller must free with
16
16
  * taladb_free_string().
17
17
  * - Handles : allocated by taladb_open(); freed by taladb_close().
18
- * - Errors : string functions return NULL; integer functions return -1.
18
+ * - Errors : string functions return NULL; integer functions return -1,
19
+ * with detail available from taladb_last_error().
19
20
  */
20
21
 
22
+
23
+ #ifndef TALADB_FFI_H
24
+ #define TALADB_FFI_H
25
+
26
+ #pragma once
27
+
28
+ #include <stdarg.h>
29
+ #include <stdbool.h>
21
30
  #include <stdint.h>
22
31
  #include <stdlib.h>
23
32
 
24
- #ifdef __cplusplus
25
- extern "C" {
26
- #endif
27
33
 
28
- /* -------------------------------------------------------------------------
29
- * Opaque database handle
30
- * ---------------------------------------------------------------------- */
31
34
  typedef struct TalaDbHandle TalaDbHandle;
32
35
 
33
- /* -------------------------------------------------------------------------
34
- * Lifecycle
35
- * ---------------------------------------------------------------------- */
36
+ /**
37
+ * A background job handle. Opaque to the caller.
38
+ */
39
+ typedef struct TalaDbJob TalaDbJob;
36
40
 
37
- /** Open (or create) a database at the given file-system path. */
38
- TalaDbHandle *taladb_open(const char *path);
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif // __cplusplus
39
44
 
40
45
  /**
41
- * Open (or create) a database with durability/encryption configuration.
46
+ * Return the last error message as a null-terminated C string, or NULL if no error.
47
+ *
48
+ * The message always describes the most recent `taladb_*` call on this thread:
49
+ * every entry point clears the slot before doing any work, so a NULL return
50
+ * means that call succeeded rather than that it forgot to report.
42
51
  *
43
- * config_json — JSON-serialised TalaDbConfig, or NULL for defaults.
44
- * Returns an opaque handle (same semantics as taladb_open), or NULL on failure.
52
+ * The returned pointer is valid until the next taladb_* call on this thread.
53
+ * Do NOT free the returned string.
45
54
  */
46
- TalaDbHandle *taladb_open_with_config(const char *path, const char *config_json);
55
+ const char *taladb_last_error(void);
47
56
 
48
- /** Flush and close the database, freeing the handle. */
49
- void taladb_close(TalaDbHandle *handle);
57
+ /**
58
+ * Open (or create) a TalaDB database at `path`.
59
+ *
60
+ * Returns an opaque handle, or NULL on failure.
61
+ * The handle must be freed with `taladb_close`.
62
+ */
63
+ struct TalaDbHandle *taladb_open(const char *path);
50
64
 
51
65
  /**
52
- * Compact the underlying storage file, reclaiming space freed by deletes and
53
- * updates. No-op on in-memory databases. Returns 1 on success, -1 on error.
66
+ * Open (or create) a TalaDB database at `path` with an optional config.
67
+ *
68
+ * `config_json` — JSON-serialised `TalaDbConfig` (durability, plus an optional
69
+ * `passphrase` for encryption at rest), or NULL for defaults. Change webhooks
70
+ * are delivered by the `taladb` TypeScript client, not by this binding.
71
+ *
72
+ * Unknown config keys are ignored so one config file can be shared with the TS
73
+ * client — **except** a key that differs from `passphrase` only in spelling, and
74
+ * a `passphrase` that is present but not a string. Both are errors rather than
75
+ * a silent unencrypted open; see [`passphrase_from_config`].
76
+ *
77
+ * Returns an opaque handle, or NULL on failure.
78
+ * The handle must be freed with `taladb_close`.
54
79
  */
55
- int32_t taladb_compact(TalaDbHandle *handle);
80
+ struct TalaDbHandle *taladb_open_with_config(const char *path, const char *config_json);
56
81
 
57
- /** Free a C string returned by any taladb_* function. */
58
- void taladb_free_string(char *s);
82
+ /**
83
+ * Compact the underlying storage file for this database handle.
84
+ * No-op on in-memory databases. Returns 1 on success, -1 on error.
85
+ */
86
+ int32_t taladb_compact(struct TalaDbHandle *handle);
59
87
 
60
- /* -------------------------------------------------------------------------
61
- * Insert
62
- * ---------------------------------------------------------------------- */
88
+ /**
89
+ * Close the database and free the handle.
90
+ */
91
+ void taladb_close(struct TalaDbHandle *handle);
63
92
 
64
93
  /**
65
- * Insert a document (JSON object).
94
+ * Free a string returned by any taladb_* function.
95
+ */
96
+ void taladb_free_string(char *s);
97
+
98
+ /**
99
+ * Insert a document (JSON object string).
66
100
  * Returns the new document's ULID as a C string, or NULL on error.
67
- * Caller must free with taladb_free_string().
101
+ * Caller must free the returned string with `taladb_free_string`.
68
102
  */
69
- char *taladb_insert(TalaDbHandle *handle,
70
- const char *collection,
71
- const char *doc_json);
103
+ char *taladb_insert(struct TalaDbHandle *handle, const char *collection, const char *doc_json);
72
104
 
73
105
  /**
74
106
  * Insert multiple documents (JSON array of objects).
75
107
  * Returns a JSON array of ULID strings, or NULL on error.
76
- * Caller must free with taladb_free_string().
108
+ * Caller must free with `taladb_free_string`.
109
+ *
110
+ * **All or nothing.** If any element of the array is not an object, the whole
111
+ * call fails and nothing is written. It previously skipped unparseable
112
+ * elements and returned a shorter id array, so a caller zipping the returned
113
+ * ids back onto its input silently mis-associated every document after the
114
+ * first bad one — and had no way to learn which had been dropped.
77
115
  */
78
- char *taladb_insert_many(TalaDbHandle *handle,
79
- const char *collection,
80
- const char *docs_json);
81
-
82
- /* -------------------------------------------------------------------------
83
- * Find
84
- * ---------------------------------------------------------------------- */
116
+ char *taladb_insert_many(struct TalaDbHandle *handle,
117
+ const char *collection,
118
+ const char *docs_json);
85
119
 
86
120
  /**
87
- * Find all documents matching filter_json.
88
- * Pass "{}" or "null" to match all.
121
+ * Find all documents matching `filter_json`.
122
+ * Pass `"{}"` or `"null"` to match all.
89
123
  * Returns a JSON array string, or NULL on error.
90
- * Caller must free with taladb_free_string().
124
+ * Caller must free with `taladb_free_string`.
91
125
  */
92
- char *taladb_find(TalaDbHandle *handle,
93
- const char *collection,
94
- const char *filter_json);
126
+ char *taladb_find(struct TalaDbHandle *handle, const char *collection, const char *filter_json);
95
127
 
96
128
  /**
97
- * Find the first document matching filter_json.
98
- * Returns a JSON object string, or the string "null" if not found.
99
- * Caller must free with taladb_free_string().
129
+ * Find one document matching `filter_json`, or JSON `null` if none.
130
+ * Caller must free with `taladb_free_string`.
100
131
  */
101
- char *taladb_find_one(TalaDbHandle *handle,
102
- const char *collection,
103
- const char *filter_json);
132
+ char *taladb_find_one(struct TalaDbHandle *handle, const char *collection, const char *filter_json);
104
133
 
105
- /* -------------------------------------------------------------------------
106
- * Update
107
- * ---------------------------------------------------------------------- */
134
+ /**
135
+ * Update the first matching document.
136
+ * Returns 1 if updated, 0 if not found, -1 on error.
137
+ */
138
+ int32_t taladb_update_one(struct TalaDbHandle *handle,
139
+ const char *collection,
140
+ const char *filter_json,
141
+ const char *update_json);
108
142
 
109
- /** Update the first matching document. Returns 1 updated, 0 not found, -1 error. */
110
- int32_t taladb_update_one(TalaDbHandle *handle,
111
- const char *collection,
112
- const char *filter_json,
113
- const char *update_json);
143
+ /**
144
+ * Update all matching documents.
145
+ * Returns count updated, or -1 on error.
146
+ */
147
+ int32_t taladb_update_many(struct TalaDbHandle *handle,
148
+ const char *collection,
149
+ const char *filter_json,
150
+ const char *update_json);
114
151
 
115
- /** Update all matching documents. Returns count updated, or -1 on error. */
116
- int32_t taladb_update_many(TalaDbHandle *handle,
117
- const char *collection,
118
- const char *filter_json,
119
- const char *update_json);
152
+ /**
153
+ * Delete the first matching document.
154
+ * Returns 1 if deleted, 0 if not found, -1 on error.
155
+ */
156
+ int32_t taladb_delete_one(struct TalaDbHandle *handle,
157
+ const char *collection,
158
+ const char *filter_json);
120
159
 
121
- /* -------------------------------------------------------------------------
122
- * Delete
123
- * ---------------------------------------------------------------------- */
160
+ /**
161
+ * Delete all matching documents.
162
+ * Returns count deleted, or -1 on error.
163
+ */
164
+ int32_t taladb_delete_many(struct TalaDbHandle *handle,
165
+ const char *collection,
166
+ const char *filter_json);
124
167
 
125
- /** Delete the first matching document. Returns 1 deleted, 0 not found, -1 error. */
126
- int32_t taladb_delete_one(TalaDbHandle *handle,
127
- const char *collection,
128
- const char *filter_json);
168
+ /**
169
+ * Count documents matching `filter_json`.
170
+ * Returns count, or -1 on error.
171
+ */
172
+ int32_t taladb_count(struct TalaDbHandle *handle, const char *collection, const char *filter_json);
129
173
 
130
- /** Delete all matching documents. Returns count deleted, or -1 on error. */
131
- int32_t taladb_delete_many(TalaDbHandle *handle,
132
- const char *collection,
133
- const char *filter_json);
174
+ /**
175
+ * Run an aggregation pipeline (`pipeline_json` is a JSON array of stages).
176
+ * Returns a JSON array of result documents, or NULL on error.
177
+ * Caller must free with `taladb_free_string`.
178
+ */
179
+ char *taladb_aggregate(struct TalaDbHandle *handle,
180
+ const char *collection,
181
+ const char *pipeline_json);
134
182
 
135
- /* -------------------------------------------------------------------------
136
- * Count
137
- * ---------------------------------------------------------------------- */
183
+ /**
184
+ * User collection names (reserved `_`-prefixed excluded), as a JSON array
185
+ * string. Backs the sync orchestration's "sync all collections" default.
186
+ * NULL on error. Caller must free with `taladb_free_string`.
187
+ */
188
+ char *taladb_list_collection_names(struct TalaDbHandle *handle);
138
189
 
139
- /** Count documents matching filter_json. Returns count, or -1 on error. */
140
- int32_t taladb_count(TalaDbHandle *handle,
141
- const char *collection,
142
- const char *filter_json);
190
+ /**
191
+ * Read the current application migration version (0 if never set), or -1 on
192
+ * error. Backs the `openDB({ migrations })` runner.
193
+ */
194
+ int64_t taladb_user_version(struct TalaDbHandle *handle);
143
195
 
144
- /* -------------------------------------------------------------------------
145
- * Aggregate
146
- * ---------------------------------------------------------------------- */
196
+ /**
197
+ * Persist the application migration version. Returns 0 on success, -1 on error.
198
+ */
199
+ int32_t taladb_set_user_version(struct TalaDbHandle *handle, uint32_t version);
147
200
 
148
201
  /**
149
- * Run an aggregation pipeline. pipeline_json is a JSON array of stages.
150
- * Returns a JSON array of result documents, or NULL on error.
151
- * Caller must free with taladb_free_string().
202
+ * Force any batched (eventual-durability) writes to disk. Returns 0 on
203
+ * success, -1 on error. No-op under the default immediate durability.
152
204
  */
153
- char *taladb_aggregate(TalaDbHandle *handle,
154
- const char *collection,
155
- const char *pipeline_json);
205
+ int32_t taladb_flush(struct TalaDbHandle *handle);
156
206
 
157
207
  /**
158
- * User collection names (reserved names excluded) as a JSON array string.
159
- * Returns NULL on error. Caller must free with taladb_free_string().
208
+ * Create a secondary index on `field`. No-op if already exists.
160
209
  */
161
- char *taladb_list_collection_names(TalaDbHandle *handle);
210
+ void taladb_create_index(struct TalaDbHandle *handle, const char *collection, const char *field);
162
211
 
163
212
  /**
164
- * Read / write the application migration version (backs openDB({ migrations })).
165
- * taladb_user_version returns the version (0 if unset) or -1 on error;
166
- * taladb_set_user_version returns 0 on success, -1 on error.
213
+ * Drop a secondary index on `field`.
167
214
  */
168
- int64_t taladb_user_version(TalaDbHandle *handle);
169
- int32_t taladb_set_user_version(TalaDbHandle *handle, uint32_t version);
215
+ void taladb_drop_index(struct TalaDbHandle *handle, const char *collection, const char *field);
170
216
 
171
217
  /**
172
- * Force any batched (eventual-durability) writes to disk. Returns 0 on success,
173
- * -1 on error. No-op under the default immediate durability. Backs db.flush().
218
+ * Create a compound index over `fields_json` (a JSON array of field names).
174
219
  */
175
- int32_t taladb_flush(TalaDbHandle *handle);
220
+ void taladb_create_compound_index(struct TalaDbHandle *handle,
221
+ const char *collection,
222
+ const char *fields_json);
176
223
 
177
- /* -------------------------------------------------------------------------
178
- * Index management
179
- * ---------------------------------------------------------------------- */
224
+ /**
225
+ * Drop a compound index by its ordered field list (`fields_json`).
226
+ */
227
+ void taladb_drop_compound_index(struct TalaDbHandle *handle,
228
+ const char *collection,
229
+ const char *fields_json);
180
230
 
181
- void taladb_create_index (TalaDbHandle *handle, const char *collection, const char *field);
182
- void taladb_drop_index (TalaDbHandle *handle, const char *collection, const char *field);
183
- void taladb_create_fts_index(TalaDbHandle *handle, const char *collection, const char *field);
184
- void taladb_drop_fts_index (TalaDbHandle *handle, const char *collection, const char *field);
231
+ /**
232
+ * Create a full-text search index on `field`.
233
+ */
234
+ void taladb_create_fts_index(struct TalaDbHandle *handle,
235
+ const char *collection,
236
+ const char *field);
185
237
 
186
- /* Compound (multi-field) indexes. fields_json is a JSON array of field names. */
187
- void taladb_create_compound_index(TalaDbHandle *handle, const char *collection, const char *fields_json);
188
- void taladb_drop_compound_index (TalaDbHandle *handle, const char *collection, const char *fields_json);
238
+ /**
239
+ * Drop a full-text search index on `field`.
240
+ */
241
+ void taladb_drop_fts_index(struct TalaDbHandle *handle, const char *collection, const char *field);
189
242
 
190
- /* -------------------------------------------------------------------------
191
- * Vector index management
192
- *
193
- * metric — "cosine" (default), "dot", or "euclidean". NULL ⇒ cosine.
194
- * hnsw_json — JSON-encoded HnswOptions, or NULL for flat index.
195
- * ---------------------------------------------------------------------- */
196
-
197
- int32_t taladb_create_vector_index(TalaDbHandle *handle,
198
- const char *collection,
199
- const char *field,
200
- size_t dimensions,
201
- const char *metric,
202
- const char *hnsw_json);
203
-
204
- int32_t taladb_drop_vector_index (TalaDbHandle *handle, const char *collection, const char *field);
205
- int32_t taladb_upgrade_vector_index(TalaDbHandle *handle, const char *collection, const char *field);
206
-
207
- /* -------------------------------------------------------------------------
208
- * findNearest — Float32 zero-copy fast path
243
+ /**
244
+ * Rank documents against a free-text query using BM25 (OR semantics).
209
245
  *
210
- * query_ptr / query_len address `query_len` consecutive f32 values. Caller
211
- * retains ownership; the buffer may be freed immediately after the call.
212
- * filter_json may be NULL / "{}" / "null" to search without a pre-filter.
246
+ * `filter_json` / `options_json` may be NULL. `options_json` accepts
247
+ * `{ k1, b }`.
213
248
  *
214
249
  * Returns a JSON array string `[{document, score}, ...]`, or NULL on error.
215
- * Caller must free with taladb_free_string.
216
- * ---------------------------------------------------------------------- */
217
-
218
- char *taladb_find_nearest(TalaDbHandle *handle,
219
- const char *collection,
220
- const char *field,
221
- const float *query_ptr,
222
- size_t query_len,
223
- size_t top_k,
224
- const char *filter_json);
225
-
226
- /* BM25 full-text ranking. Returns a JSON array `[{document, score}, ...]`,
227
- * or NULL on error. filter_json / options_json may be NULL. options_json
228
- * accepts `{ k1, b }`. Caller must free with taladb_free_string. */
229
- char *taladb_search_text(TalaDbHandle *handle,
230
- const char *collection,
231
- const char *field,
232
- const char *query,
233
- size_t top_k,
234
- const char *filter_json,
235
- const char *options_json);
236
-
237
- /* Hybrid retrieval (BM25 + vector, fused with RRF). Returns a JSON array
238
- * `[{document, score, textRank, vectorRank}, ...]`, or NULL on error.
239
- * filter_json / options_json may be NULL. options_json accepts
240
- * `{ rrfK, textWeight, vectorWeight, candidates, k1, b }`.
241
- * Caller must free with taladb_free_string. */
242
- char *taladb_hybrid_search(TalaDbHandle *handle,
243
- const char *collection,
244
- const char *text_field,
245
- const char *text,
246
- const char *vector_field,
247
- const float *vector_ptr,
248
- size_t vector_len,
249
- size_t top_k,
250
- const char *filter_json,
251
- const char *options_json);
252
-
253
- /* -------------------------------------------------------------------------
254
- * Async job API — run heavy queries on a background thread.
250
+ * Caller must free with `taladb_free_string`.
251
+ */
252
+ char *taladb_search_text(struct TalaDbHandle *handle,
253
+ const char *collection,
254
+ const char *field,
255
+ const char *query,
256
+ uintptr_t top_k,
257
+ const char *filter_json,
258
+ const char *options_json);
259
+
260
+ /**
261
+ * Hybrid retrieval — BM25 and vector similarity fused with reciprocal rank
262
+ * fusion.
263
+ *
264
+ * `vector_ptr` must point to `vector_len` consecutive `f32` values.
265
+ * `options_json` accepts `{ rrfK, textWeight, vectorWeight, candidates, k1, b }`.
255
266
  *
256
- * Flow
257
- * ----
258
- * TalaDbJob *j = taladb_find_nearest_start(...); // spawns worker thread
259
- * while (taladb_job_poll(j) == 0) { } // yield to JS event loop
260
- * char *json = taladb_job_take_result(j); // frees the job
267
+ * Returns a JSON array string `[{document, score, textRank, vectorRank}, ...]`,
268
+ * or NULL on error. Caller must free with `taladb_free_string`.
261
269
  *
262
- * Workers clone the Arc-backed database state and do not borrow the handle.
263
- * ---------------------------------------------------------------------- */
270
+ * # Safety
271
+ * `vector_ptr` must be valid for `vector_len` `f32` reads.
272
+ */
273
+ char *taladb_hybrid_search(struct TalaDbHandle *handle,
274
+ const char *collection,
275
+ const char *text_field,
276
+ const char *text,
277
+ const char *vector_field,
278
+ const float *vector_ptr,
279
+ uintptr_t vector_len,
280
+ uintptr_t top_k,
281
+ const char *filter_json,
282
+ const char *options_json);
264
283
 
265
- typedef struct TalaDbJob TalaDbJob;
284
+ /**
285
+ * Create a vector index. `metric` and `hnsw_json` may be NULL.
286
+ * Returns 1 on success, -1 on error.
287
+ */
288
+ int32_t taladb_create_vector_index(struct TalaDbHandle *handle,
289
+ const char *collection,
290
+ const char *field,
291
+ uintptr_t dimensions,
292
+ const char *metric,
293
+ const char *hnsw_json);
294
+
295
+ /**
296
+ * Drop a vector index. Returns 1 on success, -1 on error.
297
+ */
298
+ int32_t taladb_drop_vector_index(struct TalaDbHandle *handle,
299
+ const char *collection,
300
+ const char *field);
266
301
 
267
- /** Kick a background `find_nearest`. Returns NULL on immediate arg error. */
268
- TalaDbJob *taladb_find_nearest_start(TalaDbHandle *handle,
269
- const char *collection,
270
- const char *field,
271
- const float *query_ptr,
272
- size_t query_len,
273
- size_t top_k,
274
- const char *filter_json);
302
+ /**
303
+ * Promote a flat/legacy vector index or compact its persistent HNSW graph.
304
+ * Returns 1 on success, -1 on error.
305
+ */
306
+ int32_t taladb_upgrade_vector_index(struct TalaDbHandle *handle,
307
+ const char *collection,
308
+ const char *field);
275
309
 
276
- /** Kick a background `find`. Returns NULL on immediate arg error. */
277
- TalaDbJob *taladb_find_start(TalaDbHandle *handle,
278
- const char *collection,
279
- const char *filter_json);
310
+ /**
311
+ * Rebuild every configured persistent HNSW graph in the database.
312
+ *
313
+ * This walks the stored HNSW options and rebuilds each one, so a caller does
314
+ * not have to know which collections and fields were configured as HNSW —
315
+ * unlike `taladb_upgrade_vector_index`, which rebuilds a single named field.
316
+ *
317
+ * It reads and re-inserts every indexed vector, so call it for maintenance or
318
+ * legacy migration and off any latency-sensitive path. Normal startup does
319
+ * not need a rebuild. Returns 1 on success, -1 on error.
320
+ */
321
+ int32_t taladb_rebuild_hnsw_indexes(struct TalaDbHandle *handle);
280
322
 
281
- /** Non-blocking. Returns 1 if complete, 0 if still running, -1 on NULL job. */
282
- int32_t taladb_job_poll(TalaDbJob *job);
323
+ /**
324
+ * Synchronous `find_nearest` with a zero-copy Float32 query vector.
325
+ *
326
+ * `query_ptr` — pointer to `query_len` consecutive f32 values (caller-owned).
327
+ * `filter_json` — optional pre-filter JSON (may be NULL / "{}" / "null").
328
+ *
329
+ * Returns a JSON array string `[{document, score}, ...]`, or NULL on error.
330
+ * Caller must free with `taladb_free_string`.
331
+ */
332
+ char *taladb_find_nearest(struct TalaDbHandle *handle,
333
+ const char *collection,
334
+ const char *field,
335
+ const float *query_ptr,
336
+ uintptr_t query_len,
337
+ uintptr_t top_k,
338
+ const char *filter_json);
283
339
 
284
340
  /**
285
- * Join the worker, take its result, and free the job.
286
- * Returns a JSON string on success, or NULL on error (see taladb_last_error).
287
- * Caller must free with taladb_free_string. Always frees the job.
341
+ * Non-blocking poll. Returns 1 if the job has finished, 0 if still running.
288
342
  */
289
- char *taladb_job_take_result(TalaDbJob *job);
343
+ int32_t taladb_job_poll(struct TalaDbJob *job);
290
344
 
291
- /** Detach the job and free the handle without waiting. */
292
- TalaDbJob *taladb_call_start(TalaDbHandle *handle, const char *op, const char *args_json);
345
+ /**
346
+ * Wait for the job to complete, take its result, and free the job.
347
+ * Returns the result JSON string on success, or NULL on error (see
348
+ * `taladb_last_error`). Always consumes and frees the job.
349
+ * Caller must free the returned string with `taladb_free_string`.
350
+ */
351
+ char *taladb_job_take_result(struct TalaDbJob *job);
293
352
 
294
- void taladb_job_cancel(TalaDbJob *job);
353
+ /**
354
+ * Cancel (detach) the job and free its handle. The worker owns a clone of all
355
+ * database state it needs, so it can safely finish after the caller closes the
356
+ * original database handle.
357
+ */
358
+ void taladb_job_cancel(struct TalaDbJob *job);
295
359
 
296
360
  /**
297
- * Last error message for the current thread, or NULL.
298
- * The returned pointer is valid until the next taladb_* call on this thread.
299
- * Do NOT free.
361
+ * Start a bounded JSON operation on a background worker.
362
+ *
363
+ * # Safety
364
+ * The handle must be live; both strings must be valid NUL-terminated UTF-8
365
+ * for this call. All arguments are copied before returning.
300
366
  */
301
- const char *taladb_last_error(void);
367
+ struct TalaDbJob *taladb_call_start(struct TalaDbHandle *handle,
368
+ const char *op,
369
+ const char *args_json);
370
+
371
+ /**
372
+ * Start a `find_nearest` in a background thread. Returns a job handle, or
373
+ * NULL on immediate error (bad args). The Float32 query vector is copied
374
+ * into the thread before the call returns, so `query_ptr` may be freed
375
+ * immediately after this function returns.
376
+ */
377
+ struct TalaDbJob *taladb_find_nearest_start(struct TalaDbHandle *handle,
378
+ const char *collection,
379
+ const char *field,
380
+ const float *query_ptr,
381
+ uintptr_t query_len,
382
+ uintptr_t top_k,
383
+ const char *filter_json);
384
+
385
+ /**
386
+ * Start a `find` in a background thread. Returns a job handle, or NULL on
387
+ * immediate error.
388
+ */
389
+ struct TalaDbJob *taladb_find_start(struct TalaDbHandle *handle,
390
+ const char *collection,
391
+ const char *filter_json);
302
392
 
303
393
  #ifdef __cplusplus
304
- } /* extern "C" */
305
- #endif
394
+ } // extern "C"
395
+ #endif // __cplusplus
306
396
 
307
- #endif /* TALADB_FFI_H */
397
+ #endif /* TALADB_FFI_H */