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
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
// Copyright 2025-present the zvec project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ZVEC_C_API_H
#define ZVEC_C_API_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
// =============================================================================
// API Export Control
// =============================================================================
#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef ZVEC_BUILD_SHARED
#define ZVEC_EXPORT __declspec(dllexport)
#elif defined(ZVEC_USE_SHARED)
#define ZVEC_EXPORT __declspec(dllimport)
#else
#define ZVEC_EXPORT
#endif
#define ZVEC_CALL __cdecl
#else
#if __GNUC__ >= 4
#define ZVEC_EXPORT __attribute__((visibility("default")))
#else
#define ZVEC_EXPORT
#endif
#define ZVEC_CALL
#endif
#ifdef __cplusplus
extern "C" {
#endif
// =============================================================================
// Version Information
// =============================================================================
/**
* @brief Get library version information
*
* Return format: "{base_version}[-{git_info}] (built {build_time})"
* Example: "0.3.0-g3f8a2b1 (built 2025-05-13 10:30:45)"
*
* @return const char* Version string, managed internally by the library, caller
* should not free
*/
ZVEC_EXPORT const char *ZVEC_CALL zvec_get_version(void);
/**
* @brief Check API version compatibility
*
* Check if the current library version meets the specified minimum version
* requirements Following semantic versioning specification: MAJOR.MINOR.PATCH
*
* @param major Required major version number
* @param minor Required minor version number
* @param patch Required patch version number
* @return bool Returns true if compatible, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_check_version(int major, int minor, int patch);
/**
* @brief Get major version number
*
* @return int Major version number
*/
ZVEC_EXPORT int ZVEC_CALL zvec_get_version_major(void);
/**
* @brief Get minor version number
*
* @return int Minor version number
*/
ZVEC_EXPORT int ZVEC_CALL zvec_get_version_minor(void);
/**
* @brief Get patch version number
*
* @return int Patch version number
*/
ZVEC_EXPORT int ZVEC_CALL zvec_get_version_patch(void);
// =============================================================================
// Error Code Definitions
// =============================================================================
/**
* @brief ZVec C API error code enumeration
*/
typedef enum {
ZVEC_OK = 0, /**< Success */
ZVEC_ERROR_NOT_FOUND = 1, /**< Resource not found */
ZVEC_ERROR_ALREADY_EXISTS = 2, /**< Resource already exists */
ZVEC_ERROR_INVALID_ARGUMENT = 3, /**< Invalid argument */
ZVEC_ERROR_PERMISSION_DENIED = 4, /**< Permission denied */
ZVEC_ERROR_FAILED_PRECONDITION = 5, /**< Failed precondition */
ZVEC_ERROR_RESOURCE_EXHAUSTED = 6, /**< Resource exhausted */
ZVEC_ERROR_UNAVAILABLE = 7, /**< Unavailable */
ZVEC_ERROR_INTERNAL_ERROR = 8, /**< Internal error */
ZVEC_ERROR_NOT_SUPPORTED = 9, /**< Unsupported operation */
ZVEC_ERROR_UNKNOWN = 10 /**< Unknown error */
} zvec_error_code_t;
/**
* @brief Error details structure
*/
typedef struct {
zvec_error_code_t code; /**< Error code */
const char *message; /**< Error message */
const char *file; /**< File where error occurred */
int line; /**< Line number where error occurred */
const char *function; /**< Function where error occurred */
} zvec_error_details_t;
/**
* @brief Get detailed information of the last error
* @param[out] error_details Pointer to error details structure
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_get_last_error_details(zvec_error_details_t *error_details);
/**
* @brief Get last error message
* @param[out] error_msg Returned error message string (needs to be freed by
* calling free)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_get_last_error(char **error_msg);
/**
* @brief Clear error status
*/
ZVEC_EXPORT void ZVEC_CALL zvec_clear_error(void);
// =============================================================================
// Basic Data Structures
// =============================================================================
/**
* @brief String view structure (does not own memory)
*/
typedef struct {
const char *data; /**< String data pointer */
size_t length; /**< String length */
} zvec_string_view_t;
/**
* @brief Mutable string structure (owns memory)
*/
typedef struct {
char *data; /**< String data pointer */
size_t length; /**< String length */
size_t capacity; /**< Allocated capacity */
} zvec_string_t;
/**
* @brief String array structure
*/
typedef struct {
zvec_string_t *strings; /**< String array */
size_t count; /**< String count */
} zvec_string_array_t;
/**
* @brief Float array structure
*/
typedef struct {
const float *data;
size_t length;
} zvec_float_array_t;
/**
* @brief Integer array structure
*/
typedef struct {
const int64_t *data;
size_t length;
} zvec_int64_array_t;
/**
* @brief Byte array structure
*/
typedef struct {
const uint8_t *data; /**< Byte data pointer */
size_t length; /**< Array length */
} zvec_byte_array_t;
/**
* @brief Mutable byte array structure
*/
typedef struct {
uint8_t *data; /**< Byte data pointer */
size_t length; /**< Current length */
size_t capacity; /**< Allocated capacity */
} zvec_mutable_byte_array_t;
// =============================================================================
// String management functions
// =============================================================================
/**
* @brief Create string from C string
* @param str C string
* @return zvec_string_t* Pointer to the newly created string
*/
ZVEC_EXPORT zvec_string_t *ZVEC_CALL zvec_string_create(const char *str);
/**
* @brief Create string from string view
*
* Creates a new zvec_string_t by copying data from a zvec_string_view_t.
* The created string owns its memory and must be freed with zvec_free_string().
*
* @param view Pointer to source string view (must not be NULL)
* @return zvec_string_t* New string instance on success, NULL on error
* @note Caller is responsible for freeing the returned string
*/
ZVEC_EXPORT zvec_string_t *ZVEC_CALL
zvec_string_create_from_view(const zvec_string_view_t *view);
/**
* @brief Create binary-safe string from raw data
*
* Creates a new zvec_string_t from raw binary data that may contain null bytes.
* Unlike zvec_string_create(), this function takes explicit length parameter
* and doesn't rely on null-termination.
* The created string owns its memory and must be freed with zvec_free_string().
*
* @param data Raw binary data pointer (must not be NULL)
* @param length Length of data in bytes
* @return zvec_string_t* New string instance on success, NULL on error
* @note Caller is responsible for freeing the returned string
* @note This function is suitable for binary data containing null bytes
*/
ZVEC_EXPORT zvec_string_t *ZVEC_CALL zvec_bin_create(const uint8_t *data,
size_t length);
/**
* @brief Copy string
*
* Creates a new zvec_string_t by copying an existing string.
* The created string owns its memory and must be freed with zvec_free_string().
*
* @param str Pointer to source string (must not be NULL)
* @return zvec_string_t* New string instance on success, NULL on error
* @note Caller is responsible for freeing the returned string
*/
ZVEC_EXPORT zvec_string_t *ZVEC_CALL zvec_string_copy(const zvec_string_t *str);
/**
* @brief Get C string from zvec_string_t
* @param str zvec_string_t pointer
* @return const char* C string
*/
ZVEC_EXPORT const char *ZVEC_CALL zvec_string_c_str(const zvec_string_t *str);
/**
* @brief Get string length
* @param str zvec_string_t pointer
* @return size_t String length
*/
ZVEC_EXPORT size_t ZVEC_CALL zvec_string_length(const zvec_string_t *str);
/**
* @brief Compare two strings
* @param str1 First string
* @param str2 Second string
* @return int Comparison result (-1, 0, or 1)
*/
ZVEC_EXPORT int ZVEC_CALL zvec_string_compare(const zvec_string_t *str1,
const zvec_string_t *str2);
/**
* @brief Free string memory
* @param str String pointer to free
*/
ZVEC_EXPORT void ZVEC_CALL zvec_free_string(zvec_string_t *str);
// =============================================================================
// Array Memory management functions
// =============================================================================
/**
* @brief Create a new string array
* @param count Initial number of strings to allocate space for
* @return Pointer to the newly created string array, or NULL on failure
*/
ZVEC_EXPORT zvec_string_array_t *ZVEC_CALL
zvec_string_array_create(size_t count);
/**
* @brief Add a string to the string array at specified index
* @param array String array pointer
* @param idx Index position where the string should be added
* @param str Null-terminated C string to add
*/
ZVEC_EXPORT void ZVEC_CALL zvec_string_array_add(zvec_string_array_t *array,
size_t idx, const char *str);
/**
* @brief Destroy string array and free all associated memory
* @param array String array pointer to destroy
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_string_array_destroy(zvec_string_array_t *array);
/**
* @brief Create a new mutable byte array
* @param capacity Initial capacity in bytes
* @return Pointer to the newly created byte array, or NULL on failure
*/
ZVEC_EXPORT zvec_mutable_byte_array_t *ZVEC_CALL
zvec_byte_array_create(size_t capacity);
/**
* @brief Destroy byte array and free all associated memory
* @param array Byte array pointer to destroy
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_byte_array_destroy(zvec_mutable_byte_array_t *array);
/**
* @brief Create a new float array
* @param count Number of floats to allocate space for
* @return Pointer to the newly created float array, or NULL on failure
*/
ZVEC_EXPORT zvec_float_array_t *ZVEC_CALL zvec_float_array_create(size_t count);
/**
* @brief Destroy float array and free all associated memory
* @param array Float array pointer to destroy
*/
ZVEC_EXPORT void ZVEC_CALL zvec_float_array_destroy(zvec_float_array_t *array);
/**
* @brief Create a new int64 array
* @param count Number of int64 values to allocate space for
* @return Pointer to the newly created int64 array, or NULL on failure
*/
ZVEC_EXPORT zvec_int64_array_t *ZVEC_CALL zvec_int64_array_create(size_t count);
/**
* @brief Destroy int64 array and free all associated memory
* @param array Int64 array pointer to destroy
*/
ZVEC_EXPORT void ZVEC_CALL zvec_int64_array_destroy(zvec_int64_array_t *array);
/**
* @brief Release uint8_t array memory
*
* @param array uint8_t array pointer
*/
ZVEC_EXPORT void ZVEC_CALL zvec_free_uint8_array(uint8_t *array);
/**
* @brief Allocate memory within the zvec library
*
* Use this function instead of malloc to ensure memory is managed consistently
* within the library. All memory allocated with zvec_malloc should be freed
* with zvec_free.
*
* @param size Number of bytes to allocate
* @return Pointer to allocated memory, or NULL on failure
*
* @see zvec_free
*/
ZVEC_EXPORT void *ZVEC_CALL zvec_malloc(size_t size);
/**
* @brief Free memory allocated by zvec_malloc or zvec library functions
*
* Use this function instead of free to ensure memory is managed consistently
* within the library. This should be used to free any memory allocated with
* zvec_malloc or returned by library functions that document they return
* library-allocated memory.
*
* @param ptr Pointer to memory to free (can be NULL)
*
* @see zvec_malloc
*/
ZVEC_EXPORT void ZVEC_CALL zvec_free(void *ptr);
// =============================================================================
// Configuration and Options Structures
// =============================================================================
/**
* @brief Log level enumeration
*/
typedef enum {
ZVEC_LOG_LEVEL_DEBUG = 0,
ZVEC_LOG_LEVEL_INFO = 1,
ZVEC_LOG_LEVEL_WARN = 2,
ZVEC_LOG_LEVEL_ERROR = 3,
ZVEC_LOG_LEVEL_FATAL = 4
} zvec_log_level_t;
/**
* @brief Log type enumeration
*/
typedef enum {
ZVEC_LOG_TYPE_CONSOLE = 0,
ZVEC_LOG_TYPE_FILE = 1
} zvec_log_type_t;
// =============================================================================
// Configuration Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Log configuration base type (opaque pointer)
* Corresponds to zvec::GlobalConfig::LogConfig
* Use factory functions to create specific log configurations:
* - zvec_config_log_create_console() for console logging
* - zvec_config_log_create_file() for file logging
*/
typedef struct zvec_log_config_t zvec_log_config_t;
/**
* @brief Configuration data (opaque pointer)
* Corresponds to zvec::GlobalConfig::ConfigData
* Use zvec_config_data_create() to create and
* zvec_config_data_destroy() to destroy
*/
typedef struct zvec_config_data_t zvec_config_data_t;
// =============================================================================
// Log Configuration Management Functions
// =============================================================================
/**
* @brief Create console log configuration
* @param level Log level
* @return zvec_log_config_t* Pointer to the newly created log configuration
*/
ZVEC_EXPORT zvec_log_config_t *ZVEC_CALL
zvec_config_log_create_console(zvec_log_level_t level);
/**
* @brief Create file log configuration
* @param level Log level
* @param dir Log directory
* @param basename Log file base name
* @param file_size Log file size (MB)
* @param overdue_days Log expiration days
* @return zvec_log_config_t* Pointer to the newly created log configuration
*/
ZVEC_EXPORT zvec_log_config_t *ZVEC_CALL zvec_config_log_create_file(
zvec_log_level_t level, const char *dir, const char *basename,
uint32_t file_size, uint32_t overdue_days);
/**
* @brief Destroy log configuration
* @param config Log configuration pointer
*/
ZVEC_EXPORT void ZVEC_CALL zvec_config_log_destroy(zvec_log_config_t *config);
/**
* @brief Get log level from log config
* @param config Log configuration pointer
* @return zvec_log_level_t Log level
*/
ZVEC_EXPORT zvec_log_level_t ZVEC_CALL
zvec_config_log_get_level(const zvec_log_config_t *config);
/**
* @brief Set log level in log config
* @param config Log configuration pointer
* @param level Log level
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_log_set_level(zvec_log_config_t *config, zvec_log_level_t level);
/**
* @brief Check if log config is file type
* @param config Log configuration pointer
* @return true if file type, false if console type
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_config_log_is_file_type(const zvec_log_config_t *config);
/**
* @brief Get log directory from file log config
* @param config Log configuration pointer (must be file type)
* @return const char* Log directory (owned by config, do not free)
* @note Only valid for file log config, returns NULL for console config
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_config_log_get_dir(const zvec_log_config_t *config);
/**
* @brief Set log directory in file log config
* @param config Log configuration pointer (must be file type)
* @param dir Log directory
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_log_set_dir(zvec_log_config_t *config, const char *dir);
/**
* @brief Get log file basename from file log config
* @param config Log configuration pointer (must be file type)
* @return const char* Log file basename (owned by config, do not free)
* @note Only valid for file log config, returns NULL for console config
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_config_log_get_basename(const zvec_log_config_t *config);
/**
* @brief Set log file basename in file log config
* @param config Log configuration pointer (must be file type)
* @param basename Log file basename
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_log_set_basename(zvec_log_config_t *config, const char *basename);
/**
* @brief Get log file size from file log config
* @param config Log configuration pointer (must be file type)
* @return uint32_t Log file size in MB
* @note Only valid for file log config, returns 0 for console config
*/
ZVEC_EXPORT uint32_t ZVEC_CALL
zvec_config_log_get_file_size(const zvec_log_config_t *config);
/**
* @brief Set log file size in file log config
* @param config Log configuration pointer (must be file type)
* @param file_size Log file size in MB
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_log_set_file_size(zvec_log_config_t *config, uint32_t file_size);
/**
* @brief Get log overdue days from file log config
* @param config Log configuration pointer (must be file type)
* @return uint32_t Log overdue days
* @note Only valid for file log config, returns 0 for console config
*/
ZVEC_EXPORT uint32_t ZVEC_CALL
zvec_config_log_get_overdue_days(const zvec_log_config_t *config);
/**
* @brief Set log overdue days in file log config
* @param config Log configuration pointer (must be file type)
* @param days Log overdue days
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_log_set_overdue_days(zvec_log_config_t *config, uint32_t days);
// =============================================================================
// Configuration Data Management Functions
// =============================================================================
/**
* @brief Create configuration data
* @return zvec_config_data_t* Pointer to the newly created configuration data
*/
ZVEC_EXPORT zvec_config_data_t *ZVEC_CALL zvec_config_data_create(void);
/**
* @brief Destroy configuration data
* @param config Configuration data pointer
*/
ZVEC_EXPORT void ZVEC_CALL zvec_config_data_destroy(zvec_config_data_t *config);
/**
* @brief Set memory limit in configuration data
* @param config Configuration data pointer
* @param memory_limit_bytes Memory limit in bytes
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_config_data_set_memory_limit(
zvec_config_data_t *config, uint64_t memory_limit_bytes);
/**
* @brief Get memory limit from configuration data
* @param config Configuration data pointer
* @return uint64_t Memory limit in bytes
*/
ZVEC_EXPORT uint64_t ZVEC_CALL
zvec_config_data_get_memory_limit(const zvec_config_data_t *config);
/**
* @brief Set log configuration in configuration data
* @param config Configuration data pointer
* @param log_config Log configuration pointer (ownership is transferred to
* config, do not free separately)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_config_data_set_log_config(
zvec_config_data_t *config, zvec_log_config_t *log_config);
/**
* @brief Get log type from configuration data
* @param config Configuration data pointer
* @return zvec_log_type_t Log type
*/
ZVEC_EXPORT zvec_log_type_t ZVEC_CALL
zvec_config_data_get_log_type(const zvec_config_data_t *config);
/**
* @brief Set query thread count in configuration data
* @param config Configuration data pointer
* @param thread_count Query thread count
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_config_data_set_query_thread_count(
zvec_config_data_t *config, uint32_t thread_count);
/**
* @brief Get query thread count from configuration data
* @param config Configuration data pointer
* @return uint32_t Query thread count
*/
ZVEC_EXPORT uint32_t ZVEC_CALL
zvec_config_data_get_query_thread_count(const zvec_config_data_t *config);
/**
* @brief Set invert to forward scan ratio in configuration data
* @param config Configuration data pointer
* @param ratio Invert to forward scan ratio
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_data_set_invert_to_forward_scan_ratio(zvec_config_data_t *config,
float ratio);
/**
* @brief Get invert to forward scan ratio from configuration data
* @param config Configuration data pointer
* @return float Invert to forward scan ratio
*/
ZVEC_EXPORT float ZVEC_CALL zvec_config_data_get_invert_to_forward_scan_ratio(
const zvec_config_data_t *config);
/**
* @brief Set brute force by keys ratio in configuration data
* @param config Configuration data pointer
* @param ratio Brute force by keys ratio
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_data_set_brute_force_by_keys_ratio(zvec_config_data_t *config,
float ratio);
/**
* @brief Get brute force by keys ratio from configuration data
* @param config Configuration data pointer
* @return float Brute force by keys ratio
*/
ZVEC_EXPORT float ZVEC_CALL zvec_config_data_get_brute_force_by_keys_ratio(
const zvec_config_data_t *config);
/**
* @brief Set optimize thread count in configuration data
* @param config Configuration data pointer
* @param thread_count Optimize thread count
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_config_data_set_optimize_thread_count(zvec_config_data_t *config,
uint32_t thread_count);
/**
* @brief Get optimize thread count from configuration data
* @param config Configuration data pointer
* @return uint32_t Optimize thread count
*/
ZVEC_EXPORT uint32_t ZVEC_CALL
zvec_config_data_get_optimize_thread_count(const zvec_config_data_t *config);
// =============================================================================
// Initialization and Cleanup Interface
// =============================================================================
/**
* @brief Initialize ZVec library
* @param config Configuration data (optional, NULL means using default
* configuration)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_initialize(const zvec_config_data_t *config);
/**
* @brief Clean up ZVec library resources
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_shutdown(void);
/**
* @brief Check if library is initialized
* @return true if initialized, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_is_initialized(void);
// =============================================================================
// Data Type Enumerations
// =============================================================================
/**
* @brief Data type codes (must match zvec::DataType in zvec/db/type.h)
*
* These are defined as uint32_t constants instead of C enums to ensure
* consistent binary representation across C and C++ boundaries.
*/
typedef uint32_t zvec_data_type_t;
#define ZVEC_DATA_TYPE_UNDEFINED 0
#define ZVEC_DATA_TYPE_BINARY 1
#define ZVEC_DATA_TYPE_STRING 2
#define ZVEC_DATA_TYPE_BOOL 3
#define ZVEC_DATA_TYPE_INT32 4
#define ZVEC_DATA_TYPE_INT64 5
#define ZVEC_DATA_TYPE_UINT32 6
#define ZVEC_DATA_TYPE_UINT64 7
#define ZVEC_DATA_TYPE_FLOAT 8
#define ZVEC_DATA_TYPE_DOUBLE 9
#define ZVEC_DATA_TYPE_VECTOR_BINARY32 20
#define ZVEC_DATA_TYPE_VECTOR_BINARY64 21
#define ZVEC_DATA_TYPE_VECTOR_FP16 22
#define ZVEC_DATA_TYPE_VECTOR_FP32 23
#define ZVEC_DATA_TYPE_VECTOR_FP64 24
#define ZVEC_DATA_TYPE_VECTOR_INT4 25
#define ZVEC_DATA_TYPE_VECTOR_INT8 26
#define ZVEC_DATA_TYPE_VECTOR_INT16 27
#define ZVEC_DATA_TYPE_SPARSE_VECTOR_FP16 30
#define ZVEC_DATA_TYPE_SPARSE_VECTOR_FP32 31
#define ZVEC_DATA_TYPE_ARRAY_BINARY 40
#define ZVEC_DATA_TYPE_ARRAY_STRING 41
#define ZVEC_DATA_TYPE_ARRAY_BOOL 42
#define ZVEC_DATA_TYPE_ARRAY_INT32 43
#define ZVEC_DATA_TYPE_ARRAY_INT64 44
#define ZVEC_DATA_TYPE_ARRAY_UINT32 45
#define ZVEC_DATA_TYPE_ARRAY_UINT64 46
#define ZVEC_DATA_TYPE_ARRAY_FLOAT 47
#define ZVEC_DATA_TYPE_ARRAY_DOUBLE 48
/**
* @brief Index type codes (must match zvec::IndexType in zvec/db/type.h)
*
* These are defined as uint32_t constants instead of C enums to ensure
* consistent binary representation across C and C++ boundaries.
*/
typedef uint32_t zvec_index_type_t;
#define ZVEC_INDEX_TYPE_UNDEFINED 0
#define ZVEC_INDEX_TYPE_HNSW 1
#define ZVEC_INDEX_TYPE_IVF 2
#define ZVEC_INDEX_TYPE_FLAT 3
#define ZVEC_INDEX_TYPE_INVERT 10
/**
* @brief Distance metric type codes (must match zvec::MetricType in
* zvec/db/type.h)
*
* These are defined as uint32_t constants instead of C enums to ensure
* consistent binary representation across C and C++ boundaries.
*/
typedef uint32_t zvec_metric_type_t;
#define ZVEC_METRIC_TYPE_UNDEFINED 0
#define ZVEC_METRIC_TYPE_L2 1
#define ZVEC_METRIC_TYPE_IP 2
#define ZVEC_METRIC_TYPE_COSINE 3
#define ZVEC_METRIC_TYPE_MIPSL2 4
/**
* @brief Quantization type codes (must match zvec::QuantizeType in
* zvec/db/type.h)
*
* These are defined as uint32_t constants instead of C enums to ensure
* consistent binary representation across C and C++ boundaries.
*/
typedef uint32_t zvec_quantize_type_t;
#define ZVEC_QUANTIZE_TYPE_UNDEFINED 0
#define ZVEC_QUANTIZE_TYPE_FP16 1
#define ZVEC_QUANTIZE_TYPE_INT8 2
#define ZVEC_QUANTIZE_TYPE_INT4 3
// =============================================================================
// Collection Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Collection handle (opaque pointer)
*
* Internally maps to std::shared_ptr<zvec::Collection>*.
* Managed by zvec_collection_create/open() and zvec_collection_close().
*/
typedef struct zvec_collection_t zvec_collection_t;
// =============================================================================
// Index Parameters Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Index parameters (opaque pointer)
*
* Use zvec_index_params_create() to create and zvec_index_params_destroy() to
* destroy. Specific parameters are set via type-specific setter functions.
*/
typedef struct zvec_index_params_t zvec_index_params_t;
// =============================================================================
// Field Schema Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Field schema handle (opaque pointer)
*
* Internally maps to zvec::FieldSchema* (raw pointer).
* Created by zvec_field_schema_create() and destroyed by
* zvec_field_schema_destroy(). Caller owns the pointer and must explicitly
* destroy it.
*/
typedef struct zvec_field_schema_t zvec_field_schema_t;
// =============================================================================
// Index Parameters Functions
// =============================================================================
/**
* @brief Create index parameters
* @param index_type Index type
* @return Pointer to newly created zvec_index_params_t, or NULL on error
*/
ZVEC_EXPORT zvec_index_params_t *ZVEC_CALL
zvec_index_params_create(zvec_index_type_t index_type);
/**
* @brief Destroy index parameters
* @param params Index parameters to destroy
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_index_params_destroy(zvec_index_params_t *params);
// =============================================================================
// Collection Schema Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Get index type
* @param params Index parameters (must not be NULL)
* @return Index type
*/
ZVEC_EXPORT zvec_index_type_t ZVEC_CALL
zvec_index_params_get_type(const zvec_index_params_t *params);
/**
* @brief Set metric type (for vector indexes)
* @param params Index parameters (must be vector index type)
* @param metric_type Metric type
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_set_metric_type(
zvec_index_params_t *params, zvec_metric_type_t metric_type);
/**
* @brief Get metric type
* @param params Index parameters (must not be NULL)
* @return Metric type
*/
ZVEC_EXPORT zvec_metric_type_t ZVEC_CALL
zvec_index_params_get_metric_type(const zvec_index_params_t *params);
/**
* @brief Set quantize type (for vector indexes)
* @param params Index parameters (must be vector index type)
* @param quantize_type Quantize type
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_set_quantize_type(
zvec_index_params_t *params, zvec_quantize_type_t quantize_type);
/**
* @brief Get quantize type
* @param params Index parameters (must not be NULL)
* @return Quantize type
*/
ZVEC_EXPORT zvec_quantize_type_t ZVEC_CALL
zvec_index_params_get_quantize_type(const zvec_index_params_t *params);
/**
* @brief Set HNSW specific parameters
* @param params Index parameters (must be HNSW type)
* @param m Graph connectivity parameter
* @param ef_construction Construction exploration factor
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_set_hnsw_params(
zvec_index_params_t *params, int m, int ef_construction);
/**
* @brief Get HNSW m parameter
* @param params Index parameters (must not be NULL)
* @return m parameter
*/
ZVEC_EXPORT int ZVEC_CALL
zvec_index_params_get_hnsw_m(const zvec_index_params_t *params);
/**
* @brief Get HNSW ef_construction parameter
* @param params Index parameters (must not be NULL)
* @return ef_construction parameter
*/
ZVEC_EXPORT int ZVEC_CALL
zvec_index_params_get_hnsw_ef_construction(const zvec_index_params_t *params);
/**
* @brief Set IVF specific parameters
* @param params Index parameters (must be IVF type)
* @param n_list Number of cluster centers
* @param n_iters Number of iterations
* @param use_soar Whether to use SOAR algorithm
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_set_ivf_params(
zvec_index_params_t *params, int n_list, int n_iters, bool use_soar);
/**
* @brief Get IVF parameters (all at once)
* @param params Index parameters (must not be NULL)
* @param out_n_list Output parameter for n_list
* @param out_n_iters Output parameter for n_iters
* @param out_use_soar Output parameter for use_soar
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_get_ivf_params(
const zvec_index_params_t *params, int *out_n_list, int *out_n_iters,
bool *out_use_soar);
/**
* @brief Get invert index parameters (all at once)
* @param params Index parameters (must not be NULL)
* @param out_enable_range_opt Output parameter for enable_range_optimization
* @param out_enable_wildcard Output parameter for enable_extended_wildcard
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_get_invert_params(
const zvec_index_params_t *params, bool *out_enable_range_opt,
bool *out_enable_wildcard);
/**
* @brief Set invert index specific parameters
* @param params Index parameters (must be INVERT type)
* @param enable_range_opt Whether to enable range optimization
* @param enable_wildcard Whether to enable extended wildcard
* @return ZVEC_OK on success, error code on failure
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_index_params_set_invert_params(
zvec_index_params_t *params, bool enable_range_opt, bool enable_wildcard);
// =============================================================================
// Query Parameters Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief HNSW query parameters handle (opaque pointer)
*
* Internally maps to zvec::HnswQueryParams* (raw pointer).
* Created by zvec_query_params_hnsw_create() and destroyed by
* zvec_query_params_hnsw_destroy(). Caller owns the pointer and must explicitly
* destroy it.
*/
typedef struct zvec_hnsw_query_params_t zvec_hnsw_query_params_t;
/**
* @brief IVF query parameters handle (opaque pointer)
*
* Internally maps to zvec::IVFQueryParams* (raw pointer).
* Created by zvec_query_params_ivf_create() and destroyed by
* zvec_query_params_ivf_destroy(). Caller owns the pointer and must explicitly
* destroy it.
*/
typedef struct zvec_ivf_query_params_t zvec_ivf_query_params_t;
/**
* @brief Flat query parameters handle (opaque pointer)
*
* Internally maps to zvec::FlatQueryParams* (raw pointer).
* Created by zvec_query_params_flat_create() and destroyed by
* zvec_query_params_flat_destroy(). Caller owns the pointer and must explicitly
* destroy it.
*/
typedef struct zvec_flat_query_params_t zvec_flat_query_params_t;
// =============================================================================
// Query Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Vector query structure (opaque pointer)
* Aligned with zvec::VectorQuery
* Use zvec_vector_query_create() to create and zvec_vector_query_destroy() to
* destroy
*/
typedef struct zvec_vector_query_t zvec_vector_query_t;
/**
* @brief Grouped vector query structure (opaque pointer)
* Aligned with zvec::GroupByVectorQuery
* Use zvec_group_by_vector_query_create() to create and
* zvec_group_by_vector_query_destroy() to destroy
*/
typedef struct zvec_group_by_vector_query_t zvec_group_by_vector_query_t;
// =============================================================================
// Query Parameters Management Functions
// =============================================================================
// -----------------------------------------------------------------------------
// zvec_hnsw_query_params_t (HNSW Query Parameters)
// -----------------------------------------------------------------------------
/**
* @brief Create HNSW query parameters
* @param ef Exploration factor during search (default: 40)
* @param radius Search radius (default: 0.0)
* @param is_linear Whether linear search (default: false)
* @param is_using_refiner Whether using refiner (default: false)
* @return zvec_hnsw_query_params_t* Pointer to the newly created HNSW query
* parameters
*/
ZVEC_EXPORT zvec_hnsw_query_params_t *ZVEC_CALL zvec_query_params_hnsw_create(
int ef, float radius, bool is_linear, bool is_using_refiner);
/**
* @brief Destroy HNSW query parameters
* @param params HNSW query parameters pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_query_params_hnsw_destroy(zvec_hnsw_query_params_t *params);
/**
* @brief Set exploration factor
* @param params HNSW query parameters pointer
* @param ef Exploration factor
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_query_params_hnsw_set_ef(zvec_hnsw_query_params_t *params, int ef);
/**
* @brief Get exploration factor
* @param params HNSW query parameters pointer
* @return int Exploration factor
*/
ZVEC_EXPORT int ZVEC_CALL
zvec_query_params_hnsw_get_ef(const zvec_hnsw_query_params_t *params);
/**
* @brief Set search radius (common parameter from QueryParams base)
* @param params HNSW query parameters pointer
* @param radius Search radius
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_hnsw_set_radius(
zvec_hnsw_query_params_t *params, float radius);
/**
* @brief Get search radius (common parameter from QueryParams base)
* @param params HNSW query parameters pointer
* @return float Search radius
*/
ZVEC_EXPORT float ZVEC_CALL
zvec_query_params_hnsw_get_radius(const zvec_hnsw_query_params_t *params);
/**
* @brief Set linear search mode (common parameter from QueryParams base)
* @param params HNSW query parameters pointer
* @param is_linear Whether linear search
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_hnsw_set_is_linear(
zvec_hnsw_query_params_t *params, bool is_linear);
/**
* @brief Get linear search mode (common parameter from QueryParams base)
* @param params HNSW query parameters pointer
* @return bool Whether linear search
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_query_params_hnsw_get_is_linear(const zvec_hnsw_query_params_t *params);
/**
* @brief Set whether to use refiner (common parameter from QueryParams base)
* @param params HNSW query parameters pointer
* @param is_using_refiner Whether to use refiner
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_query_params_hnsw_set_is_using_refiner(zvec_hnsw_query_params_t *params,
bool is_using_refiner);
/**
* @brief Get whether to use refiner (common parameter from QueryParams base)
* @param params HNSW query parameters pointer
* @return bool Whether to use refiner
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_query_params_hnsw_get_is_using_refiner(
const zvec_hnsw_query_params_t *params);
// -----------------------------------------------------------------------------
// zvec_ivf_query_params_t (IVF Query Parameters)
// -----------------------------------------------------------------------------
/**
* @brief Create IVF query parameters
* @param nprobe Number of clusters to probe (default: 10)
* @param is_using_refiner Whether using refiner (default: false)
* @param scale_factor Scale factor (default: 10.0)
* @return zvec_ivf_query_params_t* Pointer to the newly created IVF query
* parameters
*/
ZVEC_EXPORT zvec_ivf_query_params_t *ZVEC_CALL zvec_query_params_ivf_create(
int nprobe, bool is_using_refiner, float scale_factor);
/**
* @brief Destroy IVF query parameters
* @param params IVF query parameters pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_query_params_ivf_destroy(zvec_ivf_query_params_t *params);
/**
* @brief Set number of probe clusters
* @param params IVF query parameters pointer
* @param nprobe Number of probe clusters
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_query_params_ivf_set_nprobe(zvec_ivf_query_params_t *params, int nprobe);
/**
* @brief Get number of probe clusters
* @param params IVF query parameters pointer
* @return int Number of probe clusters
*/
ZVEC_EXPORT int ZVEC_CALL
zvec_query_params_ivf_get_nprobe(const zvec_ivf_query_params_t *params);
/**
* @brief Set scale factor
* @param params IVF query parameters pointer
* @param scale_factor Scale factor
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_ivf_set_scale_factor(
zvec_ivf_query_params_t *params, float scale_factor);
/**
* @brief Get scale factor
* @param params IVF query parameters pointer
* @return float Scale factor
*/
ZVEC_EXPORT float ZVEC_CALL
zvec_query_params_ivf_get_scale_factor(const zvec_ivf_query_params_t *params);
/**
* @brief Set search radius (common parameter from QueryParams base)
* @param params IVF query parameters pointer
* @param radius Search radius
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_query_params_ivf_set_radius(zvec_ivf_query_params_t *params, float radius);
/**
* @brief Get search radius (common parameter from QueryParams base)
* @param params IVF query parameters pointer
* @return float Search radius
*/
ZVEC_EXPORT float ZVEC_CALL
zvec_query_params_ivf_get_radius(const zvec_ivf_query_params_t *params);
/**
* @brief Set linear search mode (common parameter from QueryParams base)
* @param params IVF query parameters pointer
* @param is_linear Whether linear search
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_ivf_set_is_linear(
zvec_ivf_query_params_t *params, bool is_linear);
/**
* @brief Get linear search mode (common parameter from QueryParams base)
* @param params IVF query parameters pointer
* @return bool Whether linear search
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_query_params_ivf_get_is_linear(const zvec_ivf_query_params_t *params);
/**
* @brief Set whether to use refiner (common parameter from QueryParams base)
* @param params IVF query parameters pointer
* @param is_using_refiner Whether to use refiner
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_query_params_ivf_set_is_using_refiner(zvec_ivf_query_params_t *params,
bool is_using_refiner);
/**
* @brief Get whether to use refiner (common parameter from QueryParams base)
* @param params IVF query parameters pointer
* @return bool Whether to use refiner
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_query_params_ivf_get_is_using_refiner(
const zvec_ivf_query_params_t *params);
// -----------------------------------------------------------------------------
// zvec_flat_query_params_t (Flat Query Parameters)
// -----------------------------------------------------------------------------
/**
* @brief Create Flat query parameters
* @param is_using_refiner Whether using refiner (default: false)
* @param scale_factor Scale factor (default: 10.0)
* @return zvec_flat_query_params_t* Pointer to the newly created Flat query
* parameters
*/
ZVEC_EXPORT zvec_flat_query_params_t *ZVEC_CALL
zvec_query_params_flat_create(bool is_using_refiner, float scale_factor);
/**
* @brief Destroy Flat query parameters
* @param params Flat query parameters pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_query_params_flat_destroy(zvec_flat_query_params_t *params);
/**
* @brief Set scale factor
* @param params Flat query parameters pointer
* @param scale_factor Scale factor
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_flat_set_scale_factor(
zvec_flat_query_params_t *params, float scale_factor);
/**
* @brief Get scale factor
* @param params Flat query parameters pointer
* @return float Scale factor
*/
ZVEC_EXPORT float ZVEC_CALL
zvec_query_params_flat_get_scale_factor(const zvec_flat_query_params_t *params);
/**
* @brief Set search radius (common parameter from QueryParams base)
* @param params Flat query parameters pointer
* @param radius Search radius
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_flat_set_radius(
zvec_flat_query_params_t *params, float radius);
/**
* @brief Get search radius (common parameter from QueryParams base)
* @param params Flat query parameters pointer
* @return float Search radius
*/
ZVEC_EXPORT float ZVEC_CALL
zvec_query_params_flat_get_radius(const zvec_flat_query_params_t *params);
/**
* @brief Set linear search mode (common parameter from QueryParams base)
* @param params Flat query parameters pointer
* @param is_linear Whether linear search
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_query_params_flat_set_is_linear(
zvec_flat_query_params_t *params, bool is_linear);
/**
* @brief Get linear search mode (common parameter from QueryParams base)
* @param params Flat query parameters pointer
* @return bool Whether linear search
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_query_params_flat_get_is_linear(const zvec_flat_query_params_t *params);
/**
* @brief Set whether to use refiner (common parameter from QueryParams base)
* @param params Flat query parameters pointer
* @param is_using_refiner Whether to use refiner
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_query_params_flat_set_is_using_refiner(zvec_flat_query_params_t *params,
bool is_using_refiner);
/**
* @brief Get whether to use refiner (common parameter from QueryParams base)
* @param params Flat query parameters pointer
* @return bool Whether to use refiner
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_query_params_flat_get_is_using_refiner(
const zvec_flat_query_params_t *params);
// -----------------------------------------------------------------------------
// zvec_vector_query_t (Vector Query)
// -----------------------------------------------------------------------------
/**
* @brief Create vector query
* @return zvec_vector_query_t* Pointer to the newly created vector query
*/
ZVEC_EXPORT zvec_vector_query_t *ZVEC_CALL zvec_vector_query_create(void);
/**
* @brief Destroy vector query
* @param query Vector query pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_vector_query_destroy(zvec_vector_query_t *query);
/**
* @brief Set topk (number of results to return)
* @param query Vector query pointer
* @param topk Number of results
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_vector_query_set_topk(zvec_vector_query_t *query, int topk);
/**
* @brief Get topk
* @param query Vector query pointer
* @return int Number of results
*/
ZVEC_EXPORT int ZVEC_CALL
zvec_vector_query_get_topk(const zvec_vector_query_t *query);
/**
* @brief Set field name
* @param query Vector query pointer
* @param field_name Field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_set_field_name(
zvec_vector_query_t *query, const char *field_name);
/**
* @brief Get field name
* @param query Vector query pointer
* @return const char* Field name (owned by query, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_vector_query_get_field_name(const zvec_vector_query_t *query);
/**
* @brief Set query vector data
* @param query Vector query pointer
* @param data Vector data pointer
* @param size Data size in bytes
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_set_query_vector(
zvec_vector_query_t *query, const void *data, size_t size);
/**
* @brief Set filter expression
* @param query Vector query pointer
* @param filter Filter expression string
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_vector_query_set_filter(zvec_vector_query_t *query, const char *filter);
/**
* @brief Get filter expression
* @param query Vector query pointer
* @return const char* Filter expression (owned by query, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_vector_query_get_filter(const zvec_vector_query_t *query);
/**
* @brief Set whether to include vector data in results
* @param query Vector query pointer
* @param include Whether to include vector
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_vector_query_set_include_vector(zvec_vector_query_t *query, bool include);
/**
* @brief Get whether to include vector data in results
* @param query Vector query pointer
* @return bool Whether to include vector
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_vector_query_get_include_vector(const zvec_vector_query_t *query);
/**
* @brief Set whether to include doc ID in results
* @param query Vector query pointer
* @param include Whether to include doc ID
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_vector_query_set_include_doc_id(zvec_vector_query_t *query, bool include);
/**
* @brief Get whether to include doc ID in results
* @param query Vector query pointer
* @return bool Whether to include doc ID
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_vector_query_get_include_doc_id(const zvec_vector_query_t *query);
/**
* @brief Set output fields
* @param query Vector query pointer
* @param fields Array of field names
* @param count Number of fields
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_set_output_fields(
zvec_vector_query_t *query, const char **fields, size_t count);
/**
* @brief Get output fields
* @param query Vector query pointer
* @param[out] fields Output array of field names (allocated by library)
* @param[out] count Number of fields
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual string pointers
* are owned by the query and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_get_output_fields(
const zvec_vector_query_t *query, const char ***fields, size_t *count);
/**
* @brief Set query parameters (takes ownership)
* @param query Vector query pointer
* @param params Query parameters pointer (type-specific:
* zvec_hnsw_query_params_t*, etc.)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_vector_query_set_query_params(zvec_vector_query_t *query, void *params);
/**
* @brief Set HNSW query parameters (takes ownership)
* @param query Vector query pointer
* @param hnsw_params HNSW query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_set_hnsw_params(
zvec_vector_query_t *query, zvec_hnsw_query_params_t *hnsw_params);
/**
* @brief Set IVF query parameters (takes ownership)
* @param query Vector query pointer
* @param ivf_params IVF query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_set_ivf_params(
zvec_vector_query_t *query, zvec_ivf_query_params_t *ivf_params);
/**
* @brief Set Flat query parameters (takes ownership)
* @param query Vector query pointer
* @param flat_params Flat query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_vector_query_set_flat_params(
zvec_vector_query_t *query, zvec_flat_query_params_t *flat_params);
// -----------------------------------------------------------------------------
// zvec_group_by_vector_query_t (Group By Vector Query)
// -----------------------------------------------------------------------------
/**
* @brief Create group by vector query
* @return zvec_group_by_vector_query_t* Pointer to the newly created group by
* vector query
*/
ZVEC_EXPORT zvec_group_by_vector_query_t *ZVEC_CALL
zvec_group_by_vector_query_create(void);
/**
* @brief Destroy group by vector query
* @param query Group by vector query pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_group_by_vector_query_destroy(zvec_group_by_vector_query_t *query);
/**
* @brief Set field name
* @param query Group by vector query pointer
* @param field_name Field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_field_name(zvec_group_by_vector_query_t *query,
const char *field_name);
/**
* @brief Get field name
* @param query Group by vector query pointer
* @return const char* Field name (owned by query, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL zvec_group_by_vector_query_get_field_name(
const zvec_group_by_vector_query_t *query);
/**
* @brief Set group by field name
* @param query Group by vector query pointer
* @param field_name Group by field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_group_by_field_name(
zvec_group_by_vector_query_t *query, const char *field_name);
/**
* @brief Get group by field name
* @param query Group by vector query pointer
* @return const char* Group by field name (owned by query, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_group_by_vector_query_get_group_by_field_name(
const zvec_group_by_vector_query_t *query);
/**
* @brief Set group count
* @param query Group by vector query pointer
* @param count Number of groups
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_group_count(zvec_group_by_vector_query_t *query,
uint32_t count);
/**
* @brief Get group count
* @param query Group by vector query pointer
* @return uint32_t Number of groups
*/
ZVEC_EXPORT uint32_t ZVEC_CALL zvec_group_by_vector_query_get_group_count(
const zvec_group_by_vector_query_t *query);
/**
* @brief Set group topk
* @param query Group by vector query pointer
* @param topk Number of results per group
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_group_topk(zvec_group_by_vector_query_t *query,
uint32_t topk);
/**
* @brief Get group topk
* @param query Group by vector query pointer
* @return uint32_t Number of results per group
*/
ZVEC_EXPORT uint32_t ZVEC_CALL zvec_group_by_vector_query_get_group_topk(
const zvec_group_by_vector_query_t *query);
/**
* @brief Set query vector data
* @param query Group by vector query pointer
* @param data Vector data pointer
* @param size Data size in bytes
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_query_vector(zvec_group_by_vector_query_t *query,
const void *data, size_t size);
/**
* @brief Set filter expression
* @param query Group by vector query pointer
* @param filter Filter expression string
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_group_by_vector_query_set_filter(
zvec_group_by_vector_query_t *query, const char *filter);
/**
* @brief Get filter expression
* @param query Group by vector query pointer
* @return const char* Filter expression (owned by query, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL zvec_group_by_vector_query_get_filter(
const zvec_group_by_vector_query_t *query);
/**
* @brief Set whether to include vector data in results
* @param query Group by vector query pointer
* @param include Whether to include vectors
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_include_vector(
zvec_group_by_vector_query_t *query, bool include);
/**
* @brief Get whether to include vector data in results
* @param query Group by vector query pointer
* @return bool Whether to include vectors
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_group_by_vector_query_get_include_vector(
const zvec_group_by_vector_query_t *query);
/**
* @brief Set output fields
* @param query Group by vector query pointer
* @param fields Array of field names
* @param count Number of fields
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_output_fields(
zvec_group_by_vector_query_t *query, const char **fields, size_t count);
/**
* @brief Get output fields
* @param query Group by vector query pointer
* @param[out] fields Output array of field names (allocated by library)
* @param[out] count Number of fields
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual string pointers
* are owned by the query and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_get_output_fields(
zvec_group_by_vector_query_t *query, const char ***fields, size_t *count);
/**
* @brief Set query parameters (takes ownership)
* @param query Group by vector query pointer
* @param params Query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_query_params(zvec_group_by_vector_query_t *query,
void *params);
/**
* @brief Set HNSW query parameters (takes ownership)
* @param query Group by vector query pointer
* @param hnsw_params HNSW query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_hnsw_params(
zvec_group_by_vector_query_t *query, zvec_hnsw_query_params_t *hnsw_params);
/**
* @brief Set IVF query parameters (takes ownership)
* @param query Group by vector query pointer
* @param ivf_params IVF query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_ivf_params(zvec_group_by_vector_query_t *query,
zvec_ivf_query_params_t *ivf_params);
/**
* @brief Set Flat query parameters (takes ownership)
* @param query Group by vector query pointer
* @param flat_params Flat query parameters pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_group_by_vector_query_set_flat_params(
zvec_group_by_vector_query_t *query, zvec_flat_query_params_t *flat_params);
// =============================================================================
// Collection Options and Statistics (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Collection options (opaque pointer)
* Use zvec_collection_options_create() to create and
* zvec_collection_options_destroy() to destroy
*/
typedef struct zvec_collection_options_t zvec_collection_options_t;
/**
* @brief Collection statistics (opaque pointer)
* Use zvec_collection_stats_get functions to access fields
*/
typedef struct zvec_collection_stats_t zvec_collection_stats_t;
// =============================================================================
// Collection Options Management Functions
// =============================================================================
/**
* @brief Create collection options
* @return zvec_collection_options_t* Pointer to the newly created collection
* options
*/
ZVEC_EXPORT zvec_collection_options_t *ZVEC_CALL
zvec_collection_options_create(void);
/**
* @brief Destroy collection options
* @param options Collection options pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_collection_options_destroy(zvec_collection_options_t *options);
/**
* @brief Set whether to enable memory mapping
* @param options Collection options pointer
* @param enable Whether to enable mmap
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_options_set_enable_mmap(
zvec_collection_options_t *options, bool enable);
/**
* @brief Get whether to enable memory mapping
* @param options Collection options pointer
* @return bool Whether mmap is enabled
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_collection_options_get_enable_mmap(
const zvec_collection_options_t *options);
/**
* @brief Set maximum buffer size
* @param options Collection options pointer
* @param size Maximum buffer size in bytes
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_options_set_max_buffer_size(zvec_collection_options_t *options,
size_t size);
/**
* @brief Get maximum buffer size
* @param options Collection options pointer
* @return size_t Maximum buffer size in bytes
*/
ZVEC_EXPORT size_t ZVEC_CALL zvec_collection_options_get_max_buffer_size(
const zvec_collection_options_t *options);
/**
* @brief Set whether read-only mode
* @param options Collection options pointer
* @param read_only Whether read-only
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_options_set_read_only(
zvec_collection_options_t *options, bool read_only);
/**
* @brief Get whether read-only mode
* @param options Collection options pointer
* @return bool Whether read-only mode
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_collection_options_get_read_only(const zvec_collection_options_t *options);
// =============================================================================
// Collection Statistics Management Functions
// =============================================================================
/**
* @brief Get document count from collection stats
* @param stats Collection statistics pointer
* @return uint64_t Document count
*/
ZVEC_EXPORT uint64_t ZVEC_CALL
zvec_collection_stats_get_doc_count(const zvec_collection_stats_t *stats);
/**
* @brief Get index count from collection stats
* @param stats Collection statistics pointer
* @return size_t Number of indexes
*/
ZVEC_EXPORT size_t ZVEC_CALL
zvec_collection_stats_get_index_count(const zvec_collection_stats_t *stats);
/**
* @brief Get index name at specified index
* @param stats Collection statistics pointer
* @param index Index of the index name
* @return const char* Index name (owned by stats, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL zvec_collection_stats_get_index_name(
const zvec_collection_stats_t *stats, size_t index);
/**
* @brief Get index completeness at specified index
* @param stats Collection statistics pointer
* @param index Index of the completeness value
* @return float Index completeness
*/
ZVEC_EXPORT float ZVEC_CALL zvec_collection_stats_get_index_completeness(
const zvec_collection_stats_t *stats, size_t index);
/**
* @brief Create field schema
* @param name Field name
* @param data_type Data type
* @param nullable Whether nullable
* @param dimension Vector dimension
* @return zvec_field_schema_t* Pointer to the newly created field schema
*/
ZVEC_EXPORT zvec_field_schema_t *ZVEC_CALL
zvec_field_schema_create(const char *name, zvec_data_type_t data_type,
bool nullable, uint32_t dimension);
/**
* @brief Destroy field schema
* @param schema Field schema pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_field_schema_destroy(zvec_field_schema_t *schema);
/**
* @brief Set field name
* @param schema Field schema pointer
* @param name New field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_field_schema_set_name(zvec_field_schema_t *schema, const char *name);
/**
* @brief Get field name
* @param schema Field schema pointer (must not be NULL)
* @return const char* Field name (owned by schema, do not free)
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_field_schema_get_name(const zvec_field_schema_t *schema);
/**
* @brief Get field data type
* @param schema Field schema pointer (must not be NULL)
* @return zvec_data_type_t Data type
*/
ZVEC_EXPORT zvec_data_type_t ZVEC_CALL
zvec_field_schema_get_data_type(const zvec_field_schema_t *schema);
/**
* @brief Set field data type
* @param schema Field schema pointer
* @param data_type New data type
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_field_schema_set_data_type(
zvec_field_schema_t *schema, zvec_data_type_t data_type);
/**
* @brief Get element data type for array fields
* @param schema Field schema pointer (must not be NULL)
* @return zvec_data_type_t Element data type, or original type if not array
*/
ZVEC_EXPORT zvec_data_type_t ZVEC_CALL
zvec_field_schema_get_element_data_type(const zvec_field_schema_t *schema);
/**
* @brief Get element data size for the field
* @param schema Field schema pointer (must not be NULL)
* @return size_t Element data size in bytes, or 0 for variable-size types
*/
ZVEC_EXPORT size_t ZVEC_CALL
zvec_field_schema_get_element_data_size(const zvec_field_schema_t *schema);
/**
* @brief Check if field is a vector field (dense or sparse)
* @param schema Field schema pointer (must not be NULL)
* @return bool true if vector field, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_is_vector_field(const zvec_field_schema_t *schema);
/**
* @brief Check if field is a dense vector field
* @param schema Field schema pointer (must not be NULL)
* @return bool true if dense vector field, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_is_dense_vector(const zvec_field_schema_t *schema);
/**
* @brief Check if field is a sparse vector field
* @param schema Field schema pointer (must not be NULL)
* @return bool true if sparse vector field, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_is_sparse_vector(const zvec_field_schema_t *schema);
/**
* @brief Check if field is nullable
* @param schema Field schema pointer (must not be NULL)
* @return bool true if nullable, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_is_nullable(const zvec_field_schema_t *schema);
/**
* @brief Set field nullable
* @param schema Field schema pointer
* @param nullable Whether nullable
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_field_schema_set_nullable(zvec_field_schema_t *schema, bool nullable);
/**
* @brief Check if field has inverted index (for scalar fields)
* @param schema Field schema pointer (must not be NULL)
* @return bool true if has inverted index, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_has_invert_index(const zvec_field_schema_t *schema);
/**
* @brief Check if field is an array type
* @param schema Field schema pointer (must not be NULL)
* @return bool true if array type, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_is_array_type(const zvec_field_schema_t *schema);
/**
* @brief Get field dimension (for vector fields)
* @param schema Field schema pointer (must not be NULL)
* @return uint32_t Dimension value
*/
ZVEC_EXPORT uint32_t ZVEC_CALL
zvec_field_schema_get_dimension(const zvec_field_schema_t *schema);
/**
* @brief Set field dimension (for vector fields)
* @param schema Field schema pointer
* @param dimension Dimension value
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_field_schema_set_dimension(
zvec_field_schema_t *schema, uint32_t dimension);
/**
* @brief Get index type of the field
* @param schema Field schema pointer (must not be NULL)
* @return zvec_index_type_t Index type, ZVEC_INDEX_TYPE_UNDEFINED if no index
*/
ZVEC_EXPORT zvec_index_type_t ZVEC_CALL
zvec_field_schema_get_index_type(const zvec_field_schema_t *schema);
/**
* @brief Check if field has index
* @param schema Field schema pointer (must not be NULL)
* @return bool true if field has index, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL
zvec_field_schema_has_index(const zvec_field_schema_t *schema);
/**
* @brief Get index params of the field (returns pointer owned by the field
* schema, do not destroy. Pointer becomes invalid if schema is modified or
* destroyed)
* @param schema Field schema pointer (must not be NULL)
* @return zvec_index_params_t* Index params pointer, NULL if no index
*/
ZVEC_EXPORT const zvec_index_params_t *ZVEC_CALL
zvec_field_schema_get_index_params(const zvec_field_schema_t *schema);
/**
* @brief Set index parameters for field
* @param schema Field schema pointer
* @param index_params Index parameters pointer (deep-copied internally, caller
* retains ownership and must call zvec_index_params_destroy
* after the call)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_field_schema_set_index_params(
zvec_field_schema_t *schema, const zvec_index_params_t *index_params);
/**
* @brief Validate field schema
* @param schema Field schema pointer
* @param[out] error_msg Error message (needs to be freed by calling
* zvec_free_string)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_field_schema_validate(
const zvec_field_schema_t *schema, zvec_string_t **error_msg);
// =============================================================================
// Collection Schema Structures (Opaque Pointer Pattern)
// =============================================================================
/**
* @brief Collection schema handle (opaque pointer)
*
* Internally maps to zvec::CollectionSchema* (raw pointer).
* Created by zvec_collection_schema_create() and destroyed by
* zvec_collection_schema_destroy(). Caller owns the pointer and must explicitly
* destroy it.
*/
typedef struct zvec_collection_schema_t zvec_collection_schema_t;
/**
* @brief Create collection schema
* @param name Collection name
* @return zvec_collection_schema_t* Pointer to the newly created collection
* schema
*/
ZVEC_EXPORT zvec_collection_schema_t *ZVEC_CALL
zvec_collection_schema_create(const char *name);
/**
* @brief Destroy collection schema
* @param schema Collection schema pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_collection_schema_destroy(zvec_collection_schema_t *schema);
/**
* @brief Get collection schema name
* @param schema Collection schema pointer (must not be NULL)
* @return const char* Collection name string pointer
*
* @note Returns a pointer to internal memory. Caller does NOT own the memory
* and should NOT free it. The pointer is valid as long as the schema
* exists.
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_collection_schema_get_name(const zvec_collection_schema_t *schema);
/**
* @brief Set collection schema name
* @param schema Collection schema pointer
* @param name New collection name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_set_name(
zvec_collection_schema_t *schema, const char *name);
/**
* @brief Add field to collection schema
* @param schema Collection schema pointer
* @param field Field schema pointer (will be cloned, caller retains ownership)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_add_field(
zvec_collection_schema_t *schema, const zvec_field_schema_t *field);
/**
* @brief Alter field schema
* @param schema Collection schema pointer
* @param field_name Name of field to alter
* @param new_field New field schema with updated properties
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_alter_field(
zvec_collection_schema_t *schema, const char *field_name,
const zvec_field_schema_t *new_field);
/**
* @brief Drop field from schema
* @param schema Collection schema pointer
* @param field_name Field name to drop
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_drop_field(
zvec_collection_schema_t *schema, const char *field_name);
/**
* @brief Check if field exists in schema
* @param schema Collection schema pointer
* @param field_name Field name to check
* @return true if field exists, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_collection_schema_has_field(
const zvec_collection_schema_t *schema, const char *field_name);
/**
* @brief Get field by name
* @param schema Collection schema pointer
* @param field_name Field name
* @return zvec_field_schema_t* Field schema pointer (non-owning, do not
* destroy), NULL if not found
*/
ZVEC_EXPORT zvec_field_schema_t *ZVEC_CALL zvec_collection_schema_get_field(
const zvec_collection_schema_t *schema, const char *field_name);
/**
* @brief Get forward (scalar) field by name
* @param schema Collection schema pointer
* @param field_name Field name
* @return zvec_field_schema_t* Field schema pointer (non-owning, do not
* destroy), NULL if not found or not scalar
*/
ZVEC_EXPORT zvec_field_schema_t *ZVEC_CALL
zvec_collection_schema_get_forward_field(const zvec_collection_schema_t *schema,
const char *field_name);
/**
* @brief Get vector field by name
* @param schema Collection schema pointer
* @param field_name Field name
* @return zvec_field_schema_t* Field schema pointer (non-owning, do not
* destroy), NULL if not found or not vector
*/
ZVEC_EXPORT zvec_field_schema_t *ZVEC_CALL
zvec_collection_schema_get_vector_field(const zvec_collection_schema_t *schema,
const char *field_name);
/**
* @brief Get all forward (scalar) fields
* @param schema Collection schema pointer
* @param[out] fields Receives a newly allocated array of pointers to field
* schemas. The array is allocated by the library and should be
* freed using zvec_free() when no longer needed.
* @param[out] count Number of fields
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual field pointers
* are owned by the schema and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_get_forward_fields(
const zvec_collection_schema_t *schema, zvec_field_schema_t ***fields,
size_t *count);
/**
* @brief Get all forward fields with index
* @param schema Collection schema pointer
* @param[out] fields Receives a newly allocated array of pointers to field
* schemas. The array is allocated by the library and should be
* freed using zvec_free() when no longer needed.
* @param[out] count Number of fields
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual field pointers
* are owned by the schema and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_get_forward_fields_with_index(
const zvec_collection_schema_t *schema, zvec_field_schema_t ***fields,
size_t *count);
/**
* @brief Get all forward (scalar) field names
* @param schema Collection schema pointer
* @param[out] names Output array of field names (allocated by library)
* @param[out] count Number of field names
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual string pointers
* are owned by the schema and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_get_forward_field_names(
const zvec_collection_schema_t *schema, const char ***names, size_t *count);
/**
* @brief Get all forward field names with index
* @param schema Collection schema pointer
* @param[out] names Output array of field names (allocated by library)
* @param[out] count Number of field names
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual string pointers
* are owned by the schema and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_get_forward_field_names_with_index(
const zvec_collection_schema_t *schema, const char ***names, size_t *count);
/**
* @brief Get all field names
* @param schema Collection schema pointer
* @param[out] names Output array of field names (allocated by library)
* @param[out] count Number of field names
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual string pointers
* are owned by the schema and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_get_all_field_names(
const zvec_collection_schema_t *schema, const char ***names, size_t *count);
/**
* @brief Get all vector fields
* @param schema Collection schema pointer
* @param[out] fields Receives a newly allocated array of pointers to field
* schemas. The array is allocated by the library and should be
* freed using zvec_free() when no longer needed.
* @param[out] count Number of fields
* @return zvec_error_code_t Error code
*
* @note The returned array is allocated by the library and should be freed
* using zvec_free() when no longer needed. The individual field pointers
* are owned by the schema and must NOT be freed.
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_get_vector_fields(const zvec_collection_schema_t *schema,
zvec_field_schema_t ***fields,
size_t *count);
/**
* @brief Get maximum document count per segment of collection schema
*
* @param schema Collection schema pointer
* @return uint64_t Maximum document count per segment
*/
ZVEC_EXPORT uint64_t ZVEC_CALL
zvec_collection_schema_get_max_doc_count_per_segment(
const zvec_collection_schema_t *schema);
/**
* @brief Set maximum document count per segment
* @param schema Collection schema pointer
* @param max_doc_count Maximum document count
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_schema_set_max_doc_count_per_segment(
zvec_collection_schema_t *schema, uint64_t max_doc_count);
/**
* @brief Validate collection schema
* @param schema Collection schema pointer
* @param[out] error_msg Error message (needs to be freed by calling
* zvec_free_string)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_validate(
const zvec_collection_schema_t *schema, zvec_string_t **error_msg);
/**
* @brief Add index to field
* @param schema Collection schema pointer
* @param field_name Field name to add index to
* @param index_params Index parameters
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_add_index(
zvec_collection_schema_t *schema, const char *field_name,
const zvec_index_params_t *index_params);
/**
* @brief Drop index from field
* @param schema Collection schema pointer
* @param field_name Field name to drop index from
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_schema_drop_index(
zvec_collection_schema_t *schema, const char *field_name);
/**
* @brief Check if field has index
* @param schema Collection schema pointer
* @param field_name Field name
* @return true if field has index, false otherwise
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_collection_schema_has_index(
const zvec_collection_schema_t *schema, const char *field_name);
// =============================================================================
// Collection Management Functions
// =============================================================================
/**
* @brief Create and open collection
* @param path Collection path
* @param schema Collection schema pointer
* @param options Collection options pointer (NULL uses default options)
* @param[out] collection Returned collection handle
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_create_and_open(
const char *path, const zvec_collection_schema_t *schema,
const zvec_collection_options_t *options, zvec_collection_t **collection);
/**
* @brief Open existing collection
* @param path Collection path
* @param options Collection options pointer (NULL uses default options)
* @param[out] collection Returned collection handle
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_open(const char *path, const zvec_collection_options_t *options,
zvec_collection_t **collection);
/**
* @brief Close collection
* @param collection Collection handle
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_close(zvec_collection_t *collection);
/**
* @brief Destroy collection
*
* @param collection Collection handle
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_destroy(zvec_collection_t *collection);
/**
* @brief Flush collection data to disk
* @param collection Collection handle
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_flush(zvec_collection_t *collection);
/**
* @brief Get collection schema
* @param collection Collection handle
* @param[out] schema
* Returned collection schema pointer (needs to be freed by calling
* zvec_collection_schema_destroy)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_get_schema(
const zvec_collection_t *collection, zvec_collection_schema_t **schema);
/**
* @brief Get collection options
* @param collection Collection handle
* @param[out] options
* Returned collection options pointer (needs to be freed by calling
* zvec_collection_options_destroy)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_get_options(
const zvec_collection_t *collection, zvec_collection_options_t **options);
/**
* @brief Get collection statistics
* @param collection Collection handle
* @param[out] stats
* Returned statistics pointer (needs to be freed by calling
* zvec_collection_stats_destroy)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_get_stats(
const zvec_collection_t *collection, zvec_collection_stats_t **stats);
/**
* @brief Destroy collection statistics
* @param stats Statistics pointer
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_collection_stats_destroy(zvec_collection_stats_t *stats);
/**
* @brief Free field schema memory
*
* @param field_schema Field schema pointer to be freed
*/
ZVEC_EXPORT void ZVEC_CALL
zvec_free_field_schema(zvec_field_schema_t *field_schema);
// =============================================================================
// Index Management Interface
// =============================================================================
/**
* @brief Create index for a collection field
*
* @param collection Collection handle
* @param field_name Field name to create index on
* @param index_params Index parameters. The function will make an internal copy
* of the parameters, so the caller retains ownership and
* should call zvec_index_params_destroy() after the call.
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_create_index(
zvec_collection_t *collection, const char *field_name,
const zvec_index_params_t *index_params);
/**
* @brief Drop index
* @param collection Collection handle
* @param field_name Field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_drop_index(
zvec_collection_t *collection, const char *field_name);
/**
* @brief Optimize collection (rebuild indexes, merge segments, etc.)
* @param collection Collection handle
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_collection_optimize(zvec_collection_t *collection);
// =============================================================================
// Column Management Interface (DDL)
// =============================================================================
/**
* @brief Add column
* @param collection Collection handle
* @param field_schema Field schema pointer (deep-copied internally, caller
* retains ownership and must call zvec_field_schema_destroy
* after the call)
* @param expression Default value expression (can be NULL)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_add_column(
zvec_collection_t *collection, const zvec_field_schema_t *field_schema,
const char *expression);
/**
* @brief Drop column
* @param collection Collection handle
* @param column_name Field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_drop_column(
zvec_collection_t *collection, const char *column_name);
/**
* @brief Alter column
* @param collection Collection handle
* @param column_name Column/field name to alter
* @param new_name New field name (can be NULL to indicate no renaming)
* @param new_schema New field schema (can be NULL to indicate no schema
* modification). The schema is deep-copied internally, caller retains
* ownership and must call zvec_field_schema_destroy after the
* call.
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_alter_column(
zvec_collection_t *collection, const char *column_name,
const char *new_name, const zvec_field_schema_t *new_schema);
/**
* @brief Document structure (opaque pointer mode)
* Internal implementation details are not visible to the outside, and
* operations are performed through API functions
*/
typedef struct zvec_doc_t zvec_doc_t;
/**
* @brief Per-document status returned by detailed DML APIs.
* @note Uses ordered style: result index corresponds to input document index.
* Caller should access pk by index from the original input array.
*/
typedef struct {
zvec_error_code_t code; /**< Per-document status code */
const char *message; /**< Per-document status message (allocated by API) */
} zvec_write_result_t;
// =============================================================================
// Data Manipulation Interface (DML)
// =============================================================================
/**
* @brief Insert documents into collection
* @param collection Collection handle
* @param docs Document array
* @param doc_count Document count
* @param[out] success_count Number of successfully inserted documents
* @param[out] error_count Number of failed insertions
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_insert(
zvec_collection_t *collection, const zvec_doc_t **docs, size_t doc_count,
size_t *success_count, size_t *error_count);
/**
* @brief Insert documents and return per-document statuses.
*
* @param collection Collection handle
* @param docs Document array
* @param doc_count Document count
* @param[out] results Per-document result array (free with
* zvec_write_results_free)
* @param[out] result_count Number of result entries
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_insert_with_results(
zvec_collection_t *collection, const zvec_doc_t **docs, size_t doc_count,
zvec_write_result_t **results, size_t *result_count);
/**
* @brief Update documents in collection
* @param collection Collection handle
* @param docs Document array
* @param doc_count Document count
* @param[out] success_count Number of successfully updated documents
* @param[out] error_count Number of failed updates
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_update(
zvec_collection_t *collection, const zvec_doc_t **docs, size_t doc_count,
size_t *success_count, size_t *error_count);
/**
* @brief Update documents and return per-document statuses.
*
* @param collection Collection handle
* @param docs Document array
* @param doc_count Document count
* @param[out] results Per-document result array (free with
* zvec_write_results_free)
* @param[out] result_count Number of result entries
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_update_with_results(
zvec_collection_t *collection, const zvec_doc_t **docs, size_t doc_count,
zvec_write_result_t **results, size_t *result_count);
/**
* @brief Insert or update documents in collection (upsert operation)
* @param collection Collection handle
* @param docs Document array
* @param doc_count Document count
* @param[out] success_count Number of successful operations
* @param[out] error_count Number of failed operations
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_upsert(
zvec_collection_t *collection, const zvec_doc_t **docs, size_t doc_count,
size_t *success_count, size_t *error_count);
/**
* @brief Upsert documents and return per-document statuses.
*
* @param collection Collection handle
* @param docs Document array
* @param doc_count Document count
* @param[out] results Per-document result array (free with
* zvec_write_results_free)
* @param[out] result_count Number of result entries
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_upsert_with_results(
zvec_collection_t *collection, const zvec_doc_t **docs, size_t doc_count,
zvec_write_result_t **results, size_t *result_count);
/**
* @brief Delete documents from collection
* @param collection Collection handle
* @param pks Primary key array
* @param pk_count Primary key count
* @param[out] success_count Number of successfully deleted documents
* @param[out] error_count Number of failed deletions
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_delete(
zvec_collection_t *collection, const char *const *pks, size_t pk_count,
size_t *success_count, size_t *error_count);
/**
* @brief Delete documents by PK and return per-document statuses.
*
* @param collection Collection handle
* @param pks Primary key array
* @param pk_count Primary key count
* @param[out] results Per-document result array (free with
* zvec_write_results_free)
* @param[out] result_count Number of result entries
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_delete_with_results(
zvec_collection_t *collection, const char *const *pks, size_t pk_count,
zvec_write_result_t **results, size_t *result_count);
/**
* @brief Free result arrays returned by detailed DML APIs.
*
* @param results Result array pointer
* @param result_count Number of entries in result array
*/
ZVEC_EXPORT void ZVEC_CALL zvec_write_results_free(zvec_write_result_t *results,
size_t result_count);
/**
* @brief Delete documents by filter condition
* @param collection Collection handle
* @param filter Filter expression
* @param[out] deleted_count Number of deleted documents
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_delete_by_filter(
zvec_collection_t *collection, const char *filter);
// =============================================================================
// Data Query Interface (DQL)
// =============================================================================
/**
* @brief Vector similarity search
* @param collection Collection handle
* @param query Query parameters pointer
* @param[out] results Returned document array (needs to be freed by calling
* zvec_docs_free)
* @param[out] result_count Number of returned results
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_query(
const zvec_collection_t *collection, const zvec_vector_query_t *query,
zvec_doc_t ***results, size_t *result_count);
/**
* @brief Fetch documents by primary keys
* @param collection Collection handle
* @param primary_keys Primary key array
* @param count Number of primary keys
* @param[out] documents Returned document array (needs to be freed by calling
* zvec_docs_free)
* @param[out] found_count Number of found documents
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_collection_fetch(
zvec_collection_t *collection, const char *const *primary_keys,
size_t count, zvec_doc_t ***documents, size_t *found_count);
// =============================================================================
// Document Related Structures
// =============================================================================
/**
* @brief Document field value union
*/
typedef union {
bool bool_value;
int32_t int32_value;
int64_t int64_value;
uint32_t uint32_value;
uint64_t uint64_value;
float float_value;
double double_value;
zvec_string_t string_value;
zvec_float_array_t vector_value;
zvec_byte_array_t binary_value; /**< Binary data value */
} zvec_field_value_t;
/**
* @brief Document field structure
*/
typedef struct {
zvec_string_t name; ///< Field name
zvec_data_type_t data_type; ///< Data type
zvec_field_value_t value; ///< Field value
} zvec_doc_field_t;
/**
* @brief Document operator enumeration
*/
typedef enum {
ZVEC_DOC_OP_INSERT = 0, ///< Insert operation
ZVEC_DOC_OP_UPDATE = 1, ///< Update operation
ZVEC_DOC_OP_UPSERT = 2, ///< Insert or update operation
ZVEC_DOC_OP_DELETE = 3 ///< Delete operation
} zvec_doc_operator_t;
// =============================================================================
// Data Manipulation Interface (DML)
// =============================================================================
/**
* @brief Create a new document object
*
* @return zvec_doc_t* Pointer to the newly created document object, returns
* NULL on failure
*/
ZVEC_EXPORT zvec_doc_t *ZVEC_CALL zvec_doc_create(void);
/**
* @brief Destroy the document object and release all resources
*
* @param doc Pointer to the document object
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_destroy(zvec_doc_t *doc);
/**
* @brief Clear the document object
*
* @param doc Pointer to the document object
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_clear(zvec_doc_t *doc);
/**
* @brief Add field to document by value
*
* @param doc Document object pointer
* @param field_name Field name
* @param data_type Data type
* @param value Value pointer
* @param value_size Value size
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_doc_add_field_by_value(
zvec_doc_t *doc, const char *field_name, zvec_data_type_t data_type,
const void *value, size_t value_size);
/**
* @brief Add field to document by structure
*
* @param doc Document object pointer
* @param field Field structure pointer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_add_field_by_struct(zvec_doc_t *doc, const zvec_doc_field_t *field);
/**
* @brief Remove field from document
*
* @param doc Document structure pointer
* @param field_name Field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_remove_field(zvec_doc_t *doc, const char *field_name);
/**
* @brief Batch release document array
*
* @param documents Document pointer array
* @param count Document count
*/
ZVEC_EXPORT void ZVEC_CALL zvec_docs_free(zvec_doc_t **documents, size_t count);
/**
* @brief Set document primary key
*
* @param doc Pointer to the document structure
* @param pk Primary key string
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_set_pk(zvec_doc_t *doc, const char *pk);
/**
* @brief Set document ID
*
* @param doc Document structure pointer
* @param doc_id Document ID
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_set_doc_id(zvec_doc_t *doc,
uint64_t doc_id);
/**
* @brief Set document score
*
* @param doc Document structure pointer
* @param score Score value
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_set_score(zvec_doc_t *doc, float score);
/**
* @brief Set document operator
*
* @param doc Document structure pointer
* @param op Operator
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_set_operator(zvec_doc_t *doc,
zvec_doc_operator_t op);
/**
* @brief Explicitly mark a document field as null.
*
* @param doc Document structure pointer
* @param field_name Field name
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_set_field_null(zvec_doc_t *doc, const char *field_name);
/**
* @brief Get document ID
*
* @param doc Document structure pointer
* @return uint64_t Document ID
*/
ZVEC_EXPORT uint64_t ZVEC_CALL zvec_doc_get_doc_id(const zvec_doc_t *doc);
/**
* @brief Get document score
*
* @param doc Document structure pointer
* @return float Score value
*/
ZVEC_EXPORT float ZVEC_CALL zvec_doc_get_score(const zvec_doc_t *doc);
/**
* @brief Get document operator
*
* @param doc Document structure pointer
* @return zvec_doc_operator_t Operator
*/
ZVEC_EXPORT zvec_doc_operator_t ZVEC_CALL
zvec_doc_get_operator(const zvec_doc_t *doc);
/**
* @brief Get document field count
*
* @param doc Document structure pointer
* @return size_t Field count
*/
ZVEC_EXPORT size_t ZVEC_CALL zvec_doc_get_field_count(const zvec_doc_t *doc);
/**
* @brief Get document primary key pointer (no copy)
*
* @param doc Document object pointer
* @return const char* Primary key string pointer, returns NULL if not set
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_doc_get_pk_pointer(const zvec_doc_t *doc);
/**
* @brief Get document primary key copy (needs manual release)
*
* @param doc Document object pointer
* @return const char* Primary key string copy, needs to call zvec_free() to
* release, returns NULL if not set
*
* @note The returned string is allocated by the library and must be freed
* using zvec_free() when no longer needed.
*/
ZVEC_EXPORT const char *ZVEC_CALL zvec_doc_get_pk_copy(const zvec_doc_t *doc);
/**
* @brief Get field value (basic type returned directly)
*
* Supports basic numeric data types: BOOL, INT32, INT64, UINT32, UINT64,
* FLOAT, DOUBLE. The value is copied directly into the provided buffer.
* For STRING, BINARY, and VECTOR types, use zvec_doc_get_field_value_copy
* or zvec_doc_get_field_value_pointer instead.
*
* @param doc Document object pointer
* @param field_name Field name
* @param field_type Field type (must be a basic numeric type)
* @param value_buffer Output buffer to receive the value
* @param buffer_size Size of the output buffer
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_doc_get_field_value_basic(
const zvec_doc_t *doc, const char *field_name, zvec_data_type_t field_type,
void *value_buffer, size_t buffer_size);
/**
* @brief Get field value copy (allocate new memory)
*
* Supports all data types including:
* - Basic types: BOOL, INT32, INT64, UINT32, UINT64, FLOAT, DOUBLE
* - String types: STRING, BINARY
* - Vector types: VECTOR_FP32, VECTOR_FP64, VECTOR_FP16, VECTOR_INT4,
* VECTOR_INT8, VECTOR_INT16, VECTOR_BINARY32, VECTOR_BINARY64
* - Sparse vector types: SPARSE_VECTOR_FP32, SPARSE_VECTOR_FP16
* - Array types: ARRAY_STRING, ARRAY_BINARY, ARRAY_BOOL, ARRAY_INT32,
* ARRAY_INT64, ARRAY_UINT32, ARRAY_UINT64, ARRAY_FLOAT, ARRAY_DOUBLE
*
* The returned value pointer must be manually freed using appropriate
* deallocation functions (zvec_free() for basic types and strings,
* zvec_free_uint8_array() for binary data).
*
* @param doc Document object pointer
* @param field_name Field name
* @param field_type Field type
* @param[out] value Returned value pointer (needs manual release)
* @param[out] value_size Returned value size
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_doc_get_field_value_copy(
const zvec_doc_t *doc, const char *field_name, zvec_data_type_t field_type,
void **value, size_t *value_size);
/**
* @brief Get field value pointer (data remains in document)
*
* Supports data types where direct pointer access is safe:
* - Basic types: BOOL, INT32, INT64, UINT32, UINT64, FLOAT, DOUBLE
* - String types: STRING (returns null-terminated C string), BINARY
* - Vector types: VECTOR_FP32, VECTOR_FP64, VECTOR_FP16, VECTOR_INT4,
* VECTOR_INT8, VECTOR_INT16, VECTOR_BINARY32, VECTOR_BINARY64
* - Array types: ARRAY_INT32, ARRAY_INT64, ARRAY_UINT32, ARRAY_UINT64,
* ARRAY_FLOAT, ARRAY_DOUBLE
*
* The returned pointer points to data within the document object and
* does not require manual memory management. The pointer remains valid
* as long as the document exists.
*
* @param doc Document object pointer
* @param field_name Field name
* @param field_type Field type
* @param[out] value Returned value pointer (points to document-internal data)
* @param[out] value_size Returned value size
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_doc_get_field_value_pointer(
const zvec_doc_t *doc, const char *field_name, zvec_data_type_t field_type,
const void **value, size_t *value_size);
/**
* @brief Check if document is empty
*
* @param doc Document object pointer
* @return bool Returns true if document is empty, otherwise returns false
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_doc_is_empty(const zvec_doc_t *doc);
/**
* @brief Check if document contains specified field
*
* @param doc Document object pointer
* @param field_name Field name
* @return bool Returns true if field exists, otherwise returns false
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_doc_has_field(const zvec_doc_t *doc,
const char *field_name);
/**
* @brief Check if document field has value
*
* @param doc Document object pointer
* @param field_name Field name
* @return bool Returns true if field has value, otherwise returns false
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_doc_has_field_value(const zvec_doc_t *doc,
const char *field_name);
/**
* @brief Check if document field is null
*
* @param doc Document object pointer
* @param field_name Field name
* @return bool Returns true if field is null, otherwise returns false
*/
ZVEC_EXPORT bool ZVEC_CALL zvec_doc_is_field_null(const zvec_doc_t *doc,
const char *field_name);
/**
* @brief Get all field names of document
*
* @param doc Document object pointer
* @param[out] field_names
* Returned field name array (needs to call zvec_free_str_array to release)
* @param[out] count Returned field count
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL zvec_doc_get_field_names(
const zvec_doc_t *doc, char ***field_names, size_t *count);
/**
* @brief Release string array memory
*
* @param array String array pointer
* @param count Array element count
*/
ZVEC_EXPORT void ZVEC_CALL zvec_free_str_array(char **array, size_t count);
/**
* @brief Serialize document
*
* @param doc Document object pointer
* @param[out] data Returned serialized data (needs to call
* zvec_free_uint8_array to release)
* @param[out] size Returned data size
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_serialize(const zvec_doc_t *doc, uint8_t **data, size_t *size);
/**
* @brief Deserialize document
*
* @param data Serialized data
* @param size Data size
* @param[out] doc Returned document object pointer (needs to call
* zvec_doc_destroy to release)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_deserialize(const uint8_t *data, size_t size, zvec_doc_t **doc);
/**
* @brief Merge two documents
*
* @param doc Target document object pointer
* @param other Source document object pointer
*/
ZVEC_EXPORT void ZVEC_CALL zvec_doc_merge(zvec_doc_t *doc,
const zvec_doc_t *other);
/**
* @brief Get document memory usage
*
* @param doc Document object pointer
* @return size_t Memory usage (bytes)
*/
ZVEC_EXPORT size_t ZVEC_CALL zvec_doc_memory_usage(const zvec_doc_t *doc);
/**
* @brief Validate document against Schema
*
* @param doc Document object pointer
* @param schema Schema object pointer
* @param is_update Whether it's an update operation
* @param[out] error_msg Error message (needs manual release)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_validate(const zvec_doc_t *doc, const zvec_collection_schema_t *schema,
bool is_update, char **error_msg);
/**
* @brief Get detailed string representation of document
*
* @param doc Document object pointer
* @param[out] detail_str Returned detailed string (needs manual release)
* @return zvec_error_code_t Error code
*/
ZVEC_EXPORT zvec_error_code_t ZVEC_CALL
zvec_doc_to_detail_string(const zvec_doc_t *doc, char **detail_str);
/**
* @brief Free docs array memory
* @param docs Document array pointer
* @param count Document count
*/
ZVEC_EXPORT void ZVEC_CALL zvec_docs_free(zvec_doc_t **docs, size_t count);
// =============================================================================
// Utility Functions
// =============================================================================
/**
* @brief Convert error code to description string
* @param error_code Error code
* @return const char* Error description string
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_error_code_to_string(zvec_error_code_t error_code);
/**
* @brief Convert data type to string
* @param data_type Data type
* @return const char* Data type string
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_data_type_to_string(zvec_data_type_t data_type);
/**
* @brief Convert index type to string
* @param index_type Index type
* @return const char* Index type string
*/
ZVEC_EXPORT const char *ZVEC_CALL
zvec_index_type_to_string(zvec_index_type_t index_type);
/**
* @brief Convert metric type to string
* @param metric_type Metric type
* @return const char* Metric type string
*/
const char *zvec_metric_type_to_string(zvec_metric_type_t metric_type);
// =============================================================================
// Helper Functions
// =============================================================================
/**
* @brief Simplified HNSW index parameters initialization macro
* @param _metric Distance metric type
* @param _m Connectivity parameter
* @param _ef_construction Exploration factor during construction
* @param _ef_search Exploration factor during search
* @param _quant Quantization type
*
* Usage example:
* @code
* zvec_index_params_t params = ZVEC_HNSW_PARAMS(
* ZVEC_METRIC_TYPE_COSINE, 16, 200, 50, ZVEC_QUANTIZE_TYPE_UNDEFINED);
* @endcode
*/
// clang-format off
#define ZVEC_HNSW_PARAMS(_metric, _m, _ef_construction, _ef_search, _quant) \
((zvec_index_params_t){ \
.index_type = ZVEC_INDEX_TYPE_HNSW, \
.metric_type = (_metric), \
.quantize_type = (_quant), \
.hnsw.m = (_m), \
.hnsw.ef_construction = (_ef_construction), \
.hnsw.ef_search = (_ef_search) })
// clang-format on
/**
* @brief Simplified inverted index parameters initialization macro
* @param range_opt Whether to enable range optimization
* @param wildcard Whether to enable wildcard expansion
*
* Usage example:
* zvec_index_params_t params = ZVEC_INVERT_PARAMS(true, false);
*/
// clang-format off
#define ZVEC_INVERT_PARAMS(_range_opt, _wildcard) \
((zvec_index_params_t){ \
.index_type = ZVEC_INDEX_TYPE_INVERT, \
.invert.enable_range_optimization = (_range_opt), \
.invert.enable_extended_wildcard = (_wildcard) })
// clang-format on
/**
* @brief Simplified Flat index parameters initialization macro
* @param metric Distance metric type
* @param quant Quantization type
*/
// clang-format off
#define ZVEC_FLAT_PARAMS(_metric, _quant) \
((zvec_index_params_t){ \
.index_type = ZVEC_INDEX_TYPE_FLAT, \
.metric_type = (_metric), \
.quantize_type = (_quant) })
// clang-format on
/**
* @brief Simplified IVF index parameters initialization macro
* @param metric Distance metric type
* @param nlist Number of cluster centers
* @param niters Number of iterations
* @param soar Whether to use SOAR algorithm
* @param nprobe Number of clusters to probe during search
* @param quant Quantization type
*/
// clang-format off
#define ZVEC_IVF_PARAMS(_metric, _nlist, _niters, _soar, _nprobe, _quant) \
((zvec_index_params_t){ \
.index_type = ZVEC_INDEX_TYPE_IVF, \
.metric_type = (_metric), \
.quantize_type = (_quant), \
.ivf.n_list = (_nlist), \
.ivf.n_iters = (_niters), \
.ivf.use_soar = (_soar), \
.ivf.n_probe = (_nprobe) })
// clang-format on
/**
* @brief Simplified string initialization macro
* @param str String content
*
* Usage example:
* zvec_string_t name = ZVEC_STRING("my_collection");
*/
#define ZVEC_STRING(str) \
(zvec_string_t) { \
.data = str, .length = strlen(str) \
}
/**
* @brief Simplified string view initialization macro
* @param str String content
*
* Usage example:
* zvec_string_view_t name = ZVEC_STRING_VIEW("my_collection");
*/
#define ZVEC_STRING_VIEW(str) \
(zvec_string_view_t) { \
.data = str, .length = strlen(str) \
}
// Has been replaced by the new ZVEC_STRING_VIEW macro
/**
* @brief Simplified float array initialization macro
* @param data_ptr Float array pointer
* @param len Array length
*
* Usage example:
* float vectors[] = {0.1f, 0.2f, 0.3f};
* zvec_float_array_t vec_array = ZVEC_FLOAT_ARRAY(vectors, 3);
*/
#define ZVEC_FLOAT_ARRAY(data_ptr, len) \
(zvec_float_array_t) { \
.data = data_ptr, .length = len \
}
/**
* @brief Simplified integer array initialization macro
* @param data_ptr Integer array pointer
* @param len Array length
*/
#define ZVEC_INT64_ARRAY(data_ptr, len) \
(zvec_int64_array_t) { \
.data = data_ptr, .length = len \
}
/**
* @brief Simplified document field initialization macro
* @param name_str Field name
* @param type Data type
* @param value_union Field value union
*
* Usage example:
* zvec_doc_field_t field = ZVEC_DOC_FIELD("id", ZVEC_DATA_TYPE_STRING,
* {.string_value = ZVEC_STRING("doc1")});
*/
#define ZVEC_DOC_FIELD(name_str, type, value_union) \
(zvec_doc_field_t) { \
.name = ZVEC_STRING(name_str), .data_type = type, .value = value_union \
}
#ifdef __cplusplus
} // extern "C"
#endif
#endif // ZVEC_C_API_H