1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
/*
* kglite-c — C ABI for the kglite knowledge graph engine.
*
* Generated by cbindgen. Do NOT edit by hand. To regenerate:
* cargo build -p kglite-c
* (the crate's build.rs runs cbindgen automatically).
*
* Conventions: see docs/rust/c-abi.md in the kglite repo.
* https://github.com/kkollsga/kglite/blob/main/docs/rust/c-abi.md
*/
/**
* C-ABI-side error code. Variants 1-16 map 1:1 to
* [`kglite::api::KgErrorCode`]; variants 100+ are C-ABI-specific
* (invalid UTF-8 at the boundary, null pointer, OOM — conditions
* that don't have a corresponding `KgErrorCode` because they
* can't arise from inside the engine).
*/
;
typedef uint32_t KgliteStatusCode;
/**
* The ABI version that this build of `kglite-c` exposes. Derived at
* compile time from the crate's package version (`CARGO_PKG_VERSION_*`),
* so it tracks the engine version automatically.
*/
typedef struct KgliteAbiVersion KgliteAbiVersion;
/**
* Rust-heap statistics from kglite's tracking allocator.
*/
typedef struct KgMemStats KgMemStats;
/**
* Opaque handle for a SEC HTTP client (rate-limited, user-agent
* validating). See [`KgliteGraph`](crate::KgliteGraph) for the
* rationale on the empty `#[repr(C)]` facade pattern.
*/
typedef struct KgliteSecClient KgliteSecClient;
/**
* Opaque handle for an embedder. See
* [`KgliteGraph`](crate::KgliteGraph) for the rationale on the
* empty `#[repr(C)]` facade pattern — cbindgen renders only a
* forward declaration; the actual state lives in
* [`EmbedderState`].
*/
typedef struct KgliteEmbedder KgliteEmbedder;
/**
* Opaque handle for a session. See [`KgliteGraph`](crate::KgliteGraph)
* for the rationale on the empty `#[repr(C)]` facade pattern.
*/
typedef struct KgliteSession KgliteSession;
/**
* Opaque handle for a knowledge graph. The C-side caller only
* ever sees `KgliteGraph*`; allocation, deallocation, and field
* access happen inside `kglite-c`.
*
* cbindgen sees the `#[repr(C)]` empty struct and renders only a
* forward declaration in `kglite.h`. The actual state lives in
* the private [`GraphState`] sidecar: every `*mut KgliteGraph`
* the C side holds is really a `*mut GraphState` cast through
* the opaque facade.
*/
typedef struct KgliteGraph KgliteGraph;
/**
* Opaque handle for a Cypher result. See
* [`KgliteGraph`](crate::KgliteGraph) for the rationale on the
* empty `#[repr(C)]` facade pattern — cbindgen renders only a
* forward declaration; the actual state lives in [`ResultState`].
*/
typedef struct KgliteCypherResult KgliteCypherResult;
/**
* Return the C ABI version this library was built against.
* Bindings should call this on startup and refuse to proceed if
* the major version doesn't match what they were compiled
* against — a mismatched major risks segfaults from changed
* struct layouts or removed functions.
*
* Conventions within a major version: additive only (new
* functions, new status codes, new opaque types). Existing
* function signatures and struct layouts never change.
*
* # Examples
*
* ```c
* KgliteAbiVersion v = kglite_abi_version();
* if (v.major != KGLITE_EXPECTED_MAJOR) {
* fprintf(stderr, "kglite ABI mismatch: expected %u.x, got %u.%u.%u\n",
* KGLITE_EXPECTED_MAJOR, v.major, v.minor, v.patch);
* return 1;
* }
* ```
*/
struct KgliteAbiVersion ;
/**
* Return current Rust-heap statistics from kglite's tracking allocator.
* Counts only allocations through the Rust global allocator — the host
* runtime's own heap is separate. Useful for a binding to surface
* kglite's memory footprint in its own metrics.
*/
struct KgMemStats ;
/**
* Fetch all Sodir (Norwegian Continental Shelf) datasets the
* caller asks for. Thin wrapper around the engine's synchronous
* [`fetch_all`] entry point — fetches missing/stale CSVs from the
* ArcGIS FactMaps REST API across a bounded scoped worker pool,
* applies preprocessing (FK fixups), returns a report.
*
* # Arguments
*
* - `workdir_path` (in, borrowed): directory under which CSVs
* land. Layout: `<root>/csv/<dataset>.csv`,
* `<root>/index.json`. Created on first use; subsequent
* calls reuse the layout.
* - `datasets_json` (in, borrowed): JSON array of dataset
* stem names the caller wants — e.g.
* `["field", "wellbore_exploration", "production_profile"]`.
* Must not be null. Pass `"[]"` for no datasets.
* - `index_cooldown_days` (in): how long the workdir's
* `index.json` is trusted before re-probing the catalog.
* Wheel default: 7.
* - `dataset_cooldown_days` (in): how long an already-fetched
* CSV is trusted before re-fetching. Wheel default: 30.
* - `concurrency` (in): max parallel HTTP fetches. Wheel
* default: 10.
* - `out_report_json` (out, owned): on success, set to a
* JSON object string with the report fields. Caller must
* free via [`kglite_free_string`](crate::kglite_free_string).
* Shape:
* ```json
* {
* "refresh": {
* "fetched": ["..."],
* "unchanged": ["..."],
* "user_supplied": ["..."],
* "cached": ["..."],
* "unfetchable": ["..."],
* "errors": [["stem", "message"], ...]
* },
* "preprocess": {
* "petreg_licence_pk": null | <int>,
* "seismic_progress_fk": null | <int>,
* "chrono_parent_fk": null | <int>,
* "announced_block_fk": null | <int>
* }
* }
* ```
* - `out_error_msg` (out, owned, may be null): on failure,
* set to an owned error message string. Caller must free
* via [`kglite_free_string`](crate::kglite_free_string).
*
* # Errors
*
* - `KGLITE_STATUS_CODE_NULL_POINTER` — required pointer is null
* - `KGLITE_STATUS_CODE_INVALID_UTF8` — input string isn't valid UTF-8
* - `KGLITE_STATUS_CODE_INVALID_ARGUMENT` — `datasets_json` isn't a
* JSON array of strings
* - `KGLITE_STATUS_CODE_FILE_IO` — workdir creation or CSV write failed
* - `KGLITE_STATUS_CODE_INTERNAL` — REST API call failed or another
* engine-level error
*
* # Safety
*
* `workdir_path` and `datasets_json` must be null-terminated
* UTF-8 strings. `out_report_json` must be a valid writable
* pointer to a `*const c_char` slot.
*/
KgliteStatusCode ;
/**
* Construct a SEC HTTP client. The `user_agent` is mandatory and
* must be non-empty — SEC's fair-access policy requires a
* descriptive identifier with contact info (e.g.
* `"Acme Corp research@example.com"`).
*
* # Arguments
*
* - `user_agent` (in, borrowed): UTF-8 string, non-empty after trim.
* - `out_client` (out, owned): on success, set to a client handle.
* Caller must free via [`kglite_datasets_sec_client_free`].
* - `out_error_msg` (out, owned, may be null): on failure, set to
* an error message string.
*
* # Errors
*
* - `KGLITE_STATUS_CODE_NULL_POINTER` — required pointer is null
* - `KGLITE_STATUS_CODE_INVALID_UTF8` — `user_agent` isn't valid UTF-8
* - `KGLITE_STATUS_CODE_INVALID_ARGUMENT` — `user_agent` is empty
* after trim
*
* # Safety
*
* `user_agent` must be null-terminated UTF-8.
* `out_client` must be a valid writable pointer.
*/
KgliteStatusCode ;
/**
* Free a SEC client handle. Idempotent on null.
*
* # Safety
*
* `client` must be either null or a valid pointer previously
* returned by [`kglite_datasets_sec_client_new`].
*/
void ;
/**
* Fetch the quarterly `master.idx` files covering a year range,
* landing them in `<workdir>/raw/master_idx/`. Returns counts of
* files written and files skipped (already present).
*
* # Arguments
*
* - `client` (in, borrowed): SEC HTTP client.
* - `workdir_path` (in, borrowed): root for the layout.
* - `year_start`, `year_end` (in): inclusive year range. EDGAR's
* earliest quarter is 1993 Q3; quarters before that are skipped.
* - `current_year`, `current_quarter` (in): the "now" reference
* so the fetcher knows to skip future quarters. Callers
* typically pass the system clock's year + (month/3 + 1).
* - `out_pair_json` (out, owned): on success, set to a 2-element
* JSON array `[fetched_count, skipped_count]`.
* - `out_error_msg` (out, owned, may be null).
*
* # Safety
*
* `client` and the string args must be valid. `out_pair_json`
* must be a valid writable pointer.
*/
KgliteStatusCode ;
/**
* Fetch the bulk-download `submissions.zip` (all companies' filing
* metadata in one archive). Lands at
* `<workdir>/raw/bulk/submissions.zip`. Returns `true` if a fresh
* download landed (mtime older than `staleness_hours`, or
* `force_refetch`), `false` if the existing file was reused.
*
* # Arguments
*
* - `client` (in, borrowed).
* - `workdir_path` (in, borrowed).
* - `staleness_hours` (in): how stale the cached zip can be before
* re-fetching. SEC publishes nightly so 24 is a reasonable default.
* - `force_refetch` (in): non-zero forces re-download regardless of
* staleness.
* - `out_fetched` (out): set to 1 if downloaded fresh, 0 if reused.
* - `out_error_msg` (out, owned, may be null).
*
* # Safety
*
* `client` and `workdir_path` must be valid. `out_fetched` must be
* a valid writable pointer.
*/
KgliteStatusCode ;
/**
* Fetch the `company_tickers.json` mapping (TICKER → CIK).
* Lands at `<workdir>/raw/company_tickers.json`. Returns `true`
* if a fresh download landed.
*
* # Safety
*
* Same shape as [`kglite_datasets_sec_fetch_submissions_bulk`].
*/
KgliteStatusCode ;
/**
* Fetch the XBRL `companyfacts/CIK<cik>.json` file (a single
* company's full XBRL fact history). Lands at
* `<workdir>/raw/company_facts/CIK<cik>.json`. Returns `true` if
* a fresh download landed.
*
* # Arguments
*
* - `client`, `workdir_path`: see other fetchers.
* - `cik` (in): the company's CIK as an integer (no zero-padding).
* - `force_refetch` (in): non-zero forces re-download.
*
* # Safety
*
* Same shape as the other fetchers.
*/
KgliteStatusCode ;
/**
* Resolve a list of user-supplied form-type strings into the
* per-filing-fetcher buckets needed to cover them, plus a list of
* unrecognized form types the caller should warn about.
*
* Pure-CPU — no I/O, no client. Mirrors
* `kglite::api::datasets::sec::resolve_fetch_buckets`.
*
* # Arguments
*
* - `form_types_json` (in, borrowed): JSON array of form-type strings
* (e.g. `["10-K", "4", "13F-HR"]`), or the literal `"null"`
* for "use the lean default set".
* - `out_active_json` (out, owned): JSON array of bucket name
* strings, e.g. `["form4", "13f"]`.
* - `out_unmatched_json` (out, owned): JSON array of strings that
* didn't match any bucket.
* - `out_error_msg` (out, owned, may be null).
*
* # Errors
*
* - `KGLITE_STATUS_CODE_INVALID_ARGUMENT` — `form_types_json` isn't
* a JSON array of strings (or null).
*
* # Safety
*
* All input strings must be null-terminated UTF-8.
*/
KgliteStatusCode ;
/**
* Parse SEC's `company_tickers.json` shape into a TICKER → CIK
* map. Pure-CPU, no I/O. Returns the map as JSON object string.
*
* # Arguments
*
* - `tickers_json` (in, borrowed): the raw JSON from SEC's published
* `company_tickers.json`.
* - `out_map_json` (out, owned): JSON object `{"AAPL": 320193, ...}`.
* - `out_error_msg` (out, owned, may be null).
*
* # Errors
*
* - `KGLITE_STATUS_CODE_INVALID_ARGUMENT` — `tickers_json` isn't
* valid JSON.
*
* # Safety
*
* `tickers_json` must be null-terminated UTF-8.
*/
KgliteStatusCode ;
/**
* Run the SEC extract pipeline — reads `<workdir>/raw/` (the
* downloaded artifacts) and produces `<workdir>/processed/`
* CSVs (`company.csv`, `filing_index.csv`, `form4_transaction.csv`,
* `holding.csv`, etc.).
*
* # Arguments
*
* - `workdir_path` (in, borrowed).
* - `slice_json` (in, borrowed, may be null): JSON object with
* optional filters:
* ```json
* {
* "cik_list": [320193, 789019],
* "form_types": ["10-K", "10-Q"],
* "year_range": [2020, 2024]
* }
* ```
* Any missing / null field means "no restriction on that axis".
* Pass null or `"{}"` for fully unrestricted.
* - `force` (in): non-zero re-runs even when the
* `<workdir>/processed/holding.csv` sentinel says we already
* extracted.
* - `out_report_json` (out, owned): JSON object with extract
* stats. Caller frees via `kglite_free_string`.
* - `out_error_msg` (out, owned, may be null).
*
* # Safety
*
* `workdir_path` and (if non-null) `slice_json` must be
* null-terminated UTF-8.
*/
KgliteStatusCode ;
/**
* Ensure the Wikidata `latest-truthy.nt.bz2` dump is present
* under `<workdir>/cache/`. Resumable: a partially-downloaded
* file gets continued via HTTP `Range` requests. Cooldown:
* fully-present files within `cooldown_days` of their mtime
* skip the re-fetch entirely.
*
* # Arguments
*
* - `workdir_path` (in, borrowed): root for the workdir layout.
* - `cooldown_days` (in): how stale the cached dump can be before
* re-fetching. Wheel default: 7.
* - `verbose` (in): non-zero turns on the engine's progress
* logging.
* - `out_dump_path` (out, owned): JSON-encoded path string to the
* downloaded dump (e.g. `"\"<workdir>/cache/latest-truthy.nt.bz2\""`).
* We JSON-encode the path because filesystem paths can contain
* characters that need escaping in some downstream consumers.
* - `out_remote_mtime_iso` (out, owned, may be null): if the
* server returned a `Last-Modified` header, the ISO 8601
* timestamp string. Set to null if the probe failed.
* - `out_error_msg` (out, owned, may be null).
*
* # Safety
*
* `workdir_path` must be null-terminated UTF-8. The out-pointers
* must be valid writable slots.
*/
KgliteStatusCode ;
/**
* Sync HEAD-request probe for the dump's `Last-Modified` header.
* Returns the timestamp as RFC 3339 / ISO 8601 string, or null if
* the probe failed (network down, server returned no header,
* etc.).
*
* # Arguments
*
* - `out_iso` (out, owned, may be null): ISO 8601 string on
* success; null on probe failure. Caller frees via
* [`kglite_free_string`](crate::kglite_free_string).
*
* # Safety
*
* `out_iso` must be a valid writable pointer.
*/
KgliteStatusCode ;
/**
* Run the cache-freshness decision tree. Pure-CPU; the only I/O
* is the file-mtime stat that the engine's `decide()` performs
* internally on the two meta-paths. Returns a JSON object:
*
* ```json
* {"decision": "build" | "load" | "rebuild", "reason": "..." }
* ```
*
* # Arguments
*
* - `force_rebuild` (in): non-zero → always `Build("force_rebuild")`.
* - `graph_meta_path` (in, borrowed): path to
* `<graph_dir>/disk_graph_meta.json`. Missing file →
* `Build("no_cache")`.
* - `source_meta_path` (in, borrowed): path to
* `<graph_dir>/wikidata_source.json`. May be missing on graphs
* built before source-meta stamping landed.
* - `cooldown_days` (in): graphs younger than this skip the
* remote probe.
* - `remote_mtime_iso` (in, borrowed, may be null): RFC 3339 /
* ISO 8601 timestamp from a prior call to
* [`kglite_datasets_wikidata_remote_last_modified`]. Null →
* probe was skipped or failed.
* - `out_decision_json` (out, owned).
* - `out_error_msg` (out, owned, may be null).
*
* # Safety
*
* All input strings must be null-terminated UTF-8.
* `out_decision_json` must be a valid writable pointer.
*/
KgliteStatusCode ;
/**
* Free an embedder handle. Idempotent on null.
*
* # Safety
*
* `embedder` must be either null or a valid pointer previously
* returned by a `kglite_embedder_*_new` factory and not yet
* freed. Calling twice on the same pointer is UB.
*
* **Do NOT free** an embedder that has been handed to
* [`kglite_session_set_embedder`] — the session retains a clone
* of the inner Arc; you may free your handle after the call to
* set_embedder (the Arc keeps the embedder alive until the
* session drops). For symmetry with other handles, the safest
* pattern is: factory → set_embedder → free_embedder. Once the
* Arc is shared, the original handle is no longer special.
*/
void ;
/**
* Attach an embedder to a session. The session retains a clone
* of the embedder's inner `Arc`, so subsequent
* [`kglite_session_execute_read`](crate::kglite_session_execute_read)
* calls have access to `text_score()` and other embedder-backed
* Cypher functions.
*
* The caller may free the embedder handle after this call
* returns — the `Arc` clone keeps the underlying embedder
* alive for the session's lifetime.
*
* # Safety
*
* `session` and `embedder` must be valid handles previously
* returned by `kglite_session_new` and a `kglite_embedder_*_new`
* factory respectively, neither yet freed.
*/
KgliteStatusCode ;
/**
* Construct a fastembed-rs-backed embedder.
*
* fastembed-rs downloads ONNX model weights on first
* `embed()` call (cached at `~/.cache/fastembed/`). The factory
* does NOT block on download — model name validation only. The
* first Cypher query using `text_score()` triggers the download.
*
* # Arguments
*
* - `model_name` (in, borrowed): a known fastembed model name,
* e.g. `"BAAI/bge-m3"`, `"sentence-transformers/all-MiniLM-L6-v2"`.
* See fastembed-rs's TextEmbedding::list_supported_models() for
* the full list.
* - `out_embedder` (out, owned): on success, set to an embedder
* handle. Caller must free via [`kglite_embedder_free`] (or
* transfer ownership via [`kglite_session_set_embedder`]).
* - `out_error_msg` (out, owned, may be null): on failure, set to
* an owned error string.
*
* # Errors
*
* - `KGLITE_STATUS_CODE_NULL_POINTER` — required pointer is null
* - `KGLITE_STATUS_CODE_INVALID_UTF8` — `model_name` isn't valid UTF-8
* - `KGLITE_STATUS_CODE_INVALID_ARGUMENT` — `model_name` isn't a known
* fastembed model
*
* # Feature gate
*
* Available only when `kglite-c` is built with the `fastembed`
* Cargo feature.
*
* # Safety
*
* `model_name` must be a null-terminated UTF-8 string.
* `out_embedder` must be a valid writable pointer.
*/
KgliteStatusCode ;
/**
* Create a new, empty in-memory knowledge graph.
*
* The returned handle owns a fresh, empty `DirGraph` — the C-side
* analogue of constructing `KnowledgeGraph()` in Python. Build it up
* by opening a session ([`kglite_session_new`](crate::kglite_session_new))
* and running `CREATE` / `MERGE` Cypher through
* [`kglite_session_execute_mut`](crate::kglite_session_execute_mut), or
* by bulk-loading via the dataset / blueprint entry points. Before this
* existed, the only way to obtain a graph at the C boundary was to load
* a pre-built `.kgl` file — a binding could not start one from scratch.
*
* # Returns
*
* A non-null `KgliteGraph*` the caller must free with
* [`kglite_graph_free`], or hand to
* [`kglite_session_new`](crate::kglite_session_new) which takes
* ownership. Returns null only on allocation failure.
*/
struct KgliteGraph *;
/**
* Create a fresh, empty knowledge graph in an explicit storage mode.
*
* `mode` is `"memory"` (alias `"default"`), `"mapped"`, or `"disk"` — the
* same mode vocabulary as Python's `storage=` argument:
*
* - `"memory"` — heap-resident (the default; same as [`kglite_graph_new`]).
* - `"mapped"` — property columns spill to mmap during build, so a graph
* larger than RAM can be constructed; saves to a `.kgl` file.
* - `"disk"` — CSR + mmap on-disk directory format for very large graphs;
* **requires** `path` (the directory that becomes the graph).
*
* This is the create/ingest entry point. Opening an existing graph
* ([`kglite_load_file`]) auto-detects its mode, so no mode argument is
* needed there.
*
* # Arguments
*
* - `mode` (in, borrowed): UTF-8 mode string, null-terminated.
* - `path` (in, borrowed): UTF-8 directory path for `"disk"`, else null.
* - `out_graph` (out, owned): set to the new graph handle on success
* (free via [`kglite_graph_free`], or hand to
* [`kglite_session_new`](crate::kglite_session_new)); null on failure.
* - `out_error_msg` (out, owned): owned error message on failure (free via
* [`kglite_free_string`](crate::kglite_free_string)); null on success.
*
* # Errors
*
* - `KGLITE_ERR_NULL_POINTER` — `mode` or `out_graph` is null
* - `KGLITE_ERR_INVALID_UTF8` — `mode` / `path` isn't valid UTF-8
* - `KGLITE_ERR_INVALID_ARGUMENT` — unknown mode, or `"disk"` with no path
* - `KGLITE_ERR_FILE_IO` — failed to create the disk-graph directory
*
* # Safety
*
* `mode` must be a null-terminated UTF-8 string; `path` null or the same;
* `out_graph` a valid `*mut KgliteGraph` slot; `out_error_msg` null or a
* valid slot.
*/
KgliteStatusCode ;
/**
* Load a knowledge graph from disk. Accepts `.kgl` files
* (single-file mmap format) and directories (disk-backed CSR
* layout) — the loader picks the right path based on what's at
* `path`.
*
* # Arguments
*
* - `path` (in, borrowed): UTF-8 file path, null-terminated.
* - `out_graph` (out, owned): set to the loaded graph handle on
* success; caller must free via [`kglite_graph_free`]. Set to
* null on failure.
* - `out_error_msg` (out, owned): set to an owned error message
* on failure; caller must free via
* [`kglite_free_string`](crate::kglite_free_string). Set to
* null on success.
*
* # Errors
*
* - `KGLITE_ERR_NULL_POINTER` — `path` or `out_graph` is null
* - `KGLITE_ERR_INVALID_UTF8` — `path` isn't valid UTF-8
* - `KGLITE_ERR_FILE_NOT_FOUND` — `path` doesn't exist
* - `KGLITE_ERR_FILE_FORMAT` — file isn't a valid `.kgl` /
* disk-graph directory
* - `KGLITE_ERR_FILE_IO` — I/O failure during read
*
* # Safety
*
* `path` must point to a null-terminated UTF-8 string.
* `out_graph` must be a valid writable pointer to a
* `*mut KgliteGraph` slot. `out_error_msg` may be null (the
* caller doesn't care about the message); otherwise it must
* point to a valid writable `*const c_char` slot.
*/
KgliteStatusCode ;
/**
* Load an RDF file into a fresh in-memory graph — the C-side handle on
* the wheel's `kglite.load_rdf`. Dispatches on the extension: `.ttl`
* (Turtle), `.nt` (N-Triples), `.nq` (N-Quads), `.trig` (TriG).
*
* The RDF → property-graph fold: object literals become typed node
* properties, resource objects become edges, and `rdf:type` sets the
* node label (first wins; extras kept in an `rdf_types` property).
* Predicate / type IRIs are CURIE-compacted with a `__` separator
* (so `[:foaf__knows]` matches in Cypher); each node keeps its full
* subject IRI in a `uri` property. In-memory backend only.
*
* # Arguments
*
* - `path` (in, borrowed): UTF-8 file path; the extension picks the parser.
* - `languages_json` (in, borrowed): JSON array of language tags to keep
* (e.g. `["en","de"]`), or null to keep all literals.
* - `label_predicates_json` (in, borrowed): JSON array of predicate IRIs
* whose literal object sets the node title, or null for
* `["http://www.w3.org/2000/01/rdf-schema#label"]`.
* - `keep_full_iris` (in): non-zero keeps full IRIs instead of CURIEs.
* - `default_type` (in, borrowed): node type for subjects without an
* `rdf:type`, or null for `"Resource"`.
* - `max_triples` (in): stop after this many triples; negative = no limit.
* - `out_graph` (out, owned): the loaded graph on success (free via
* [`kglite_graph_free`] or hand to
* [`kglite_session_new`](crate::kglite_session_new)); null on failure.
* - `out_stats_json` (out, owned): `{"nodes":N,"edges":M,"triples":T}` on
* success — free via [`kglite_free_string`](crate::kglite_free_string).
* May be null if the caller doesn't want stats.
* - `out_error_msg` (out, owned): error message on failure — free via
* [`kglite_free_string`](crate::kglite_free_string); null on success.
*
* # Errors
*
* - `KGLITE_ERR_NULL_POINTER` — `path` or `out_graph` is null
* - `KGLITE_ERR_INVALID_UTF8` — a string argument isn't valid UTF-8
* - `KGLITE_ERR_INVALID_ARGUMENT` — a `*_json` arg isn't a JSON string
* array, or the file extension isn't a supported RDF format
* - `KGLITE_ERR_FILE_NOT_FOUND` — `path` doesn't exist
* - `KGLITE_ERR_FILE_FORMAT` — a parse error in the RDF
*
* # Safety
*
* String arguments must each be a null-terminated UTF-8 string or null;
* `out_graph` a valid writable `*mut KgliteGraph` slot; `out_stats_json`
* and `out_error_msg` null or valid writable slots.
*/
KgliteStatusCode ;
/**
* Save a knowledge graph to disk. The on-disk format depends on
* the underlying storage mode — in-memory and mapped graphs
* produce a `.kgl` single-file; disk-backed graphs produce / fill
* a directory.
*
* The write is atomic (temp + rename) and **durable** (file +
* parent-directory fsync) — a crash mid-save can't tear the file.
* Use [`kglite_save_graph_durable`] with `fsync == 0` for the fast,
* non-durable opt-out.
*
* # Arguments
*
* - `graph` (in, borrowed): the graph to save.
* - `path` (in, borrowed): UTF-8 destination path,
* null-terminated.
* - `out_error_msg` (out, owned): set to an owned error message
* on failure; caller must free via
* [`kglite_free_string`](crate::kglite_free_string). Set to
* null on success.
*
* # Errors
*
* - `KGLITE_ERR_NULL_POINTER` — `graph` or `path` is null
* - `KGLITE_ERR_INVALID_UTF8` — `path` isn't valid UTF-8
* - `KGLITE_ERR_FILE_IO` — write failed
*
* # Safety
*
* `graph` must be a valid `*mut KgliteGraph` previously returned
* by a `kglite_*` function and not yet freed. `path` must be a
* null-terminated UTF-8 string.
*/
KgliteStatusCode ;
/**
* Free a graph handle. Idempotent on null (no-op).
*
* # Safety
*
* `graph` must be either null or a pointer previously returned by
* [`kglite_load_file`] (or any future `kglite_*` function that
* returns a `*mut KgliteGraph`) and not yet freed. Calling twice
* on the same pointer is UB.
*
* **Do NOT free** a graph handle that has been handed to
* [`kglite_session_new`](crate::kglite_session_new) — the session
* takes ownership and frees on its own teardown.
*/
void ;
/**
* Generate a synthetic benchmark/demo graph as CSVs + a manifest under
* `out_dir`, in bounded memory. Load the result with [`kglite_load_file`]
* pointed at `out_dir` — the C-side handle on `kglite.graphgen(...)`, the
* "hello, query a graph" data source for a fresh binding.
*
* `zipf` != 0 uses a Zipf degree distribution (high-degree hubs) with
* exponent `zipf_exp`; `zipf` == 0 uses uniform degree.
*
* On success `out_stats_json` is set to an owned `{"nodes": N, "edges": M}`
* string — free via [`kglite_free_string`](crate::kglite_free_string).
*
* # Safety
*
* `out_dir` must be a null-terminated UTF-8 path; `out_stats_json` a valid
* writable `*const c_char` slot; `out_error_msg` null or a valid slot.
*/
KgliteStatusCode ;
/**
* Build a graph declaratively from a blueprint file + a directory of
* CSVs — the C-side handle on the wheel's `from_blueprint`. Loads the
* JSON/YAML blueprint at `blueprint_path`, builds into a fresh graph
* reading CSVs relative to `csv_dir`, and returns the populated graph.
*
* On success `out_graph` is set to a `KgliteGraph*` (free via
* [`kglite_graph_free`] or hand to [`kglite_session_new`](crate::kglite_session_new)),
* and `out_report_json` to an owned
* `{"nodes_by_type":{..},"edges_by_type":{..},"warnings":[..],"errors":[..],"provisional_purged":N}`
* string — free via [`kglite_free_string`](crate::kglite_free_string).
*
* # Safety
*
* `blueprint_path` / `csv_dir` must be null-terminated UTF-8 paths;
* `out_graph` / `out_report_json` valid writable slots; `out_error_msg`
* null or a valid slot.
*/
KgliteStatusCode ;
/**
* Save a graph to a `.kgl` file with an explicit durability choice.
*
* `fsync` != 0 is exactly [`kglite_save_graph`]: mode-aware (disk dir vs
* in-memory `.kgl`), atomic temp+rename, and the file + parent directory
* are flushed to stable storage before returning — durable across power
* loss, at the cost of fsync latency.
*
* `fsync` == 0 is the fast, **non-durable** opt-out: same mode-aware
* atomic rename (never a torn file) but the fsync barrier is skipped, so
* the bytes may not survive an OS/power crash. Use it only for bulk or
* throwaway saves where you'll re-save or can rebuild.
*
* # Safety
*
* `graph` must be a valid handle; `path` a null-terminated UTF-8 path;
* `out_error_msg` null or a valid slot.
*/
KgliteStatusCode ;
/**
* Serialize a graph to an in-memory `.kgl` byte buffer (no file). On
* success `*out_buf` / `*out_len` describe an owned buffer the caller
* MUST free with [`kglite_free_bytes`]. Pair with
* [`kglite_graph_from_bytes`] to round-trip a graph through bytes (IPC,
* object storage, …).
*
* # Safety
*
* `graph` valid; `out_buf` a valid `*mut u8` slot; `out_len` a valid
* `usize` slot; `out_error_msg` null or valid.
*/
KgliteStatusCode ;
/**
* Free a byte buffer returned by [`kglite_graph_to_bytes`]. Pass the
* same `buf` / `len` pair. Null `buf` is a no-op.
*
* # Safety
*
* `buf` / `len` must be a pair previously returned by
* [`kglite_graph_to_bytes`] and not yet freed.
*/
void ;
/**
* Load a graph from an in-memory `.kgl` byte buffer — the inverse of
* [`kglite_graph_to_bytes`].
*
* # Safety
*
* `data` / `len` must describe a readable buffer; `out_graph` a valid
* writable slot; `out_error_msg` null or a valid slot.
*/
KgliteStatusCode ;
/**
* Compute a JSON schema overview of a graph: node types (count +
* property types), connection types (endpoints + property names),
* indexes, and total node/edge counts. The C-side handle on the
* agent-facing schema — call it right after load / build / from_bytes
* to learn a graph's shape before querying.
*
* On success `out_json` is set to an owned JSON object — free via
* [`kglite_free_string`](crate::kglite_free_string). Operates on a graph
* handle (before it is moved into a session).
*
* # Safety
*
* `graph` must be a valid handle; `out_json` a valid writable slot;
* `out_error_msg` null or a valid slot.
*/
KgliteStatusCode ;
/**
* Return the column names as a JSON array string:
* `["col1", "col2", ...]`.
*
* The returned string is OWNED by the caller and must be freed
* via [`kglite_free_string`](crate::kglite_free_string). Returns
* null on serialization failure (shouldn't happen — column names
* are always serializable).
*/
const char *;
/**
* Return all rows as a JSON array of objects keyed by column
* name: `[{"col1": v1, "col2": v2}, ...]`.
*
* Cell values are **natural** JSON (`2`, `"x"`, `[..]`, `{..}`) via
* [`kglite_value_to_json`](kglite::api::param::kglite_value_to_json) —
* not serde's externally-tagged enum encoding — so a binding parses
* `{"n": 2}`, not `{"n": {"Int64": 2}}`.
*
* For large result sets this materializes the entire JSON blob
* in memory. Future v2 will add pull-row-by-row accessors; for
* now this is fine for the common-case query sizes.
*
* The returned string is OWNED by the caller and must be freed
* via [`kglite_free_string`](crate::kglite_free_string). Returns
* null on serialization failure.
*/
const char *;
/**
* Return the number of rows in the result. Useful for callers
* that want to size buffers before requesting the JSON blob.
*/
uintptr_t ;
/**
* Free a result handle. Idempotent on null (no-op).
*
* # Safety
*
* `result` must be either null or a valid pointer previously
* returned by [`kglite_session_execute_read`](crate::kglite_session_execute_read)
* or [`kglite_session_execute_mut`](crate::kglite_session_execute_mut)
* and not yet freed.
*/
void ;
/**
* Create a new session from a graph handle. The session takes
* ownership of the graph — the caller MUST NOT call
* [`kglite_graph_free`](crate::kglite_graph_free) on the handle
* after this call. Free the session via
* [`kglite_session_free`] when done.
*
* # Arguments
*
* - `graph` (in, MOVED): graph handle. After this call, the
* pointer is no longer valid for any other use.
* - `out_session` (out, owned): set to the session handle on
* success; caller must free via [`kglite_session_free`].
*
* # Errors
*
* - `KGLITE_ERR_NULL_POINTER` — `graph` or `out_session` is null
*
* # Safety
*
* `graph` must be a valid `*mut KgliteGraph` previously returned
* by [`kglite_load_file`](crate::kglite_load_file) and not yet
* freed or moved into another session. `out_session` must be a
* valid writable pointer to a `*mut KgliteSession` slot.
*/
KgliteStatusCode ;
/**
* Run a read-only Cypher query.
*
* # Arguments
*
* - `session` (in, borrowed): the session.
* - `query` (in, borrowed): UTF-8 Cypher query, null-terminated.
* - `params_json` (in, borrowed, may be null): JSON object of
* parameter bindings. Pass null or `"{}"` for no params.
* - `out_result` (out, owned): on success, set to the result
* handle; caller must free via [`kglite_cypher_result_free`].
* - `out_error_msg` (out, owned, may be null): on failure, set
* to the error message; caller must free via
* [`kglite_free_string`](crate::kglite_free_string).
*
* # Errors
*
* Any `KgErrorCode` variant — Cypher syntax / type mismatch /
* timeout / execution error / node-not-found / argument
* validation. The error message describes the specific failure.
*
* # Safety
*
* `session` must be valid. `query` and (if non-null) `params_json`
* must be null-terminated UTF-8 strings.
*/
KgliteStatusCode ;
/**
* Run a read-only Cypher query with execution options. Same as
* [`kglite_session_execute_read`], plus:
*
* - `timeout_ms`: past this wall-clock budget the query returns
* `CypherTimeout`. `0` = no deadline.
* - `max_rows`: reject the query (error) if it would produce more than
* this many rows — a safety guard against runaway results, not a
* silent truncation; add a `LIMIT` clause to bound output. `0` = no
* limit.
*
* # Safety
*
* Same as [`kglite_session_execute_read`].
*/
KgliteStatusCode ;
/**
* Run a mutating Cypher query. Same shape as
* [`kglite_session_execute_read`] but accepts CREATE / SET /
* DELETE / REMOVE / MERGE statements. The session's underlying
* graph is auto-committed after a successful execute (no
* explicit begin/commit in v1 — explicit transactions land in
* a future ABI version once a binding needs them).
*
* # Safety
*
* Same as [`kglite_session_execute_read`] except `session` is
* declared as `*mut` (the call mutates the session's interior
* graph via commit-swap).
*/
KgliteStatusCode ;
/**
* Run several read-only Cypher queries against a single consistent
* snapshot, in one lock acquisition.
*
* `queries_json` is a JSON array of objects, each `{"query": "...",
* "params": {...}}` (the `params` key is optional). Every query sees
* the same snapshot, taken once up front — cheaper and more consistent
* than N separate [`kglite_session_execute_read`] calls when a binding
* issues many small reads.
*
* On success `out_results_json` is set to an owned JSON string: an
* array of `{"columns": [...], "rows": [{...}]}` objects, one per input
* query in order, with the same natural-value encoding as
* [`kglite_cypher_result_rows_json`]. Free it with
* [`kglite_free_string`](crate::kglite_free_string).
*
* The batch aborts on the first failing query: `out_results_json` is
* set to null and the status code / `out_error_msg` describe that
* query's failure.
*
* # Safety
*
* `session` must be valid; `queries_json` a null-terminated UTF-8 JSON
* array; `out_results_json` a valid writable `*const c_char` slot;
* `out_error_msg` null or a valid writable slot.
*/
KgliteStatusCode ;
/**
* Run several mutating Cypher queries in a single transaction — one
* `begin`, N executes (each sees the previous query's writes), a single
* `commit`. The batch is **atomic**: if any query fails, the
* transaction is dropped uncommitted and none of the batch's mutations
* reach the graph.
*
* `queries_json` / `out_results_json` have the same shape as
* [`kglite_session_execute_read_batch`]. On failure `out_results_json`
* is null and the status / `out_error_msg` describe the failing query.
*
* # Safety
*
* Same as [`kglite_session_execute_read_batch`] except `session` is
* `*mut` (the call mutates the session's interior graph via
* commit-swap).
*/
KgliteStatusCode ;
/**
* Bulk-create edges addressed by **stable node id + type**, bypassing
* Cypher — the fast ingest path for bindings loading many edges.
*
* `edges_json` is a JSON array of objects:
* `{"src_id": <id>, "src_type": "Person", "dst_id": <id>,
* "dst_type": "Company", "type": "WORKS_AT", "props": {...}}`
* (`props` optional). `src_id`/`dst_id` are the nodes' stable ids (the
* same value `n.id` returns), not internal indices. Runs in one
* transaction: the whole batch commits together, or — on error — none
* of it lands. Endpoints must already exist; an edge whose source or
* target id isn't found for its declared type is skipped and counted.
*
* On success `out_report_json` is set to an owned JSON object
* `{"connections_created": N, "skipped_missing_endpoint": M}`; free it
* with [`kglite_free_string`](crate::kglite_free_string).
*
* This wraps the shared core primitive
* [`add_edges_from_specs`](kglite::api::mutation::add_edges_from_specs) —
* the same engine the Python `add_connections` DataFrame path uses.
*
* # Safety
*
* `session` must be valid; `edges_json` a null-terminated UTF-8 JSON
* array; `out_report_json` a valid writable `*const c_char` slot;
* `out_error_msg` null or a valid writable slot.
*/
KgliteStatusCode ;
/**
* Free a session handle. Idempotent on null (no-op).
*
* # Safety
*
* `session` must be either null or a valid pointer previously
* returned by [`kglite_session_new`] and not yet freed.
*/
void ;
/**
* Return the canonical human-readable name of a status code (e.g.
* `"CypherSyntax"`, `"NodeNotFound"`, `"InvalidUtf8"`).
*
* The returned string is OWNED by the caller and must be freed
* via [`kglite_free_string`](crate::kglite_free_string). Returns
* null on `Ok` (no error to name).
*/
const char *;
/**
* Return the Neo4j wire status code for a status code (e.g.
* `"Neo.ClientError.Statement.SyntaxError"`). Useful for bindings
* implementing the Neo4j Bolt wire protocol or compatible HTTP
* APIs.
*
* The returned string is OWNED by the caller and must be freed
* via [`kglite_free_string`](crate::kglite_free_string). Returns
* null on `Ok` or on C-ABI-only error codes that have no Neo4j
* counterpart (`InvalidUtf8`, `NullPointer`).
*/
const char *;
/**
* Return the HTTP status code mapping for a status code (e.g.
* 400 for `CypherSyntax`, 404 for `NodeNotFound`, 500 for
* `Internal`). Useful for REST/gRPC bindings.
*
* Returns 0 for `Ok` and 500 for C-ABI-only codes (`InvalidUtf8`
* = 400 / bad request from caller, `NullPointer` = 400).
*/
uint16_t ;
/**
* Free a string previously returned by any `kglite_*` function.
*
* Safety: `s` must be either null or a pointer previously returned
* by a `kglite_*` function (these all flow through
* [`alloc_c_string`]). Calling twice on the same pointer is UB.
* Calling with a pointer to a string allocated by the C caller's
* own `malloc` is UB.
*
* Passing null is safe (treated as a no-op).
*
* # Examples
*
* ```c
* const char* col_json = kglite_cypher_result_columns_json(result);
* printf("%s\n", col_json);
* kglite_free_string(col_json);
* ```
*/
void ;
/* KGLITE_H_INCLUDED */