// Code generated for linux/s390x by 'generator --prefix-enumerator=_ --prefix-external=x_ --prefix-field=F --prefix-macro=m_ --prefix-static-internal=_ --prefix-static-none=_ --prefix-tagged-enum=_ --prefix-tagged-struct=T --prefix-tagged-union=T --prefix-typename=T --prefix-undefined=_ -extended-errors -ignore-unsupported-alignment -ignore-link-errors -o vec.go --package-name libsqlite_vec dist/libsqlite_vec0.a -lsqlite3', DO NOT EDIT.

//go:build linux && s390x

package vec

import (
	"reflect"
	"unsafe"

	"modernc.org/libc"
	libsqlite3 "modernc.org/sqlite/lib"
)

var _ reflect.Type
var _ unsafe.Pointer

const m_ARG_MAX = 131072
const m_BC_BASE_MAX = 99
const m_BC_DIM_MAX = 2048
const m_BC_SCALE_MAX = 99
const m_BC_STRING_MAX = 1000
const m_BUFSIZ = 1024
const m_CARRAY_BLOB = 4
const m_CARRAY_DOUBLE = 2
const m_CARRAY_INT32 = 0
const m_CARRAY_INT64 = 1
const m_CARRAY_TEXT = 3
const m_CHARCLASS_NAME_MAX = 14
const m_CHAR_BIT = 8
const m_CHAR_MAX = 255
const m_CHAR_MIN = 0
const m_COLL_WEIGHTS_MAX = 2
const m_COMPILER_SUPPORTS_VTAB_IN = 1
const m_DBL_DECIMAL_DIG = 17
const m_DBL_DIG = 15
const m_DBL_EPSILON = 2.22044604925031308085e-16
const m_DBL_HAS_SUBNORM = 1
const m_DBL_MANT_DIG = 53
const m_DBL_MAX = 1.79769313486231570815e+308
const m_DBL_MAX_10_EXP = 308
const m_DBL_MAX_EXP = 1024
const m_DBL_MIN = 2.22507385850720138309e-308
const m_DBL_TRUE_MIN = 4.94065645841246544177e-324
const m_DECIMAL_DIG = 17
const m_DELAYTIMER_MAX = 0x7fffffff
const m_E2BIG = 7
const m_EACCES = 13
const m_EADDRINUSE = 98
const m_EADDRNOTAVAIL = 99
const m_EADV = 68
const m_EAFNOSUPPORT = 97
const m_EAGAIN = 11
const m_EALREADY = 114
const m_EBADE = 52
const m_EBADF = 9
const m_EBADFD = 77
const m_EBADMSG = 74
const m_EBADR = 53
const m_EBADRQC = 56
const m_EBADSLT = 57
const m_EBFONT = 59
const m_EBUSY = 16
const m_ECANCELED = 125
const m_ECHILD = 10
const m_ECHRNG = 44
const m_ECOMM = 70
const m_ECONNABORTED = 103
const m_ECONNREFUSED = 111
const m_ECONNRESET = 104
const m_EDEADLK = 35
const m_EDEADLOCK = "EDEADLK"
const m_EDESTADDRREQ = 89
const m_EDOM = 33
const m_EDOTDOT = 73
const m_EDQUOT = 122
const m_EEXIST = 17
const m_EFAULT = 14
const m_EFBIG = 27
const m_EHOSTDOWN = 112
const m_EHOSTUNREACH = 113
const m_EHWPOISON = 133
const m_EIDRM = 43
const m_EILSEQ = 84
const m_EINPROGRESS = 115
const m_EINTR = 4
const m_EINVAL = 22
const m_EIO = 5
const m_EISCONN = 106
const m_EISDIR = 21
const m_EISNAM = 120
const m_EKEYEXPIRED = 127
const m_EKEYREJECTED = 129
const m_EKEYREVOKED = 128
const m_EL2HLT = 51
const m_EL2NSYNC = 45
const m_EL3HLT = 46
const m_EL3RST = 47
const m_ELIBACC = 79
const m_ELIBBAD = 80
const m_ELIBEXEC = 83
const m_ELIBMAX = 82
const m_ELIBSCN = 81
const m_ELNRNG = 48
const m_ELOOP = 40
const m_EMEDIUMTYPE = 124
const m_EMFILE = 24
const m_EMLINK = 31
const m_EMSGSIZE = 90
const m_EMULTIHOP = 72
const m_ENAMETOOLONG = 36
const m_ENAVAIL = 119
const m_ENETDOWN = 100
const m_ENETRESET = 102
const m_ENETUNREACH = 101
const m_ENFILE = 23
const m_ENOANO = 55
const m_ENOBUFS = 105
const m_ENOCSI = 50
const m_ENODATA = 61
const m_ENODEV = 19
const m_ENOENT = 2
const m_ENOEXEC = 8
const m_ENOKEY = 126
const m_ENOLCK = 37
const m_ENOLINK = 67
const m_ENOMEDIUM = 123
const m_ENOMEM = 12
const m_ENOMSG = 42
const m_ENONET = 64
const m_ENOPKG = 65
const m_ENOPROTOOPT = 92
const m_ENOSPC = 28
const m_ENOSR = 63
const m_ENOSTR = 60
const m_ENOSYS = 38
const m_ENOTBLK = 15
const m_ENOTCONN = 107
const m_ENOTDIR = 20
const m_ENOTEMPTY = 39
const m_ENOTNAM = 118
const m_ENOTRECOVERABLE = 131
const m_ENOTSOCK = 88
const m_ENOTSUP = "EOPNOTSUPP"
const m_ENOTTY = 25
const m_ENOTUNIQ = 76
const m_ENXIO = 6
const m_EOPNOTSUPP = 95
const m_EOVERFLOW = 75
const m_EOWNERDEAD = 130
const m_EPERM = 1
const m_EPFNOSUPPORT = 96
const m_EPIPE = 32
const m_EPROTO = 71
const m_EPROTONOSUPPORT = 93
const m_EPROTOTYPE = 91
const m_ERANGE = 34
const m_EREMCHG = 78
const m_EREMOTE = 66
const m_EREMOTEIO = 121
const m_ERESTART = 85
const m_ERFKILL = 132
const m_EROFS = 30
const m_ESHUTDOWN = 108
const m_ESOCKTNOSUPPORT = 94
const m_ESPIPE = 29
const m_ESRCH = 3
const m_ESRMNT = 69
const m_ESTALE = 116
const m_ESTRPIPE = 86
const m_ETIME = 62
const m_ETIMEDOUT = 110
const m_ETOOMANYREFS = 109
const m_ETXTBSY = 26
const m_EUCLEAN = 117
const m_EUNATCH = 49
const m_EUSERS = 87
const m_EWOULDBLOCK = "EAGAIN"
const m_EXDEV = 18
const m_EXFULL = 54
const m_EXIT_FAILURE = 1
const m_EXIT_SUCCESS = 0
const m_EXPR_NEST_MAX = 32
const m_FILENAME_MAX = 4096
const m_FILESIZEBITS = 64
const m_FLT_DECIMAL_DIG = 9
const m_FLT_DIG = 6
const m_FLT_EPSILON = 1.1920928955078125e-07
const m_FLT_EVAL_METHOD = 0
const m_FLT_HAS_SUBNORM = 1
const m_FLT_MANT_DIG = 24
const m_FLT_MAX = 3.40282346638528859812e+38
const m_FLT_MAX_10_EXP = 38
const m_FLT_MAX_EXP = 128
const m_FLT_MIN = 1.17549435082228750797e-38
const m_FLT_RADIX = 2
const m_FLT_TRUE_MIN = 1.40129846432481707092e-45
const m_FOPEN_MAX = 1000
const m_FP_FAST_FMA = 1
const m_FP_FAST_FMAF = 1
const m_FP_FAST_FMAL = 1
const m_FP_ILOGB0 = "FP_ILOGBNAN"
const m_FP_INFINITE = 1
const m_FP_NAN = 0
const m_FP_NORMAL = 4
const m_FP_SUBNORMAL = 3
const m_FP_ZERO = 2
const m_FTS5_TOKENIZE_AUX = 0x0008
const m_FTS5_TOKENIZE_DOCUMENT = 0x0004
const m_FTS5_TOKENIZE_PREFIX = 0x0002
const m_FTS5_TOKENIZE_QUERY = 0x0001
const m_FTS5_TOKEN_COLOCATED = 0x0001
const m_FULLY_WITHIN = 2
const m_HOST_NAME_MAX = 255
const m_HUGE = 3.40282346638528859812e+38
const m_HUGE_VALF = "INFINITY"
const m_INT16_MAX = 0x7fff
const m_INT32_MAX = 0x7fffffff
const m_INT64_MAX = 0x7fffffffffffffff
const m_INT8_MAX = 127
const m_INTMAX_MAX = "INT64_MAX"
const m_INTMAX_MIN = "INT64_MIN"
const m_INTPTR_MAX = "INT64_MAX"
const m_INTPTR_MIN = "INT64_MIN"
const m_INT_FAST16_MAX = "INT32_MAX"
const m_INT_FAST16_MIN = "INT32_MIN"
const m_INT_FAST32_MAX = "INT32_MAX"
const m_INT_FAST32_MIN = "INT32_MIN"
const m_INT_FAST64_MAX = "INT64_MAX"
const m_INT_FAST64_MIN = "INT64_MIN"
const m_INT_FAST8_MAX = "INT8_MAX"
const m_INT_FAST8_MIN = "INT8_MIN"
const m_INT_LEAST16_MAX = "INT16_MAX"
const m_INT_LEAST16_MIN = "INT16_MIN"
const m_INT_LEAST32_MAX = "INT32_MAX"
const m_INT_LEAST32_MIN = "INT32_MIN"
const m_INT_LEAST64_MAX = "INT64_MAX"
const m_INT_LEAST64_MIN = "INT64_MIN"
const m_INT_LEAST8_MAX = "INT8_MAX"
const m_INT_LEAST8_MIN = "INT8_MIN"
const m_INT_MAX = 0x7fffffff
const m_IOV_MAX = 1024
const m_JSON_SUBTYPE = 74
const m_LDBL_DECIMAL_DIG = "DECIMAL_DIG"
const m_LDBL_DIG = 15
const m_LDBL_EPSILON = 2.22044604925031308085e-16
const m_LDBL_HAS_SUBNORM = 1
const m_LDBL_MANT_DIG = 53
const m_LDBL_MAX = 1.79769313486231570815e+308
const m_LDBL_MAX_10_EXP = 308
const m_LDBL_MAX_EXP = 1024
const m_LDBL_MIN = 2.22507385850720138309e-308
const m_LDBL_TRUE_MIN = 4.94065645841246544177e-324
const m_LINE_MAX = 4096
const m_LLONG_MAX = 0x7fffffffffffffff
const m_LOGIN_NAME_MAX = 256
const m_LONG_BIT = 64
const m_LONG_MAX = "__LONG_MAX"
const m_L_ctermid = 20
const m_L_cuserid = 20
const m_L_tmpnam = 20
const m_MATH_ERREXCEPT = 2
const m_MATH_ERRNO = 1
const m_MAX_STATIC_BLOBS = 16
const m_MB_LEN_MAX = 4
const m_MQ_PRIO_MAX = 32768
const m_M_1_PI = 0.31830988618379067154
const m_M_2_PI = 0.63661977236758134308
const m_M_2_SQRTPI = 1.12837916709551257390
const m_M_E = 2.7182818284590452354
const m_M_LN10 = 2.30258509299404568402
const m_M_LN2 = 0.69314718055994530942
const m_M_LOG10E = 0.43429448190325182765
const m_M_LOG2E = 1.4426950408889634074
const m_M_PI = 3.14159265358979323846
const m_M_PI_2 = 1.57079632679489661923
const m_M_PI_4 = 0.78539816339744830962
const m_M_SQRT1_2 = 0.70710678118654752440
const m_M_SQRT2 = 1.41421356237309504880
const m_NAME_MAX = 255
const m_NDEBUG = 1
const m_NGROUPS_MAX = 32
const m_NL_ARGMAX = 9
const m_NL_LANGMAX = 32
const m_NL_MSGMAX = 32767
const m_NL_NMAX = 16
const m_NL_SETMAX = 255
const m_NL_TEXTMAX = 2048
const m_NOT_WITHIN = 0
const m_NPY_PARSE_ERROR = "Error parsing numpy array: numpy header did not start with '{'"
const m_NZERO = 20
const m_PAGESIZE = 4096
const m_PAGE_SIZE = "PAGESIZE"
const m_PARTLY_WITHIN = 1
const m_PATH_MAX = 4096
const m_PIPE_BUF = 4096
const m_PRIX16 = "X"
const m_PRIX32 = "X"
const m_PRIX8 = "X"
const m_PRIXFAST16 = "X"
const m_PRIXFAST32 = "X"
const m_PRIXFAST8 = "X"
const m_PRIXLEAST16 = "X"
const m_PRIXLEAST32 = "X"
const m_PRIXLEAST8 = "X"
const m_PRId16 = "d"
const m_PRId32 = "d"
const m_PRId8 = "d"
const m_PRIdFAST16 = "d"
const m_PRIdFAST32 = "d"
const m_PRIdFAST8 = "d"
const m_PRIdLEAST16 = "d"
const m_PRIdLEAST32 = "d"
const m_PRIdLEAST8 = "d"
const m_PRIi16 = "i"
const m_PRIi32 = "i"
const m_PRIi8 = "i"
const m_PRIiFAST16 = "i"
const m_PRIiFAST32 = "i"
const m_PRIiFAST8 = "i"
const m_PRIiLEAST16 = "i"
const m_PRIiLEAST32 = "i"
const m_PRIiLEAST8 = "i"
const m_PRIo16 = "o"
const m_PRIo32 = "o"
const m_PRIo8 = "o"
const m_PRIoFAST16 = "o"
const m_PRIoFAST32 = "o"
const m_PRIoFAST8 = "o"
const m_PRIoLEAST16 = "o"
const m_PRIoLEAST32 = "o"
const m_PRIoLEAST8 = "o"
const m_PRIu16 = "u"
const m_PRIu32 = "u"
const m_PRIu8 = "u"
const m_PRIuFAST16 = "u"
const m_PRIuFAST32 = "u"
const m_PRIuFAST8 = "u"
const m_PRIuLEAST16 = "u"
const m_PRIuLEAST32 = "u"
const m_PRIuLEAST8 = "u"
const m_PRIx16 = "x"
const m_PRIx32 = "x"
const m_PRIx8 = "x"
const m_PRIxFAST16 = "x"
const m_PRIxFAST32 = "x"
const m_PRIxFAST8 = "x"
const m_PRIxLEAST16 = "x"
const m_PRIxLEAST32 = "x"
const m_PRIxLEAST8 = "x"
const m_PTHREAD_DESTRUCTOR_ITERATIONS = 4
const m_PTHREAD_KEYS_MAX = 128
const m_PTHREAD_STACK_MIN = 2048
const m_PTRDIFF_MAX = "INT64_MAX"
const m_PTRDIFF_MIN = "INT64_MIN"
const m_P_tmpdir = "/tmp"
const m_RAND_MAX = 0x7fffffff
const m_REPORT_URL = "https://github.com/asg017/sqlite-vec/issues/new"
const m_RE_DUP_MAX = 255
const m_SCHAR_MAX = 127
const m_SCNd16 = "hd"
const m_SCNd32 = "d"
const m_SCNd8 = "hhd"
const m_SCNdFAST16 = "d"
const m_SCNdFAST32 = "d"
const m_SCNdFAST8 = "hhd"
const m_SCNdLEAST16 = "hd"
const m_SCNdLEAST32 = "d"
const m_SCNdLEAST8 = "hhd"
const m_SCNi16 = "hi"
const m_SCNi32 = "i"
const m_SCNi8 = "hhi"
const m_SCNiFAST16 = "i"
const m_SCNiFAST32 = "i"
const m_SCNiFAST8 = "hhi"
const m_SCNiLEAST16 = "hi"
const m_SCNiLEAST32 = "i"
const m_SCNiLEAST8 = "hhi"
const m_SCNo16 = "ho"
const m_SCNo32 = "o"
const m_SCNo8 = "hho"
const m_SCNoFAST16 = "o"
const m_SCNoFAST32 = "o"
const m_SCNoFAST8 = "hho"
const m_SCNoLEAST16 = "ho"
const m_SCNoLEAST32 = "o"
const m_SCNoLEAST8 = "hho"
const m_SCNu16 = "hu"
const m_SCNu32 = "u"
const m_SCNu8 = "hhu"
const m_SCNuFAST16 = "u"
const m_SCNuFAST32 = "u"
const m_SCNuFAST8 = "hhu"
const m_SCNuLEAST16 = "hu"
const m_SCNuLEAST32 = "u"
const m_SCNuLEAST8 = "hhu"
const m_SCNx16 = "hx"
const m_SCNx32 = "x"
const m_SCNx8 = "hhx"
const m_SCNxFAST16 = "x"
const m_SCNxFAST32 = "x"
const m_SCNxFAST8 = "hhx"
const m_SCNxLEAST16 = "hx"
const m_SCNxLEAST32 = "x"
const m_SCNxLEAST8 = "hhx"
const m_SEM_NSEMS_MAX = 256
const m_SEM_VALUE_MAX = 0x7fffffff
const m_SHRT_MAX = 0x7fff
const m_SIG_ATOMIC_MAX = "INT32_MAX"
const m_SIG_ATOMIC_MIN = "INT32_MIN"
const m_SIZE_MAX = "UINT64_MAX"
const m_SQLITE3_TEXT = 3
const m_SQLITE_ABORT = 4
const m_SQLITE_ACCESS_EXISTS = 0
const m_SQLITE_ACCESS_READ = 2
const m_SQLITE_ACCESS_READWRITE = 1
const m_SQLITE_ALTER_TABLE = 26
const m_SQLITE_ANALYZE = 28
const m_SQLITE_ANY = 5
const m_SQLITE_ATTACH = 24
const m_SQLITE_AUTH = 23
const m_SQLITE_BLOB = 4
const m_SQLITE_BUSY = 5
const m_SQLITE_CANTOPEN = 14
const m_SQLITE_CARRAY_BLOB = 4
const m_SQLITE_CARRAY_DOUBLE = 2
const m_SQLITE_CARRAY_INT32 = 0
const m_SQLITE_CARRAY_INT64 = 1
const m_SQLITE_CARRAY_TEXT = 3
const m_SQLITE_CHECKPOINT_FULL = 1
const m_SQLITE_CHECKPOINT_PASSIVE = 0
const m_SQLITE_CHECKPOINT_RESTART = 2
const m_SQLITE_CHECKPOINT_TRUNCATE = 3
const m_SQLITE_CONFIG_COVERING_INDEX_SCAN = 20
const m_SQLITE_CONFIG_GETMALLOC = 5
const m_SQLITE_CONFIG_GETMUTEX = 11
const m_SQLITE_CONFIG_GETPCACHE = 15
const m_SQLITE_CONFIG_GETPCACHE2 = 19
const m_SQLITE_CONFIG_HEAP = 8
const m_SQLITE_CONFIG_LOG = 16
const m_SQLITE_CONFIG_LOOKASIDE = 13
const m_SQLITE_CONFIG_MALLOC = 4
const m_SQLITE_CONFIG_MEMDB_MAXSIZE = 29
const m_SQLITE_CONFIG_MEMSTATUS = 9
const m_SQLITE_CONFIG_MMAP_SIZE = 22
const m_SQLITE_CONFIG_MULTITHREAD = 2
const m_SQLITE_CONFIG_MUTEX = 10
const m_SQLITE_CONFIG_PAGECACHE = 7
const m_SQLITE_CONFIG_PCACHE = 14
const m_SQLITE_CONFIG_PCACHE2 = 18
const m_SQLITE_CONFIG_PCACHE_HDRSZ = 24
const m_SQLITE_CONFIG_PMASZ = 25
const m_SQLITE_CONFIG_ROWID_IN_VIEW = 30
const m_SQLITE_CONFIG_SCRATCH = 6
const m_SQLITE_CONFIG_SERIALIZED = 3
const m_SQLITE_CONFIG_SINGLETHREAD = 1
const m_SQLITE_CONFIG_SMALL_MALLOC = 27
const m_SQLITE_CONFIG_SORTERREF_SIZE = 28
const m_SQLITE_CONFIG_SQLLOG = 21
const m_SQLITE_CONFIG_STMTJRNL_SPILL = 26
const m_SQLITE_CONFIG_URI = 17
const m_SQLITE_CONFIG_WIN32_HEAPSIZE = 23
const m_SQLITE_CONSTRAINT = 19
const m_SQLITE_COPY = 0
const m_SQLITE_CORE = 1
const m_SQLITE_CORRUPT = 11
const m_SQLITE_CREATE_INDEX = 1
const m_SQLITE_CREATE_TABLE = 2
const m_SQLITE_CREATE_TEMP_INDEX = 3
const m_SQLITE_CREATE_TEMP_TABLE = 4
const m_SQLITE_CREATE_TEMP_TRIGGER = 5
const m_SQLITE_CREATE_TEMP_VIEW = 6
const m_SQLITE_CREATE_TRIGGER = 7
const m_SQLITE_CREATE_VIEW = 8
const m_SQLITE_CREATE_VTABLE = 29
const m_SQLITE_DBCONFIG_DEFENSIVE = 1010
const m_SQLITE_DBCONFIG_DQS_DDL = 1014
const m_SQLITE_DBCONFIG_DQS_DML = 1013
const m_SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE = 1020
const m_SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE = 1021
const m_SQLITE_DBCONFIG_ENABLE_COMMENTS = 1022
const m_SQLITE_DBCONFIG_ENABLE_FKEY = 1002
const m_SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004
const m_SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005
const m_SQLITE_DBCONFIG_ENABLE_QPSG = 1007
const m_SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003
const m_SQLITE_DBCONFIG_ENABLE_VIEW = 1015
const m_SQLITE_DBCONFIG_LEGACY_ALTER_TABLE = 1012
const m_SQLITE_DBCONFIG_LEGACY_FILE_FORMAT = 1016
const m_SQLITE_DBCONFIG_LOOKASIDE = 1001
const m_SQLITE_DBCONFIG_MAINDBNAME = 1000
const m_SQLITE_DBCONFIG_MAX = 1022
const m_SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE = 1006
const m_SQLITE_DBCONFIG_RESET_DATABASE = 1009
const m_SQLITE_DBCONFIG_REVERSE_SCANORDER = 1019
const m_SQLITE_DBCONFIG_STMT_SCANSTATUS = 1018
const m_SQLITE_DBCONFIG_TRIGGER_EQP = 1008
const m_SQLITE_DBCONFIG_TRUSTED_SCHEMA = 1017
const m_SQLITE_DBCONFIG_WRITABLE_SCHEMA = 1011
const m_SQLITE_DBSTATUS_CACHE_HIT = 7
const m_SQLITE_DBSTATUS_CACHE_MISS = 8
const m_SQLITE_DBSTATUS_CACHE_SPILL = 12
const m_SQLITE_DBSTATUS_CACHE_USED = 1
const m_SQLITE_DBSTATUS_CACHE_USED_SHARED = 11
const m_SQLITE_DBSTATUS_CACHE_WRITE = 9
const m_SQLITE_DBSTATUS_DEFERRED_FKS = 10
const m_SQLITE_DBSTATUS_LOOKASIDE_HIT = 4
const m_SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6
const m_SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5
const m_SQLITE_DBSTATUS_LOOKASIDE_USED = 0
const m_SQLITE_DBSTATUS_MAX = 13
const m_SQLITE_DBSTATUS_SCHEMA_USED = 2
const m_SQLITE_DBSTATUS_STMT_USED = 3
const m_SQLITE_DBSTATUS_TEMPBUF_SPILL = 13
const m_SQLITE_DELETE = 9
const m_SQLITE_DENY = 1
const m_SQLITE_DESERIALIZE_FREEONCLOSE = 1
const m_SQLITE_DESERIALIZE_READONLY = 4
const m_SQLITE_DESERIALIZE_RESIZEABLE = 2
const m_SQLITE_DETACH = 25
const m_SQLITE_DETERMINISTIC = 2048
const m_SQLITE_DIRECTONLY = 0x000080000
const m_SQLITE_DONE = 101
const m_SQLITE_DROP_INDEX = 10
const m_SQLITE_DROP_TABLE = 11
const m_SQLITE_DROP_TEMP_INDEX = 12
const m_SQLITE_DROP_TEMP_TABLE = 13
const m_SQLITE_DROP_TEMP_TRIGGER = 14
const m_SQLITE_DROP_TEMP_VIEW = 15
const m_SQLITE_DROP_TRIGGER = 16
const m_SQLITE_DROP_VIEW = 17
const m_SQLITE_DROP_VTABLE = 30
const m_SQLITE_EMPTY = 16
const m_SQLITE_ERROR = 1
const m_SQLITE_EXTERN = "extern"
const m_SQLITE_FAIL = 3
const m_SQLITE_FCNTL_BEGIN_ATOMIC_WRITE = 31
const m_SQLITE_FCNTL_BLOCK_ON_CONNECT = 44
const m_SQLITE_FCNTL_BUSYHANDLER = 15
const m_SQLITE_FCNTL_CHUNK_SIZE = 6
const m_SQLITE_FCNTL_CKPT_DONE = 37
const m_SQLITE_FCNTL_CKPT_START = 39
const m_SQLITE_FCNTL_CKSM_FILE = 41
const m_SQLITE_FCNTL_COMMIT_ATOMIC_WRITE = 32
const m_SQLITE_FCNTL_COMMIT_PHASETWO = 22
const m_SQLITE_FCNTL_DATA_VERSION = 35
const m_SQLITE_FCNTL_EXTERNAL_READER = 40
const m_SQLITE_FCNTL_FILESTAT = 45
const m_SQLITE_FCNTL_FILE_POINTER = 7
const m_SQLITE_FCNTL_GET_LOCKPROXYFILE = 2
const m_SQLITE_FCNTL_HAS_MOVED = 20
const m_SQLITE_FCNTL_JOURNAL_POINTER = 28
const m_SQLITE_FCNTL_LAST_ERRNO = 4
const m_SQLITE_FCNTL_LOCKSTATE = 1
const m_SQLITE_FCNTL_LOCK_TIMEOUT = 34
const m_SQLITE_FCNTL_MMAP_SIZE = 18
const m_SQLITE_FCNTL_NULL_IO = 43
const m_SQLITE_FCNTL_OVERWRITE = 11
const m_SQLITE_FCNTL_PDB = 30
const m_SQLITE_FCNTL_PERSIST_WAL = 10
const m_SQLITE_FCNTL_POWERSAFE_OVERWRITE = 13
const m_SQLITE_FCNTL_PRAGMA = 14
const m_SQLITE_FCNTL_RBU = 26
const m_SQLITE_FCNTL_RESERVE_BYTES = 38
const m_SQLITE_FCNTL_RESET_CACHE = 42
const m_SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE = 33
const m_SQLITE_FCNTL_SET_LOCKPROXYFILE = 3
const m_SQLITE_FCNTL_SIZE_HINT = 5
const m_SQLITE_FCNTL_SIZE_LIMIT = 36
const m_SQLITE_FCNTL_SYNC = 21
const m_SQLITE_FCNTL_SYNC_OMITTED = 8
const m_SQLITE_FCNTL_TEMPFILENAME = 16
const m_SQLITE_FCNTL_TRACE = 19
const m_SQLITE_FCNTL_VFSNAME = 12
const m_SQLITE_FCNTL_VFS_POINTER = 27
const m_SQLITE_FCNTL_WAL_BLOCK = 24
const m_SQLITE_FCNTL_WIN32_AV_RETRY = 9
const m_SQLITE_FCNTL_WIN32_GET_HANDLE = 29
const m_SQLITE_FCNTL_WIN32_SET_HANDLE = 23
const m_SQLITE_FCNTL_ZIPVFS = 25
const m_SQLITE_FLOAT = 2
const m_SQLITE_FORMAT = 24
const m_SQLITE_FULL = 13
const m_SQLITE_FUNCTION = 31
const m_SQLITE_GET_LOCKPROXYFILE = "SQLITE_FCNTL_GET_LOCKPROXYFILE"
const m_SQLITE_IGNORE = 2
const m_SQLITE_INDEX_CONSTRAINT_EQ = 2
const m_SQLITE_INDEX_CONSTRAINT_FUNCTION = 150
const m_SQLITE_INDEX_CONSTRAINT_GE = 32
const m_SQLITE_INDEX_CONSTRAINT_GLOB = 66
const m_SQLITE_INDEX_CONSTRAINT_GT = 4
const m_SQLITE_INDEX_CONSTRAINT_IS = 72
const m_SQLITE_INDEX_CONSTRAINT_ISNOT = 69
const m_SQLITE_INDEX_CONSTRAINT_ISNOTNULL = 70
const m_SQLITE_INDEX_CONSTRAINT_ISNULL = 71
const m_SQLITE_INDEX_CONSTRAINT_LE = 8
const m_SQLITE_INDEX_CONSTRAINT_LIKE = 65
const m_SQLITE_INDEX_CONSTRAINT_LIMIT = 73
const m_SQLITE_INDEX_CONSTRAINT_LT = 16
const m_SQLITE_INDEX_CONSTRAINT_MATCH = 64
const m_SQLITE_INDEX_CONSTRAINT_NE = 68
const m_SQLITE_INDEX_CONSTRAINT_OFFSET = 74
const m_SQLITE_INDEX_CONSTRAINT_REGEXP = 67
const m_SQLITE_INDEX_SCAN_HEX = 0x00000002
const m_SQLITE_INDEX_SCAN_UNIQUE = 0x00000001
const m_SQLITE_INNOCUOUS = 2097152
const m_SQLITE_INSERT = 18
const m_SQLITE_INTEGER = 1
const m_SQLITE_INTERNAL = 2
const m_SQLITE_INTERRUPT = 9
const m_SQLITE_IOCAP_ATOMIC = 0x00000001
const m_SQLITE_IOCAP_ATOMIC16K = 0x00000040
const m_SQLITE_IOCAP_ATOMIC1K = 0x00000004
const m_SQLITE_IOCAP_ATOMIC2K = 0x00000008
const m_SQLITE_IOCAP_ATOMIC32K = 0x00000080
const m_SQLITE_IOCAP_ATOMIC4K = 0x00000010
const m_SQLITE_IOCAP_ATOMIC512 = 0x00000002
const m_SQLITE_IOCAP_ATOMIC64K = 0x00000100
const m_SQLITE_IOCAP_ATOMIC8K = 0x00000020
const m_SQLITE_IOCAP_BATCH_ATOMIC = 0x00004000
const m_SQLITE_IOCAP_IMMUTABLE = 0x00002000
const m_SQLITE_IOCAP_POWERSAFE_OVERWRITE = 0x00001000
const m_SQLITE_IOCAP_SAFE_APPEND = 0x00000200
const m_SQLITE_IOCAP_SEQUENTIAL = 0x00000400
const m_SQLITE_IOCAP_SUBPAGE_READ = 0x00008000
const m_SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN = 0x00000800
const m_SQLITE_IOERR = 10
const m_SQLITE_LAST_ERRNO = "SQLITE_FCNTL_LAST_ERRNO"
const m_SQLITE_LIMIT_ATTACHED = 7
const m_SQLITE_LIMIT_COLUMN = 2
const m_SQLITE_LIMIT_COMPOUND_SELECT = 4
const m_SQLITE_LIMIT_EXPR_DEPTH = 3
const m_SQLITE_LIMIT_FUNCTION_ARG = 6
const m_SQLITE_LIMIT_LENGTH = 0
const m_SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8
const m_SQLITE_LIMIT_SQL_LENGTH = 1
const m_SQLITE_LIMIT_TRIGGER_DEPTH = 10
const m_SQLITE_LIMIT_VARIABLE_NUMBER = 9
const m_SQLITE_LIMIT_VDBE_OP = 5
const m_SQLITE_LIMIT_WORKER_THREADS = 11
const m_SQLITE_LOCKED = 6
const m_SQLITE_LOCK_EXCLUSIVE = 4
const m_SQLITE_LOCK_NONE = 0
const m_SQLITE_LOCK_PENDING = 3
const m_SQLITE_LOCK_RESERVED = 2
const m_SQLITE_LOCK_SHARED = 1
const m_SQLITE_MISMATCH = 20
const m_SQLITE_MISUSE = 21
const m_SQLITE_MUTEX_FAST = 0
const m_SQLITE_MUTEX_RECURSIVE = 1
const m_SQLITE_MUTEX_STATIC_APP1 = 8
const m_SQLITE_MUTEX_STATIC_APP2 = 9
const m_SQLITE_MUTEX_STATIC_APP3 = 10
const m_SQLITE_MUTEX_STATIC_LRU = 6
const m_SQLITE_MUTEX_STATIC_LRU2 = 7
const m_SQLITE_MUTEX_STATIC_MAIN = 2
const m_SQLITE_MUTEX_STATIC_MASTER = 2
const m_SQLITE_MUTEX_STATIC_MEM = 3
const m_SQLITE_MUTEX_STATIC_MEM2 = 4
const m_SQLITE_MUTEX_STATIC_OPEN = 4
const m_SQLITE_MUTEX_STATIC_PMEM = 7
const m_SQLITE_MUTEX_STATIC_PRNG = 5
const m_SQLITE_MUTEX_STATIC_VFS1 = 11
const m_SQLITE_MUTEX_STATIC_VFS2 = 12
const m_SQLITE_MUTEX_STATIC_VFS3 = 13
const m_SQLITE_NOLFS = 22
const m_SQLITE_NOMEM = 7
const m_SQLITE_NOTADB = 26
const m_SQLITE_NOTFOUND = 12
const m_SQLITE_NOTICE = 27
const m_SQLITE_NULL = 5
const m_SQLITE_OK = 0
const m_SQLITE_OPEN_AUTOPROXY = 0x00000020
const m_SQLITE_OPEN_CREATE = 0x00000004
const m_SQLITE_OPEN_DELETEONCLOSE = 0x00000008
const m_SQLITE_OPEN_EXCLUSIVE = 0x00000010
const m_SQLITE_OPEN_EXRESCODE = 0x02000000
const m_SQLITE_OPEN_FULLMUTEX = 0x00010000
const m_SQLITE_OPEN_MAIN_DB = 0x00000100
const m_SQLITE_OPEN_MAIN_JOURNAL = 0x00000800
const m_SQLITE_OPEN_MASTER_JOURNAL = 0x00004000
const m_SQLITE_OPEN_MEMORY = 0x00000080
const m_SQLITE_OPEN_NOFOLLOW = 0x01000000
const m_SQLITE_OPEN_NOMUTEX = 0x00008000
const m_SQLITE_OPEN_PRIVATECACHE = 0x00040000
const m_SQLITE_OPEN_READONLY = 0x00000001
const m_SQLITE_OPEN_READWRITE = 0x00000002
const m_SQLITE_OPEN_SHAREDCACHE = 0x00020000
const m_SQLITE_OPEN_SUBJOURNAL = 0x00002000
const m_SQLITE_OPEN_SUPER_JOURNAL = 0x00004000
const m_SQLITE_OPEN_TEMP_DB = 0x00000200
const m_SQLITE_OPEN_TEMP_JOURNAL = 0x00001000
const m_SQLITE_OPEN_TRANSIENT_DB = 0x00000400
const m_SQLITE_OPEN_URI = 0x00000040
const m_SQLITE_OPEN_WAL = 0x00080000
const m_SQLITE_PERM = 3
const m_SQLITE_PRAGMA = 19
const m_SQLITE_PREPARE_DONT_LOG = 0x10
const m_SQLITE_PREPARE_NORMALIZE = 0x02
const m_SQLITE_PREPARE_NO_VTAB = 0x04
const m_SQLITE_PREPARE_PERSISTENT = 0x01
const m_SQLITE_PROTOCOL = 15
const m_SQLITE_RANGE = 25
const m_SQLITE_READ = 20
const m_SQLITE_READONLY = 8
const m_SQLITE_RECURSIVE = 33
const m_SQLITE_REINDEX = 27
const m_SQLITE_REPLACE = 5
const m_SQLITE_RESULT_SUBTYPE = 16777216
const m_SQLITE_ROLLBACK = 1
const m_SQLITE_ROW = 100
const m_SQLITE_SAVEPOINT = 32
const m_SQLITE_SCANSTAT_COMPLEX = 0x0001
const m_SQLITE_SCANSTAT_EST = 2
const m_SQLITE_SCANSTAT_EXPLAIN = 4
const m_SQLITE_SCANSTAT_NAME = 3
const m_SQLITE_SCANSTAT_NCYCLE = 7
const m_SQLITE_SCANSTAT_NLOOP = 0
const m_SQLITE_SCANSTAT_NVISIT = 1
const m_SQLITE_SCANSTAT_PARENTID = 6
const m_SQLITE_SCANSTAT_SELECTID = 5
const m_SQLITE_SCHEMA = 17
const m_SQLITE_SCM_BRANCH = "branch-3.51"
const m_SQLITE_SCM_DATETIME = "2026-01-09T17:27:48.405Z"
const m_SQLITE_SCM_TAGS = "release version-3.51.2"
const m_SQLITE_SELECT = 21
const m_SQLITE_SELFORDER1 = 0x002000000
const m_SQLITE_SERIALIZE_NOCOPY = 0x001
const m_SQLITE_SETLK_BLOCK_ON_CONNECT = 0x01
const m_SQLITE_SET_LOCKPROXYFILE = "SQLITE_FCNTL_SET_LOCKPROXYFILE"
const m_SQLITE_SHM_EXCLUSIVE = 8
const m_SQLITE_SHM_LOCK = 2
const m_SQLITE_SHM_NLOCK = 8
const m_SQLITE_SHM_SHARED = 4
const m_SQLITE_SHM_UNLOCK = 1
const m_SQLITE_SOURCE_ID = "2026-01-09 17:27:48 b270f8339eb13b504d0b2ba154ebca966b7dde08e40c3ed7d559749818cb2075"
const m_SQLITE_STATUS_MALLOC_COUNT = 9
const m_SQLITE_STATUS_MALLOC_SIZE = 5
const m_SQLITE_STATUS_MEMORY_USED = 0
const m_SQLITE_STATUS_PAGECACHE_OVERFLOW = 2
const m_SQLITE_STATUS_PAGECACHE_SIZE = 7
const m_SQLITE_STATUS_PAGECACHE_USED = 1
const m_SQLITE_STATUS_PARSER_STACK = 6
const m_SQLITE_STATUS_SCRATCH_OVERFLOW = 4
const m_SQLITE_STATUS_SCRATCH_SIZE = 8
const m_SQLITE_STATUS_SCRATCH_USED = 3
const m_SQLITE_STDCALL = "SQLITE_APICALL"
const m_SQLITE_STMTSTATUS_AUTOINDEX = 3
const m_SQLITE_STMTSTATUS_FILTER_HIT = 8
const m_SQLITE_STMTSTATUS_FILTER_MISS = 7
const m_SQLITE_STMTSTATUS_FULLSCAN_STEP = 1
const m_SQLITE_STMTSTATUS_MEMUSED = 99
const m_SQLITE_STMTSTATUS_REPREPARE = 5
const m_SQLITE_STMTSTATUS_RUN = 6
const m_SQLITE_STMTSTATUS_SORT = 2
const m_SQLITE_STMTSTATUS_VM_STEP = 4
const m_SQLITE_SUBTYPE = 1048576
const m_SQLITE_SYNC_DATAONLY = 0x00010
const m_SQLITE_SYNC_FULL = 0x00003
const m_SQLITE_SYNC_NORMAL = 0x00002
const m_SQLITE_TESTCTRL_ALWAYS = 13
const m_SQLITE_TESTCTRL_ASSERT = 12
const m_SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS = 10
const m_SQLITE_TESTCTRL_BITVEC_TEST = 8
const m_SQLITE_TESTCTRL_BYTEORDER = 22
const m_SQLITE_TESTCTRL_EXPLAIN_STMT = 19
const m_SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS = 29
const m_SQLITE_TESTCTRL_FAULT_INSTALL = 9
const m_SQLITE_TESTCTRL_FIRST = 5
const m_SQLITE_TESTCTRL_FK_NO_ACTION = 7
const m_SQLITE_TESTCTRL_GETOPT = 16
const m_SQLITE_TESTCTRL_IMPOSTER = 25
const m_SQLITE_TESTCTRL_INTERNAL_FUNCTIONS = 17
const m_SQLITE_TESTCTRL_ISINIT = 23
const m_SQLITE_TESTCTRL_ISKEYWORD = 16
const m_SQLITE_TESTCTRL_JSON_SELFCHECK = 14
const m_SQLITE_TESTCTRL_LAST = 34
const m_SQLITE_TESTCTRL_LOCALTIME_FAULT = 18
const m_SQLITE_TESTCTRL_LOGEST = 33
const m_SQLITE_TESTCTRL_NEVER_CORRUPT = 20
const m_SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD = 19
const m_SQLITE_TESTCTRL_OPTIMIZATIONS = 15
const m_SQLITE_TESTCTRL_PARSER_COVERAGE = 26
const m_SQLITE_TESTCTRL_PENDING_BYTE = 11
const m_SQLITE_TESTCTRL_PRNG_RESET = 7
const m_SQLITE_TESTCTRL_PRNG_RESTORE = 6
const m_SQLITE_TESTCTRL_PRNG_SAVE = 5
const m_SQLITE_TESTCTRL_PRNG_SEED = 28
const m_SQLITE_TESTCTRL_RESERVE = 14
const m_SQLITE_TESTCTRL_RESULT_INTREAL = 27
const m_SQLITE_TESTCTRL_SCRATCHMALLOC = 17
const m_SQLITE_TESTCTRL_SEEK_COUNT = 30
const m_SQLITE_TESTCTRL_SORTER_MMAP = 24
const m_SQLITE_TESTCTRL_TRACEFLAGS = 31
const m_SQLITE_TESTCTRL_TUNE = 32
const m_SQLITE_TESTCTRL_USELONGDOUBLE = 34
const m_SQLITE_TESTCTRL_VDBE_COVERAGE = 21
const m_SQLITE_TEXT = 3
const m_SQLITE_THREADSAFE = 0
const m_SQLITE_TOOBIG = 18
const m_SQLITE_TRACE_CLOSE = 0x08
const m_SQLITE_TRACE_PROFILE = 0x02
const m_SQLITE_TRACE_ROW = 0x04
const m_SQLITE_TRACE_STMT = 0x01
const m_SQLITE_TRANSACTION = 22
const m_SQLITE_TXN_NONE = 0
const m_SQLITE_TXN_READ = 1
const m_SQLITE_TXN_WRITE = 2
const m_SQLITE_UPDATE = 23
const m_SQLITE_UTF16 = 4
const m_SQLITE_UTF16BE = 3
const m_SQLITE_UTF16LE = 2
const m_SQLITE_UTF16_ALIGNED = 8
const m_SQLITE_UTF8 = 1
const m_SQLITE_VEC_CHUNK_SIZE_MAX = 4096
const m_SQLITE_VEC_DATE = "2024-11-20T17:34:19Z+0100"
const m_SQLITE_VEC_DEBUG_BUILD_AVX = ""
const m_SQLITE_VEC_DEBUG_BUILD_NEON = ""
const m_SQLITE_VEC_NPY_FILE_NAME = "vec0-npy-file"
const m_SQLITE_VEC_SOURCE = ""
const m_SQLITE_VEC_STATIC = 1
const m_SQLITE_VEC_VEC0_K_MAX = 4096
const m_SQLITE_VEC_VEC0_MAX_DIMENSIONS = 8192
const m_SQLITE_VEC_VERSION = "v0.1.6"
const m_SQLITE_VEC_VERSION_MAJOR = 0
const m_SQLITE_VEC_VERSION_MINOR = 1
const m_SQLITE_VEC_VERSION_PATCH = 6
const m_SQLITE_VERSION = "3.51.2"
const m_SQLITE_VERSION_NUMBER = 3051002
const m_SQLITE_VTAB_CONSTRAINT_SUPPORT = 1
const m_SQLITE_VTAB_DIRECTONLY = 3
const m_SQLITE_VTAB_INNOCUOUS = 2
const m_SQLITE_VTAB_USES_ALL_SCHEMAS = 4
const m_SQLITE_WARNING = 28
const m_SQLITE_WIN32_DATA_DIRECTORY_TYPE = 1
const m_SQLITE_WIN32_TEMP_DIRECTORY_TYPE = 2
const m_SSIZE_MAX = "LONG_MAX"
const m_SYMLOOP_MAX = 40
const m_TMP_MAX = 10000
const m_TTY_NAME_MAX = 32
const m_TZNAME_MAX = 6
const m_UCHAR_MAX = 255
const m_UINT16_MAX = 0xffff
const m_UINT32_MAX = "0xffffffffu"
const m_UINT64_MAX = "0xffffffffffffffffu"
const m_UINT8_MAX = 0xff
const m_UINTMAX_MAX = "UINT64_MAX"
const m_UINTPTR_MAX = "UINT64_MAX"
const m_UINT_FAST16_MAX = "UINT32_MAX"
const m_UINT_FAST32_MAX = "UINT32_MAX"
const m_UINT_FAST64_MAX = "UINT64_MAX"
const m_UINT_FAST8_MAX = "UINT8_MAX"
const m_UINT_LEAST16_MAX = "UINT16_MAX"
const m_UINT_LEAST32_MAX = "UINT32_MAX"
const m_UINT_LEAST64_MAX = "UINT64_MAX"
const m_UINT_LEAST8_MAX = "UINT8_MAX"
const m_UINT_MAX = 0xffffffff
const m_USHRT_MAX = 0xffff
const m_VEC0_COLUMN_ID = 0
const m_VEC0_COLUMN_OFFSET_DISTANCE = 1
const m_VEC0_COLUMN_OFFSET_K = 2
const m_VEC0_COLUMN_USERN_START = 1
const m_VEC0_MAX_AUXILIARY_COLUMNS = 16
const m_VEC0_MAX_METADATA_COLUMNS = 16
const m_VEC0_MAX_PARTITION_COLUMNS = 4
const m_VEC0_MAX_VECTOR_COLUMNS = 16
const m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH = 16
const m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH = 12
const m_VEC0_SHADOW_AUXILIARY_NAME = "\\\"%w\\\".\\\"%w_auxiliary\\\""
const m_VEC0_SHADOW_CHUNKS_NAME = "\\\"%w\\\".\\\"%w_chunks\\\""
const m_VEC0_SHADOW_INFO_NAME = "\\\"%w\\\".\\\"%w_info\\\""
const m_VEC0_SHADOW_METADATA_N_NAME = "\\\"%w\\\".\\\"%w_metadatachunks%02d\\\""
const m_VEC0_SHADOW_METADATA_TEXT_DATA_NAME = "\\\"%w\\\".\\\"%w_metadatatext%02d\\\""
const m_VEC0_SHADOW_ROWIDS_NAME = "\\\"%w\\\".\\\"%w_rowids\\\""
const m_VEC0_SHADOW_VECTOR_N_NAME = "\\\"%w\\\".\\\"%w_vector_chunks%02d\\\""
const m_VEC0_TOKEN_RESULT_EOF = 1
const m_VEC0_TOKEN_RESULT_ERROR = 3
const m_VEC0_TOKEN_RESULT_SOME = 2
const m_VEC_CONSTRUCTOR_ERROR = "vec0 constructor error: could not parse vector column '%s'"
const m_VEC_EACH_COLUMN_VALUE = 0
const m_VEC_EACH_COLUMN_VECTOR = 1
const m_VEC_INTERAL_ERROR = "Internal sqlite-vec error: could not initialize 'rowids get chunk position' statement"
const m_VEC_NPY_EACH_COLUMN_INPUT = 1
const m_VEC_NPY_EACH_COLUMN_VECTOR = 0
const m_VEC_STATIC_BLOBS_COUNT = 3
const m_VEC_STATIC_BLOBS_DATA = 1
const m_VEC_STATIC_BLOBS_DIMENSIONS = 2
const m_VEC_STATIC_BLOBS_NAME = 0
const m_VEC_STATIC_BLOB_ENTRIES_DISTANCE = 1
const m_VEC_STATIC_BLOB_ENTRIES_K = 2
const m_VEC_STATIC_BLOB_ENTRIES_VECTOR = 0
const m_WINT_MAX = "UINT32_MAX"
const m_WINT_MIN = 0
const m_WNOHANG = 1
const m_WORD_BIT = 32
const m_WUNTRACED = 2
const m__GNU_SOURCE = 1
const m__IOFBF = 0
const m__IOLBF = 1
const m__IONBF = 2
const m__LP64 = 1
const m__POSIX2_BC_BASE_MAX = 99
const m__POSIX2_BC_DIM_MAX = 2048
const m__POSIX2_BC_SCALE_MAX = 99
const m__POSIX2_BC_STRING_MAX = 1000
const m__POSIX2_CHARCLASS_NAME_MAX = 14
const m__POSIX2_COLL_WEIGHTS_MAX = 2
const m__POSIX2_EXPR_NEST_MAX = 32
const m__POSIX2_LINE_MAX = 2048
const m__POSIX2_RE_DUP_MAX = 255
const m__POSIX_AIO_LISTIO_MAX = 2
const m__POSIX_AIO_MAX = 1
const m__POSIX_ARG_MAX = 4096
const m__POSIX_CHILD_MAX = 25
const m__POSIX_CLOCKRES_MIN = 20000000
const m__POSIX_DELAYTIMER_MAX = 32
const m__POSIX_HOST_NAME_MAX = 255
const m__POSIX_LINK_MAX = 8
const m__POSIX_LOGIN_NAME_MAX = 9
const m__POSIX_MAX_CANON = 255
const m__POSIX_MAX_INPUT = 255
const m__POSIX_MQ_OPEN_MAX = 8
const m__POSIX_MQ_PRIO_MAX = 32
const m__POSIX_NAME_MAX = 14
const m__POSIX_NGROUPS_MAX = 8
const m__POSIX_OPEN_MAX = 20
const m__POSIX_PATH_MAX = 256
const m__POSIX_PIPE_BUF = 512
const m__POSIX_RE_DUP_MAX = 255
const m__POSIX_RTSIG_MAX = 8
const m__POSIX_SEM_NSEMS_MAX = 256
const m__POSIX_SEM_VALUE_MAX = 32767
const m__POSIX_SIGQUEUE_MAX = 32
const m__POSIX_SSIZE_MAX = 32767
const m__POSIX_SS_REPL_MAX = 4
const m__POSIX_STREAM_MAX = 8
const m__POSIX_SYMLINK_MAX = 255
const m__POSIX_SYMLOOP_MAX = 8
const m__POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4
const m__POSIX_THREAD_KEYS_MAX = 128
const m__POSIX_THREAD_THREADS_MAX = 64
const m__POSIX_TIMER_MAX = 32
const m__POSIX_TRACE_EVENT_NAME_MAX = 30
const m__POSIX_TRACE_NAME_MAX = 8
const m__POSIX_TRACE_SYS_MAX = 8
const m__POSIX_TRACE_USER_EVENT_MAX = 32
const m__POSIX_TTY_NAME_MAX = 9
const m__POSIX_TZNAME_MAX = 6
const m__STDC_PREDEF_H = 1
const m__XOPEN_IOV_MAX = 16
const m__XOPEN_NAME_MAX = 255
const m__XOPEN_PATH_MAX = 1024
const m___ARCH__ = 9
const m___ATOMIC_ACQUIRE = 2
const m___ATOMIC_ACQ_REL = 4
const m___ATOMIC_CONSUME = 1
const m___ATOMIC_RELAXED = 0
const m___ATOMIC_RELEASE = 3
const m___ATOMIC_SEQ_CST = 5
const m___BIGGEST_ALIGNMENT__ = 8
const m___BIG_ENDIAN = 4321
const m___BYTE_ORDER = 4321
const m___BYTE_ORDER__ = "__ORDER_BIG_ENDIAN__"
const m___CCGO__ = 1
const m___CHAR_BIT__ = 8
const m___CHAR_UNSIGNED__ = 1
const m___DBL_DECIMAL_DIG__ = 17
const m___DBL_DIG__ = 15
const m___DBL_HAS_DENORM__ = 1
const m___DBL_HAS_INFINITY__ = 1
const m___DBL_HAS_QUIET_NAN__ = 1
const m___DBL_IS_IEC_60559__ = 2
const m___DBL_MANT_DIG__ = 53
const m___DBL_MAX_10_EXP__ = 308
const m___DBL_MAX_EXP__ = 1024
const m___DEC128_EPSILON__ = 1e-33
const m___DEC128_MANT_DIG__ = 34
const m___DEC128_MAX_EXP__ = 6145
const m___DEC128_MAX__ = "9.999999999999999999999999999999999E6144"
const m___DEC128_MIN__ = 1e-6143
const m___DEC128_SUBNORMAL_MIN__ = 0.000000000000000000000000000000001e-6143
const m___DEC32_EPSILON__ = 1e-6
const m___DEC32_MANT_DIG__ = 7
const m___DEC32_MAX_EXP__ = 97
const m___DEC32_MAX__ = 9.999999e96
const m___DEC32_MIN__ = 1e-95
const m___DEC32_SUBNORMAL_MIN__ = 0.000001e-95
const m___DEC64_EPSILON__ = 1e-15
const m___DEC64_MANT_DIG__ = 16
const m___DEC64_MAX_EXP__ = 385
const m___DEC64_MAX__ = "9.999999999999999E384"
const m___DEC64_MIN__ = 1e-383
const m___DEC64_SUBNORMAL_MIN__ = 0.000000000000001e-383
const m___DECIMAL_DIG__ = 17
const m___DEC_EVAL_METHOD__ = 2
const m___ELF__ = 1
const m___FINITE_MATH_ONLY__ = 0
const m___FLOAT_WORD_ORDER__ = "__ORDER_BIG_ENDIAN__"
const m___FLT32X_DECIMAL_DIG__ = 17
const m___FLT32X_DENORM_MIN__ = 4.9406564584124654e-324
const m___FLT32X_DIG__ = 15
const m___FLT32X_EPSILON__ = 2.2204460492503131e-16
const m___FLT32X_HAS_DENORM__ = 1
const m___FLT32X_HAS_INFINITY__ = 1
const m___FLT32X_HAS_QUIET_NAN__ = 1
const m___FLT32X_IS_IEC_60559__ = 2
const m___FLT32X_MANT_DIG__ = 53
const m___FLT32X_MAX_10_EXP__ = 308
const m___FLT32X_MAX_EXP__ = 1024
const m___FLT32X_MAX__ = 1.7976931348623157e+308
const m___FLT32X_MIN__ = 2.2250738585072014e-308
const m___FLT32X_NORM_MAX__ = 1.7976931348623157e+308
const m___FLT32_DECIMAL_DIG__ = 9
const m___FLT32_DENORM_MIN__ = 1.4012984643248171e-45
const m___FLT32_DIG__ = 6
const m___FLT32_EPSILON__ = 1.1920928955078125e-7
const m___FLT32_HAS_DENORM__ = 1
const m___FLT32_HAS_INFINITY__ = 1
const m___FLT32_HAS_QUIET_NAN__ = 1
const m___FLT32_IS_IEC_60559__ = 2
const m___FLT32_MANT_DIG__ = 24
const m___FLT32_MAX_10_EXP__ = 38
const m___FLT32_MAX_EXP__ = 128
const m___FLT32_MAX__ = 3.4028234663852886e+38
const m___FLT32_MIN__ = 1.1754943508222875e-38
const m___FLT32_NORM_MAX__ = 3.4028234663852886e+38
const m___FLT64_DECIMAL_DIG__ = 17
const m___FLT64_DENORM_MIN__ = 4.9406564584124654e-324
const m___FLT64_DIG__ = 15
const m___FLT64_EPSILON__ = 2.2204460492503131e-16
const m___FLT64_HAS_DENORM__ = 1
const m___FLT64_HAS_INFINITY__ = 1
const m___FLT64_HAS_QUIET_NAN__ = 1
const m___FLT64_IS_IEC_60559__ = 2
const m___FLT64_MANT_DIG__ = 53
const m___FLT64_MAX_10_EXP__ = 308
const m___FLT64_MAX_EXP__ = 1024
const m___FLT64_MAX__ = 1.7976931348623157e+308
const m___FLT64_MIN__ = 2.2250738585072014e-308
const m___FLT64_NORM_MAX__ = 1.7976931348623157e+308
const m___FLT_DECIMAL_DIG__ = 9
const m___FLT_DENORM_MIN__ = 1.4012984643248171e-45
const m___FLT_DIG__ = 6
const m___FLT_EPSILON__ = 1.1920928955078125e-7
const m___FLT_EVAL_METHOD_TS_18661_3__ = 0
const m___FLT_EVAL_METHOD__ = 0
const m___FLT_HAS_DENORM__ = 1
const m___FLT_HAS_INFINITY__ = 1
const m___FLT_HAS_QUIET_NAN__ = 1
const m___FLT_IS_IEC_60559__ = 2
const m___FLT_MANT_DIG__ = 24
const m___FLT_MAX_10_EXP__ = 38
const m___FLT_MAX_EXP__ = 128
const m___FLT_MAX__ = 3.4028234663852886e+38
const m___FLT_MIN__ = 1.1754943508222875e-38
const m___FLT_NORM_MAX__ = 3.4028234663852886e+38
const m___FLT_RADIX__ = 2
const m___FP_FAST_FMA = 1
const m___FP_FAST_FMAF = 1
const m___FP_FAST_FMAF32 = 1
const m___FP_FAST_FMAF32x = 1
const m___FP_FAST_FMAF64 = 1
const m___FP_FAST_FMAL = 1
const m___FUNCTION__ = "__func__"
const m___GCC_ATOMIC_BOOL_LOCK_FREE = 2
const m___GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2
const m___GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2
const m___GCC_ATOMIC_CHAR_LOCK_FREE = 2
const m___GCC_ATOMIC_INT_LOCK_FREE = 2
const m___GCC_ATOMIC_LLONG_LOCK_FREE = 2
const m___GCC_ATOMIC_LONG_LOCK_FREE = 2
const m___GCC_ATOMIC_POINTER_LOCK_FREE = 2
const m___GCC_ATOMIC_SHORT_LOCK_FREE = 2
const m___GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1
const m___GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2
const m___GCC_HAVE_DWARF2_CFI_ASM = 1
const m___GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1
const m___GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 = 1
const m___GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1
const m___GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1
const m___GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1
const m___GCC_IEC_559 = 2
const m___GCC_IEC_559_COMPLEX = 2
const m___GNUC_EXECUTION_CHARSET_NAME = "UTF-8"
const m___GNUC_MINOR__ = 2
const m___GNUC_PATCHLEVEL__ = 0
const m___GNUC_STDC_INLINE__ = 1
const m___GNUC_WIDE_EXECUTION_CHARSET_NAME = "UTF-32BE"
const m___GNUC__ = 12
const m___GXX_ABI_VERSION = 1017
const m___HAVE_SPECULATION_SAFE_VALUE = 1
const m___INT16_MAX__ = 0x7fff
const m___INT32_MAX__ = 0x7fffffff
const m___INT32_TYPE__ = "int"
const m___INT64_MAX__ = 0x7fffffffffffffff
const m___INT8_MAX__ = 0x7f
const m___INTMAX_MAX__ = 0x7fffffffffffffff
const m___INTMAX_WIDTH__ = 64
const m___INTPTR_MAX__ = 0x7fffffffffffffff
const m___INTPTR_WIDTH__ = 64
const m___INT_FAST16_MAX__ = 0x7fffffffffffffff
const m___INT_FAST16_WIDTH__ = 64
const m___INT_FAST32_MAX__ = 0x7fffffffffffffff
const m___INT_FAST32_WIDTH__ = 64
const m___INT_FAST64_MAX__ = 0x7fffffffffffffff
const m___INT_FAST64_WIDTH__ = 64
const m___INT_FAST8_MAX__ = 0x7f
const m___INT_FAST8_WIDTH__ = 8
const m___INT_LEAST16_MAX__ = 0x7fff
const m___INT_LEAST16_WIDTH__ = 16
const m___INT_LEAST32_MAX__ = 0x7fffffff
const m___INT_LEAST32_TYPE__ = "int"
const m___INT_LEAST32_WIDTH__ = 32
const m___INT_LEAST64_MAX__ = 0x7fffffffffffffff
const m___INT_LEAST64_WIDTH__ = 64
const m___INT_LEAST8_MAX__ = 0x7f
const m___INT_LEAST8_WIDTH__ = 8
const m___INT_MAX__ = 0x7fffffff
const m___INT_WIDTH__ = 32
const m___LDBL_DECIMAL_DIG__ = 17
const m___LDBL_DENORM_MIN__ = 4.9406564584124654e-324
const m___LDBL_DIG__ = 15
const m___LDBL_EPSILON__ = 2.2204460492503131e-16
const m___LDBL_HAS_DENORM__ = 1
const m___LDBL_HAS_INFINITY__ = 1
const m___LDBL_HAS_QUIET_NAN__ = 1
const m___LDBL_IS_IEC_60559__ = 2
const m___LDBL_MANT_DIG__ = 53
const m___LDBL_MAX_10_EXP__ = 308
const m___LDBL_MAX_EXP__ = 1024
const m___LDBL_MAX__ = 1.7976931348623157e+308
const m___LDBL_MIN__ = 2.2250738585072014e-308
const m___LDBL_NORM_MAX__ = 1.7976931348623157e+308
const m___LITTLE_ENDIAN = 1234
const m___LONG_LONG_MAX__ = 0x7fffffffffffffff
const m___LONG_LONG_WIDTH__ = 64
const m___LONG_MAX = 9223372036854775807
const m___LONG_MAX__ = 0x7fffffffffffffff
const m___LONG_WIDTH__ = 64
const m___LP64__ = 1
const m___OPTIMIZE__ = 1
const m___ORDER_BIG_ENDIAN__ = 4321
const m___ORDER_LITTLE_ENDIAN__ = 1234
const m___ORDER_PDP_ENDIAN__ = 3412
const m___PIC__ = 2
const m___PIE__ = 2
const m___PRAGMA_REDEFINE_EXTNAME = 1
const m___PRETTY_FUNCTION__ = "__func__"
const m___PRI64 = "l"
const m___PRIPTR = "l"
const m___PTRDIFF_MAX__ = 0x7fffffffffffffff
const m___PTRDIFF_WIDTH__ = 64
const m___SCHAR_MAX__ = 0x7f
const m___SCHAR_WIDTH__ = 8
const m___SHRT_MAX__ = 0x7fff
const m___SHRT_WIDTH__ = 16
const m___SIG_ATOMIC_MAX__ = 0x7fffffff
const m___SIG_ATOMIC_TYPE__ = "int"
const m___SIG_ATOMIC_WIDTH__ = 32
const m___SIZEOF_DOUBLE__ = 8
const m___SIZEOF_FLOAT__ = 4
const m___SIZEOF_INT128__ = 16
const m___SIZEOF_INT__ = 4
const m___SIZEOF_LONG_DOUBLE__ = 8
const m___SIZEOF_LONG_LONG__ = 8
const m___SIZEOF_LONG__ = 8
const m___SIZEOF_POINTER__ = 8
const m___SIZEOF_PTRDIFF_T__ = 8
const m___SIZEOF_SHORT__ = 2
const m___SIZEOF_SIZE_T__ = 8
const m___SIZEOF_WCHAR_T__ = 4
const m___SIZEOF_WINT_T__ = 4
const m___SIZE_MAX__ = 0xffffffffffffffff
const m___SIZE_WIDTH__ = 64
const m___STDC_HOSTED__ = 1
const m___STDC_IEC_559_COMPLEX__ = 1
const m___STDC_IEC_559__ = 1
const m___STDC_IEC_60559_BFP__ = 201404
const m___STDC_IEC_60559_COMPLEX__ = 201404
const m___STDC_ISO_10646__ = 201706
const m___STDC_UTF_16__ = 1
const m___STDC_UTF_32__ = 1
const m___STDC_VERSION__ = 201710
const m___STDC__ = 1
const m___UINT16_MAX__ = 0xffff
const m___UINT32_MAX__ = 0xffffffff
const m___UINT64_MAX__ = 0xffffffffffffffff
const m___UINT8_MAX__ = 0xff
const m___UINTMAX_MAX__ = 0xffffffffffffffff
const m___UINTPTR_MAX__ = 0xffffffffffffffff
const m___UINT_FAST16_MAX__ = 0xffffffffffffffff
const m___UINT_FAST32_MAX__ = 0xffffffffffffffff
const m___UINT_FAST64_MAX__ = 0xffffffffffffffff
const m___UINT_FAST8_MAX__ = 0xff
const m___UINT_LEAST16_MAX__ = 0xffff
const m___UINT_LEAST32_MAX__ = 0xffffffff
const m___UINT_LEAST64_MAX__ = 0xffffffffffffffff
const m___UINT_LEAST8_MAX__ = 0xff
const m___USE_TIME_BITS64 = 1
const m___VERSION__ = "12.2.0"
const m___WCHAR_MAX__ = 0x7fffffff
const m___WCHAR_TYPE__ = "int"
const m___WCHAR_WIDTH__ = 32
const m___WINT_MAX__ = 0xffffffff
const m___WINT_MIN__ = 0
const m___WINT_WIDTH__ = 32
const m___bool_true_false_are_defined = 1
const m___gnu_linux__ = 1
const m___inline = "inline"
const m___linux = 1
const m___linux__ = 1
const m___pic__ = 2
const m___pie__ = 2
const m___restrict = "restrict"
const m___restrict_arr = "restrict"
const m___s390__ = 1
const m___s390x__ = 1
const m___unix = 1
const m___unix__ = 1
const m___wasi__ = 1
const m___zarch__ = 1
const m_alloca = "__builtin_alloca"
const m_bool = "_Bool"
const m_false = 0
const m_linux = 1
const m_math_errhandling = 2
const m_static_assert = "_Static_assert"
const m_true = 1
const m_unix = 1

type t__builtin_va_list = uintptr

type t__predefined_size_t = uint64

type t__predefined_wchar_t = int32

type t__predefined_ptrdiff_t = int64

type Tva_list = uintptr

type va_list = Tva_list

type Tsqlite_int64 = int64

type sqlite_int64 = Tsqlite_int64

type Tsqlite_uint64 = uint64

type sqlite_uint64 = Tsqlite_uint64

type Tsqlite3_int64 = int64

type sqlite3_int64 = Tsqlite3_int64

type Tsqlite3_uint64 = uint64

type sqlite3_uint64 = Tsqlite3_uint64

type Tsqlite3_callback = uintptr

type sqlite3_callback = Tsqlite3_callback

type Tsqlite3_file = struct {
	FpMethods uintptr
}

type sqlite3_file = Tsqlite3_file

type Tsqlite3_io_methods = struct {
	FiVersion               int32
	FxClose                 uintptr
	FxRead                  uintptr
	FxWrite                 uintptr
	FxTruncate              uintptr
	FxSync                  uintptr
	FxFileSize              uintptr
	FxLock                  uintptr
	FxUnlock                uintptr
	FxCheckReservedLock     uintptr
	FxFileControl           uintptr
	FxSectorSize            uintptr
	FxDeviceCharacteristics uintptr
	FxShmMap                uintptr
	FxShmLock               uintptr
	FxShmBarrier            uintptr
	FxShmUnmap              uintptr
	FxFetch                 uintptr
	FxUnfetch               uintptr
}

type sqlite3_io_methods = Tsqlite3_io_methods

type Tsqlite3_filename = uintptr

type sqlite3_filename = Tsqlite3_filename

type Tsqlite3_vfs = struct {
	FiVersion          int32
	FszOsFile          int32
	FmxPathname        int32
	FpNext             uintptr
	FzName             uintptr
	FpAppData          uintptr
	FxOpen             uintptr
	FxDelete           uintptr
	FxAccess           uintptr
	FxFullPathname     uintptr
	FxDlOpen           uintptr
	FxDlError          uintptr
	FxDlSym            uintptr
	FxDlClose          uintptr
	FxRandomness       uintptr
	FxSleep            uintptr
	FxCurrentTime      uintptr
	FxGetLastError     uintptr
	FxCurrentTimeInt64 uintptr
	FxSetSystemCall    uintptr
	FxGetSystemCall    uintptr
	FxNextSystemCall   uintptr
}

type sqlite3_vfs = Tsqlite3_vfs

type Tsqlite3_syscall_ptr = uintptr

type sqlite3_syscall_ptr = Tsqlite3_syscall_ptr

type Tsqlite3_mem_methods = struct {
	FxMalloc   uintptr
	FxFree     uintptr
	FxRealloc  uintptr
	FxSize     uintptr
	FxRoundup  uintptr
	FxInit     uintptr
	FxShutdown uintptr
	FpAppData  uintptr
}

type sqlite3_mem_methods = Tsqlite3_mem_methods

type Tsqlite3_destructor_type = uintptr

type sqlite3_destructor_type = Tsqlite3_destructor_type

type Tsqlite3_vtab = struct {
	FpModule uintptr
	FnRef    int32
	FzErrMsg uintptr
}

type sqlite3_vtab = Tsqlite3_vtab

type Tsqlite3_index_info = struct {
	FnConstraint      int32
	FaConstraint      uintptr
	FnOrderBy         int32
	FaOrderBy         uintptr
	FaConstraintUsage uintptr
	FidxNum           int32
	FidxStr           uintptr
	FneedToFreeIdxStr int32
	ForderByConsumed  int32
	FestimatedCost    float64
	FestimatedRows    Tsqlite3_int64
	FidxFlags         int32
	FcolUsed          Tsqlite3_uint64
}

type sqlite3_index_info = Tsqlite3_index_info

type Tsqlite3_vtab_cursor = struct {
	FpVtab uintptr
}

type sqlite3_vtab_cursor = Tsqlite3_vtab_cursor

type Tsqlite3_module = struct {
	FiVersion      int32
	FxCreate       uintptr
	FxConnect      uintptr
	FxBestIndex    uintptr
	FxDisconnect   uintptr
	FxDestroy      uintptr
	FxOpen         uintptr
	FxClose        uintptr
	FxFilter       uintptr
	FxNext         uintptr
	FxEof          uintptr
	FxColumn       uintptr
	FxRowid        uintptr
	FxUpdate       uintptr
	FxBegin        uintptr
	FxSync         uintptr
	FxCommit       uintptr
	FxRollback     uintptr
	FxFindFunction uintptr
	FxRename       uintptr
	FxSavepoint    uintptr
	FxRelease      uintptr
	FxRollbackTo   uintptr
	FxShadowName   uintptr
	FxIntegrity    uintptr
}

type sqlite3_module = Tsqlite3_module

type Tsqlite3_mutex_methods = struct {
	FxMutexInit    uintptr
	FxMutexEnd     uintptr
	FxMutexAlloc   uintptr
	FxMutexFree    uintptr
	FxMutexEnter   uintptr
	FxMutexTry     uintptr
	FxMutexLeave   uintptr
	FxMutexHeld    uintptr
	FxMutexNotheld uintptr
}

type sqlite3_mutex_methods = Tsqlite3_mutex_methods

type Tsqlite3_pcache_page = struct {
	FpBuf   uintptr
	FpExtra uintptr
}

type sqlite3_pcache_page = Tsqlite3_pcache_page

type Tsqlite3_pcache_methods2 = struct {
	FiVersion   int32
	FpArg       uintptr
	FxInit      uintptr
	FxShutdown  uintptr
	FxCreate    uintptr
	FxCachesize uintptr
	FxPagecount uintptr
	FxFetch     uintptr
	FxUnpin     uintptr
	FxRekey     uintptr
	FxTruncate  uintptr
	FxDestroy   uintptr
	FxShrink    uintptr
}

type sqlite3_pcache_methods2 = Tsqlite3_pcache_methods2

type Tsqlite3_pcache_methods = struct {
	FpArg       uintptr
	FxInit      uintptr
	FxShutdown  uintptr
	FxCreate    uintptr
	FxCachesize uintptr
	FxPagecount uintptr
	FxFetch     uintptr
	FxUnpin     uintptr
	FxRekey     uintptr
	FxTruncate  uintptr
	FxDestroy   uintptr
}

type sqlite3_pcache_methods = Tsqlite3_pcache_methods

type Tsqlite3_snapshot = struct {
	Fhidden [48]uint8
}

type sqlite3_snapshot = Tsqlite3_snapshot

type Tsqlite3_rtree_geometry = struct {
	FpContext uintptr
	FnParam   int32
	FaParam   uintptr
	FpUser    uintptr
	FxDelUser uintptr
}

type sqlite3_rtree_geometry = Tsqlite3_rtree_geometry

type Tsqlite3_rtree_query_info = struct {
	FpContext      uintptr
	FnParam        int32
	FaParam        uintptr
	FpUser         uintptr
	FxDelUser      uintptr
	FaCoord        uintptr
	FanQueue       uintptr
	FnCoord        int32
	FiLevel        int32
	FmxLevel       int32
	FiRowid        Tsqlite3_int64
	FrParentScore  Tsqlite3_rtree_dbl
	FeParentWithin int32
	FeWithin       int32
	FrScore        Tsqlite3_rtree_dbl
	FapSqlParam    uintptr
}

type sqlite3_rtree_query_info = Tsqlite3_rtree_query_info

type Tsqlite3_rtree_dbl = float64

type sqlite3_rtree_dbl = Tsqlite3_rtree_dbl

type TFts5ExtensionApi = struct {
	FiVersion           int32
	FxUserData          uintptr
	FxColumnCount       uintptr
	FxRowCount          uintptr
	FxColumnTotalSize   uintptr
	FxTokenize          uintptr
	FxPhraseCount       uintptr
	FxPhraseSize        uintptr
	FxInstCount         uintptr
	FxInst              uintptr
	FxRowid             uintptr
	FxColumnText        uintptr
	FxColumnSize        uintptr
	FxQueryPhrase       uintptr
	FxSetAuxdata        uintptr
	FxGetAuxdata        uintptr
	FxPhraseFirst       uintptr
	FxPhraseNext        uintptr
	FxPhraseFirstColumn uintptr
	FxPhraseNextColumn  uintptr
	FxQueryToken        uintptr
	FxInstToken         uintptr
	FxColumnLocale      uintptr
	FxTokenize_v2       uintptr
}

type Fts5ExtensionApi = TFts5ExtensionApi

type TFts5PhraseIter = struct {
	Fa uintptr
	Fb uintptr
}

type Fts5PhraseIter = TFts5PhraseIter

type Tfts5_extension_function = uintptr

type fts5_extension_function = Tfts5_extension_function

type Tfts5_tokenizer_v2 = struct {
	FiVersion  int32
	FxCreate   uintptr
	FxDelete   uintptr
	FxTokenize uintptr
}

type fts5_tokenizer_v2 = Tfts5_tokenizer_v2

type Tfts5_tokenizer = struct {
	FxCreate   uintptr
	FxDelete   uintptr
	FxTokenize uintptr
}

type fts5_tokenizer = Tfts5_tokenizer

type Tfts5_api = struct {
	FiVersion            int32
	FxCreateTokenizer    uintptr
	FxFindTokenizer      uintptr
	FxCreateFunction     uintptr
	FxCreateTokenizer_v2 uintptr
	FxFindTokenizer_v2   uintptr
}

type fts5_api = Tfts5_api

type Tuintptr_t = uint64

type uintptr_t = Tuintptr_t

type Tintptr_t = int64

type intptr_t = Tintptr_t

type Tint8_t = int8

type int8_t = Tint8_t

type Tint16_t = int16

type int16_t = Tint16_t

type Tint32_t = int32

type int32_t = Tint32_t

type Tint64_t = int64

type int64_t = Tint64_t

type Tintmax_t = int64

type intmax_t = Tintmax_t

type Tuint8_t = uint8

type uint8_t = Tuint8_t

type Tuint16_t = uint16

type uint16_t = Tuint16_t

type Tuint32_t = uint32

type uint32_t = Tuint32_t

type Tuint64_t = uint64

type uint64_t = Tuint64_t

type Tuintmax_t = uint64

type uintmax_t = Tuintmax_t

type Tint_fast8_t = int8

type int_fast8_t = Tint_fast8_t

type Tint_fast64_t = int64

type int_fast64_t = Tint_fast64_t

type Tint_least8_t = int8

type int_least8_t = Tint_least8_t

type Tint_least16_t = int16

type int_least16_t = Tint_least16_t

type Tint_least32_t = int32

type int_least32_t = Tint_least32_t

type Tint_least64_t = int64

type int_least64_t = Tint_least64_t

type Tuint_fast8_t = uint8

type uint_fast8_t = Tuint_fast8_t

type Tuint_fast64_t = uint64

type uint_fast64_t = Tuint_fast64_t

type Tuint_least8_t = uint8

type uint_least8_t = Tuint_least8_t

type Tuint_least16_t = uint16

type uint_least16_t = Tuint_least16_t

type Tuint_least32_t = uint32

type uint_least32_t = Tuint_least32_t

type Tuint_least64_t = uint64

type uint_least64_t = Tuint_least64_t

type Tint_fast16_t = int32

type int_fast16_t = Tint_fast16_t

type Tint_fast32_t = int32

type int_fast32_t = Tint_fast32_t

type Tuint_fast16_t = uint32

type uint_fast16_t = Tuint_fast16_t

type Tuint_fast32_t = uint32

type uint_fast32_t = Tuint_fast32_t

type Twchar_t = int32

type wchar_t = Twchar_t

type Timaxdiv_t = struct {
	Fquot Tintmax_t
	Frem  Tintmax_t
}

type imaxdiv_t = Timaxdiv_t

type Tfloat_t = float32

type float_t = Tfloat_t

type Tdouble_t = float64

type double_t = Tdouble_t

type Tsize_t = uint64

type size_t = Tsize_t

type Tdiv_t = struct {
	Fquot int32
	Frem  int32
}

type div_t = Tdiv_t

type Tldiv_t = struct {
	Fquot int64
	Frem  int64
}

type ldiv_t = Tldiv_t

type Tlldiv_t = struct {
	Fquot int64
	Frem  int64
}

type lldiv_t = Tlldiv_t

type Tlocale_t = uintptr

type locale_t = Tlocale_t

type Tssize_t = int64

type ssize_t = Tssize_t

type Toff_t = int64

type off_t = Toff_t

type t__isoc_va_list = uintptr

type Tfpos_t = struct {
	F__lldata [0]int64
	F__align  [0]float64
	F__opaque [16]uint8
}

type fpos_t = Tfpos_t

type T_G_fpos64_t = Tfpos_t

type _G_fpos64_t = T_G_fpos64_t

type Tcookie_io_functions_t = struct {
	Fread   uintptr
	Fwrite  uintptr
	Fseek   uintptr
	Fclose1 uintptr
}

type cookie_io_functions_t = Tcookie_io_functions_t

type T_IO_cookie_io_functions_t = Tcookie_io_functions_t

type _IO_cookie_io_functions_t = T_IO_cookie_io_functions_t

/*
** 2001-09-15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.  If a C-function, structure, datatype,
** or constant definition does not appear in this file, then it is
** not a published API of SQLite, is subject to change without
** notice, and should not be referenced by programs that use SQLite.
**
** Some of the definitions that are in this file are marked as
** "experimental".  Experimental interfaces are normally new
** features recently added to SQLite.  We do not anticipate changes
** to experimental interfaces but reserve the right to make minor changes
** if experience from use "in the wild" suggest such changes are prudent.
**
** The official C-language API documentation for SQLite is derived
** from comments in this file.  This file is the authoritative source
** on how SQLite interfaces are supposed to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
 */

type Ti8 = int8

type i8 = Ti8

type Tu8 = uint8

type u8 = Tu8

type Ti16 = int16

type i16 = Ti16

type Ti32 = int32

type i32 = Ti32

type Ti64 = int64

type i64 = Ti64

type Tu32 = uint32

type u32 = Tu32

type Tu64 = uint64

type u64 = Tu64

type Tf32 = float32

type f32 = Tf32

type Tusize = uint64

type usize = Tusize

// sqlite3_vtab_in() was added in SQLite version 3.38 (2022-02-22)
// https://www.sqlite.org/changes.html#version_3_38_0

type _VectorElementType = int32

const
// clang-format off
_SQLITE_VEC_ELEMENT_TYPE_FLOAT32 = 223
const _SQLITE_VEC_ELEMENT_TYPE_BIT = 224
const _SQLITE_VEC_ELEMENT_TYPE_INT8 = 225

func _l2_sqr_float(tls *libc.TLS, pVect1v uintptr, pVect2v uintptr, qty_ptr uintptr) (r Tf32) {
	var i, qty Tsize_t
	var pVect1, pVect2 uintptr
	var res, t Tf32
	_, _, _, _, _, _ = i, pVect1, pVect2, qty, res, t
	pVect1 = pVect1v
	pVect2 = pVect2v
	qty = *(*Tsize_t)(unsafe.Pointer(qty_ptr))
	res = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < qty) {
			break
		}
		t = *(*Tf32)(unsafe.Pointer(pVect1)) - *(*Tf32)(unsafe.Pointer(pVect2))
		pVect1 += 4
		pVect2 += 4
		res = res + Tf32(t*t)
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Xsqrt(tls, float64(res)))
}

func _l2_sqr_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Tf32) {
	var a, b uintptr
	var d, i Tsize_t
	var res, t Tf32
	_, _, _, _, _, _ = a, b, d, i, res, t
	a = pA
	b = pB
	d = *(*Tsize_t)(unsafe.Pointer(pD))
	res = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < d) {
			break
		}
		t = float32(int32(*(*Ti8)(unsafe.Pointer(a))) - int32(*(*Ti8)(unsafe.Pointer(b))))
		a = a + 1
		b = b + 1
		res = res + Tf32(t*t)
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Xsqrt(tls, float64(res)))
}

func _distance_l2_sqr_float(tls *libc.TLS, a uintptr, b uintptr, d uintptr) (r Tf32) {
	return _l2_sqr_float(tls, a, b, d)
}

func _distance_l2_sqr_int8(tls *libc.TLS, a uintptr, b uintptr, d uintptr) (r Tf32) {
	return _l2_sqr_int8(tls, a, b, d)
}

func _l1_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Ti32) {
	var a, b uintptr
	var d, i Tsize_t
	var res Ti32
	_, _, _, _, _ = a, b, d, i, res
	a = pA
	b = pB
	d = *(*Tsize_t)(unsafe.Pointer(pD))
	res = 0
	i = uint64(0)
	for {
		if !(i < d) {
			break
		}
		res = res + libc.Xabs(tls, int32(*(*Ti8)(unsafe.Pointer(a)))-int32(*(*Ti8)(unsafe.Pointer(b))))
		a = a + 1
		b = b + 1
		goto _1
	_1:
		;
		i = i + 1
	}
	return res
}

func _distance_l1_int8(tls *libc.TLS, a uintptr, b uintptr, d uintptr) (r Ti32) {
	return _l1_int8(tls, a, b, d)
}

func _l1_f32(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r float64) {
	var a, b uintptr
	var d, i Tsize_t
	var res float64
	_, _, _, _, _ = a, b, d, i, res
	a = pA
	b = pB
	d = *(*Tsize_t)(unsafe.Pointer(pD))
	res = libc.Float64FromInt32(0)
	i = uint64(0)
	for {
		if !(i < d) {
			break
		}
		res = res + libc.Xfabs(tls, float64(*(*Tf32)(unsafe.Pointer(a)))-float64(*(*Tf32)(unsafe.Pointer(b))))
		a += 4
		b += 4
		goto _1
	_1:
		;
		i = i + 1
	}
	return res
}

func _distance_l1_f32(tls *libc.TLS, a uintptr, b uintptr, d uintptr) (r float64) {
	return _l1_f32(tls, a, b, d)
}

func _distance_cosine_float(tls *libc.TLS, pVect1v uintptr, pVect2v uintptr, qty_ptr uintptr) (r Tf32) {
	var aMag, bMag, dot Tf32
	var i, qty Tsize_t
	var pVect1, pVect2 uintptr
	_, _, _, _, _, _, _ = aMag, bMag, dot, i, pVect1, pVect2, qty
	pVect1 = pVect1v
	pVect2 = pVect2v
	qty = *(*Tsize_t)(unsafe.Pointer(qty_ptr))
	dot = libc.Float32FromInt32(0)
	aMag = libc.Float32FromInt32(0)
	bMag = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < qty) {
			break
		}
		dot = dot + Tf32(*(*Tf32)(unsafe.Pointer(pVect1))**(*Tf32)(unsafe.Pointer(pVect2)))
		aMag = aMag + Tf32(*(*Tf32)(unsafe.Pointer(pVect1))**(*Tf32)(unsafe.Pointer(pVect1)))
		bMag = bMag + Tf32(*(*Tf32)(unsafe.Pointer(pVect2))**(*Tf32)(unsafe.Pointer(pVect2)))
		pVect1 += 4
		pVect2 += 4
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Float64FromInt32(1) - float64(dot)/float64(libc.Xsqrt(tls, float64(aMag))*libc.Xsqrt(tls, float64(bMag))))
}

func _distance_cosine_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Tf32) {
	var a, b uintptr
	var aMag, bMag, dot Tf32
	var d, i Tsize_t
	_, _, _, _, _, _, _ = a, aMag, b, bMag, d, dot, i
	a = pA
	b = pB
	d = *(*Tsize_t)(unsafe.Pointer(pD))
	dot = libc.Float32FromInt32(0)
	aMag = libc.Float32FromInt32(0)
	bMag = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < d) {
			break
		}
		dot = dot + Tf32(int32(*(*Ti8)(unsafe.Pointer(a)))*int32(*(*Ti8)(unsafe.Pointer(b))))
		aMag = aMag + Tf32(int32(*(*Ti8)(unsafe.Pointer(a)))*int32(*(*Ti8)(unsafe.Pointer(a))))
		bMag = bMag + Tf32(int32(*(*Ti8)(unsafe.Pointer(b)))*int32(*(*Ti8)(unsafe.Pointer(b))))
		a = a + 1
		b = b + 1
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Float64FromInt32(1) - float64(dot)/float64(libc.Xsqrt(tls, float64(aMag))*libc.Xsqrt(tls, float64(bMag))))
}

// C documentation
//
//	// https://github.com/facebookresearch/faiss/blob/77e2e79cd0a680adc343b9840dd865da724c579e/faiss/utils/hamming_distance/common.h#L34
var _hamdist_table = [256]Tu8{
	1:   uint8(1),
	2:   uint8(1),
	3:   uint8(2),
	4:   uint8(1),
	5:   uint8(2),
	6:   uint8(2),
	7:   uint8(3),
	8:   uint8(1),
	9:   uint8(2),
	10:  uint8(2),
	11:  uint8(3),
	12:  uint8(2),
	13:  uint8(3),
	14:  uint8(3),
	15:  uint8(4),
	16:  uint8(1),
	17:  uint8(2),
	18:  uint8(2),
	19:  uint8(3),
	20:  uint8(2),
	21:  uint8(3),
	22:  uint8(3),
	23:  uint8(4),
	24:  uint8(2),
	25:  uint8(3),
	26:  uint8(3),
	27:  uint8(4),
	28:  uint8(3),
	29:  uint8(4),
	30:  uint8(4),
	31:  uint8(5),
	32:  uint8(1),
	33:  uint8(2),
	34:  uint8(2),
	35:  uint8(3),
	36:  uint8(2),
	37:  uint8(3),
	38:  uint8(3),
	39:  uint8(4),
	40:  uint8(2),
	41:  uint8(3),
	42:  uint8(3),
	43:  uint8(4),
	44:  uint8(3),
	45:  uint8(4),
	46:  uint8(4),
	47:  uint8(5),
	48:  uint8(2),
	49:  uint8(3),
	50:  uint8(3),
	51:  uint8(4),
	52:  uint8(3),
	53:  uint8(4),
	54:  uint8(4),
	55:  uint8(5),
	56:  uint8(3),
	57:  uint8(4),
	58:  uint8(4),
	59:  uint8(5),
	60:  uint8(4),
	61:  uint8(5),
	62:  uint8(5),
	63:  uint8(6),
	64:  uint8(1),
	65:  uint8(2),
	66:  uint8(2),
	67:  uint8(3),
	68:  uint8(2),
	69:  uint8(3),
	70:  uint8(3),
	71:  uint8(4),
	72:  uint8(2),
	73:  uint8(3),
	74:  uint8(3),
	75:  uint8(4),
	76:  uint8(3),
	77:  uint8(4),
	78:  uint8(4),
	79:  uint8(5),
	80:  uint8(2),
	81:  uint8(3),
	82:  uint8(3),
	83:  uint8(4),
	84:  uint8(3),
	85:  uint8(4),
	86:  uint8(4),
	87:  uint8(5),
	88:  uint8(3),
	89:  uint8(4),
	90:  uint8(4),
	91:  uint8(5),
	92:  uint8(4),
	93:  uint8(5),
	94:  uint8(5),
	95:  uint8(6),
	96:  uint8(2),
	97:  uint8(3),
	98:  uint8(3),
	99:  uint8(4),
	100: uint8(3),
	101: uint8(4),
	102: uint8(4),
	103: uint8(5),
	104: uint8(3),
	105: uint8(4),
	106: uint8(4),
	107: uint8(5),
	108: uint8(4),
	109: uint8(5),
	110: uint8(5),
	111: uint8(6),
	112: uint8(3),
	113: uint8(4),
	114: uint8(4),
	115: uint8(5),
	116: uint8(4),
	117: uint8(5),
	118: uint8(5),
	119: uint8(6),
	120: uint8(4),
	121: uint8(5),
	122: uint8(5),
	123: uint8(6),
	124: uint8(5),
	125: uint8(6),
	126: uint8(6),
	127: uint8(7),
	128: uint8(1),
	129: uint8(2),
	130: uint8(2),
	131: uint8(3),
	132: uint8(2),
	133: uint8(3),
	134: uint8(3),
	135: uint8(4),
	136: uint8(2),
	137: uint8(3),
	138: uint8(3),
	139: uint8(4),
	140: uint8(3),
	141: uint8(4),
	142: uint8(4),
	143: uint8(5),
	144: uint8(2),
	145: uint8(3),
	146: uint8(3),
	147: uint8(4),
	148: uint8(3),
	149: uint8(4),
	150: uint8(4),
	151: uint8(5),
	152: uint8(3),
	153: uint8(4),
	154: uint8(4),
	155: uint8(5),
	156: uint8(4),
	157: uint8(5),
	158: uint8(5),
	159: uint8(6),
	160: uint8(2),
	161: uint8(3),
	162: uint8(3),
	163: uint8(4),
	164: uint8(3),
	165: uint8(4),
	166: uint8(4),
	167: uint8(5),
	168: uint8(3),
	169: uint8(4),
	170: uint8(4),
	171: uint8(5),
	172: uint8(4),
	173: uint8(5),
	174: uint8(5),
	175: uint8(6),
	176: uint8(3),
	177: uint8(4),
	178: uint8(4),
	179: uint8(5),
	180: uint8(4),
	181: uint8(5),
	182: uint8(5),
	183: uint8(6),
	184: uint8(4),
	185: uint8(5),
	186: uint8(5),
	187: uint8(6),
	188: uint8(5),
	189: uint8(6),
	190: uint8(6),
	191: uint8(7),
	192: uint8(2),
	193: uint8(3),
	194: uint8(3),
	195: uint8(4),
	196: uint8(3),
	197: uint8(4),
	198: uint8(4),
	199: uint8(5),
	200: uint8(3),
	201: uint8(4),
	202: uint8(4),
	203: uint8(5),
	204: uint8(4),
	205: uint8(5),
	206: uint8(5),
	207: uint8(6),
	208: uint8(3),
	209: uint8(4),
	210: uint8(4),
	211: uint8(5),
	212: uint8(4),
	213: uint8(5),
	214: uint8(5),
	215: uint8(6),
	216: uint8(4),
	217: uint8(5),
	218: uint8(5),
	219: uint8(6),
	220: uint8(5),
	221: uint8(6),
	222: uint8(6),
	223: uint8(7),
	224: uint8(3),
	225: uint8(4),
	226: uint8(4),
	227: uint8(5),
	228: uint8(4),
	229: uint8(5),
	230: uint8(5),
	231: uint8(6),
	232: uint8(4),
	233: uint8(5),
	234: uint8(5),
	235: uint8(6),
	236: uint8(5),
	237: uint8(6),
	238: uint8(6),
	239: uint8(7),
	240: uint8(4),
	241: uint8(5),
	242: uint8(5),
	243: uint8(6),
	244: uint8(5),
	245: uint8(6),
	246: uint8(6),
	247: uint8(7),
	248: uint8(5),
	249: uint8(6),
	250: uint8(6),
	251: uint8(7),
	252: uint8(6),
	253: uint8(7),
	254: uint8(7),
	255: uint8(8),
}

func _distance_hamming_u8(tls *libc.TLS, a uintptr, b uintptr, n Tsize_t) (r Tf32) {
	var i uint64
	var same int32
	_, _ = i, same
	same = 0
	i = uint64(0)
	for {
		if !(i < n) {
			break
		}
		same = same + libc.Int32FromUint8(_hamdist_table[libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(a + uintptr(i))))^libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(b + uintptr(i))))])
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(same)
}

func _distance_hamming_u64(tls *libc.TLS, a uintptr, b uintptr, n Tsize_t) (r Tf32) {
	var i uint64
	var same int32
	_, _ = i, same
	same = 0
	i = uint64(0)
	for {
		if !(i < n) {
			break
		}
		same = same + libc.X__builtin_popcountl(tls, *(*Tu64)(unsafe.Pointer(a + uintptr(i)*8))^*(*Tu64)(unsafe.Pointer(b + uintptr(i)*8)))
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(same)
}

// C documentation
//
//	/**
//	 * @brief Calculate the hamming distance between two bitvectors.
//	 *
//	 * @param a - first bitvector, MUST have d dimensions
//	 * @param b - second bitvector, MUST have d dimensions
//	 * @param d - pointer to size_t, MUST be divisible by CHAR_BIT
//	 * @return f32
//	 */
func _distance_hamming(tls *libc.TLS, a uintptr, b uintptr, d uintptr) (r Tf32) {
	var dimensions Tsize_t
	_ = dimensions
	dimensions = *(*Tsize_t)(unsafe.Pointer(d))
	if dimensions%uint64(64) == uint64(0) {
		return _distance_hamming_u64(tls, a, b, dimensions/uint64(8)/uint64(m_CHAR_BIT))
	}
	return _distance_hamming_u8(tls, a, b, dimensions/uint64(m_CHAR_BIT))
}

// C documentation
//
//	// from SQLite source:
//	// https://github.com/sqlite/sqlite/blob/a509a90958ddb234d1785ed7801880ccb18b497e/src/json.c#L153
var _vecJsonIsSpaceX = [256]uint8{
	9:  uint8(1),
	10: uint8(1),
	13: uint8(1),
	32: uint8(1),
}

type Tvector_cleanup = uintptr

type vector_cleanup = Tvector_cleanup

func Xvector_cleanup_noop(tls *libc.TLS, _1 uintptr) {
	_ = _1
}

func Xvtab_set_error(tls *libc.TLS, pVTab uintptr, zFormat uintptr, va uintptr) {
	var args Tva_list
	_ = args
	libsqlite3.Xsqlite3_free(tls, (*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg)
	args = va
	(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = libsqlite3.Xsqlite3_vmprintf(tls, zFormat, args)
	_ = args
}

type TArray = struct {
	Felement_size Tsize_t
	Flength       Tsize_t
	Fcapacity     Tsize_t
	Fz            uintptr
}

type Array = TArray

// C documentation
//
//	/**
//	 * @brief Initial an array with the given element size and capacity.
//	 *
//	 * @param array
//	 * @param element_size
//	 * @param init_capacity
//	 * @return SQLITE_OK on success, error code on failure. Only error is
//	 * SQLITE_NOMEM
//	 */
func Xarray_init(tls *libc.TLS, array uintptr, element_size Tsize_t, init_capacity Tsize_t) (r int32) {
	var sz int32
	var z uintptr
	_, _ = sz, z
	sz = libc.Int32FromUint64(element_size * init_capacity)
	z = libsqlite3.Xsqlite3_malloc(tls, sz)
	if !(z != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, z, 0, libc.Uint64FromInt32(sz))
	(*TArray)(unsafe.Pointer(array)).Felement_size = element_size
	(*TArray)(unsafe.Pointer(array)).Flength = uint64(0)
	(*TArray)(unsafe.Pointer(array)).Fcapacity = init_capacity
	(*TArray)(unsafe.Pointer(array)).Fz = z
	return m_SQLITE_OK
}

func Xarray_append(tls *libc.TLS, array uintptr, element uintptr) (r int32) {
	var new_capacity Tsize_t
	var z uintptr
	_, _ = new_capacity, z
	if (*TArray)(unsafe.Pointer(array)).Flength == (*TArray)(unsafe.Pointer(array)).Fcapacity {
		new_capacity = (*TArray)(unsafe.Pointer(array)).Fcapacity*uint64(2) + uint64(100)
		z = libsqlite3.Xsqlite3_realloc64(tls, (*TArray)(unsafe.Pointer(array)).Fz, (*TArray)(unsafe.Pointer(array)).Felement_size*new_capacity)
		if z != 0 {
			(*TArray)(unsafe.Pointer(array)).Fcapacity = new_capacity
			(*TArray)(unsafe.Pointer(array)).Fz = z
		} else {
			return int32(m_SQLITE_NOMEM)
		}
	}
	libc.Xmemcpy(tls, (*TArray)(unsafe.Pointer(array)).Fz+uintptr((*TArray)(unsafe.Pointer(array)).Flength*(*TArray)(unsafe.Pointer(array)).Felement_size), element, (*TArray)(unsafe.Pointer(array)).Felement_size)
	(*TArray)(unsafe.Pointer(array)).Flength = (*TArray)(unsafe.Pointer(array)).Flength + 1
	return m_SQLITE_OK
}

func Xarray_cleanup(tls *libc.TLS, array uintptr) {
	if !(array != 0) {
		return
	}
	(*TArray)(unsafe.Pointer(array)).Felement_size = uint64(0)
	(*TArray)(unsafe.Pointer(array)).Flength = uint64(0)
	(*TArray)(unsafe.Pointer(array)).Fcapacity = uint64(0)
	libsqlite3.Xsqlite3_free(tls, (*TArray)(unsafe.Pointer(array)).Fz)
	(*TArray)(unsafe.Pointer(array)).Fz = libc.UintptrFromInt32(0)
}

func Xvector_subtype_name(tls *libc.TLS, subtype int32) (r uintptr) {
	switch subtype {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		return __ccgo_ts
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		return __ccgo_ts + 8
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		return __ccgo_ts + 13
	}
	return __ccgo_ts + 17
}

func Xtype_name(tls *libc.TLS, type1 int32) (r uintptr) {
	switch type1 {
	case int32(m_SQLITE_INTEGER):
		return __ccgo_ts + 18
	case int32(m_SQLITE_BLOB):
		return __ccgo_ts + 26
	case int32(m_SQLITE_TEXT):
		return __ccgo_ts + 31
	case int32(m_SQLITE_FLOAT):
		return __ccgo_ts + 36
	case int32(m_SQLITE_NULL):
		return __ccgo_ts + 42
	}
	return __ccgo_ts + 17
}

type Tfvec_cleanup = uintptr

type fvec_cleanup = Tfvec_cleanup

func Xfvec_cleanup_noop(tls *libc.TLS, _1 uintptr) {
	_ = _1
}

func _fvec_from_value(tls *libc.TLS, value uintptr, vector uintptr, dimensions uintptr, __ccgo_fp_cleanup uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var blob, ptr, source uintptr
	var bytes, i, offset, rc, source_len, value_type int32
	var result float64
	var _ /* endptr at bp+32 */ uintptr
	var _ /* res at bp+40 */ Tf32
	var _ /* x at bp+0 */ TArray
	_, _, _, _, _, _, _, _, _, _ = blob, bytes, i, offset, ptr, rc, result, source, source_len, value_type
	value_type = libsqlite3.Xsqlite3_value_type(tls, value)
	if value_type == int32(m_SQLITE_BLOB) {
		blob = libsqlite3.Xsqlite3_value_blob(tls, value)
		bytes = libsqlite3.Xsqlite3_value_bytes(tls, value)
		if bytes == 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
			return int32(m_SQLITE_ERROR)
		}
		if libc.Uint64FromInt32(bytes)%uint64(4) != uint64(0) {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+86, libc.VaList(bp+56, uint64(4), bytes))
			return int32(m_SQLITE_ERROR)
		}
		*(*uintptr)(unsafe.Pointer(vector)) = blob
		*(*Tsize_t)(unsafe.Pointer(dimensions)) = libc.Uint64FromInt32(bytes) / uint64(4)
		*(*Tfvec_cleanup)(unsafe.Pointer(__ccgo_fp_cleanup)) = __ccgo_fp(Xfvec_cleanup_noop)
		return m_SQLITE_OK
	}
	if value_type == int32(m_SQLITE_TEXT) {
		source = libsqlite3.Xsqlite3_value_text(tls, value)
		source_len = libsqlite3.Xsqlite3_value_bytes(tls, value)
		if source_len == 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
			return int32(m_SQLITE_ERROR)
		}
		i = 0
		rc = Xarray_init(tls, bp, uint64(4), uint64(libc.Xceil(tls, float64(source_len)/float64(2))))
		if rc != m_SQLITE_OK {
			return rc
		}
		// advance leading whitespace to first '['
		for i < source_len {
			if _vecJsonIsSpaceX[*(*uint8)(unsafe.Pointer(source + uintptr(i)))] != 0 {
				i = i + 1
				continue
			}
			if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(i)))) == int32('[') {
				break
			}
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+156, 0)
			Xarray_cleanup(tls, bp)
			return int32(m_SQLITE_ERROR)
		}
		if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(i)))) != int32('[') {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+156, 0)
			Xarray_cleanup(tls, bp)
			return int32(m_SQLITE_ERROR)
		}
		offset = i + int32(1)
		for offset < source_len {
			ptr = source + uintptr(offset)
			*(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) = 0
			result = libc.Xstrtod(tls, ptr, bp+32)
			if *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) != 0 && result == libc.Float64FromInt32(0) || *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == int32(m_ERANGE) && (result == float64(libc.X__builtin_inff(tls)) || result == -float64(libc.X__builtin_inff(tls))) {
				libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+212, 0)
				return int32(m_SQLITE_ERROR)
			}
			if *(*uintptr)(unsafe.Pointer(bp + 32)) == ptr {
				if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(ptr))) != int32(']') {
					libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
					*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+212, 0)
					return int32(m_SQLITE_ERROR)
				}
				goto done
			}
			*(*Tf32)(unsafe.Pointer(bp + 40)) = float32(result)
			Xarray_append(tls, bp, bp+40)
			offset = int32(int64(offset) + (int64(*(*uintptr)(unsafe.Pointer(bp + 32))) - int64(ptr)))
			for offset < source_len {
				if _vecJsonIsSpaceX[*(*uint8)(unsafe.Pointer(source + uintptr(offset)))] != 0 {
					offset = offset + 1
					continue
				}
				if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(offset)))) == int32(',') {
					offset = offset + 1
					continue
				}
				if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(offset)))) == int32(']') {
					goto done
				}
				break
			}
		}
		goto done
	done:
		;
		if (*(*TArray)(unsafe.Pointer(bp))).Flength > uint64(0) {
			*(*uintptr)(unsafe.Pointer(vector)) = (*(*TArray)(unsafe.Pointer(bp))).Fz
			*(*Tsize_t)(unsafe.Pointer(dimensions)) = (*(*TArray)(unsafe.Pointer(bp))).Flength
			*(*Tfvec_cleanup)(unsafe.Pointer(__ccgo_fp_cleanup)) = __ccgo_fp(libsqlite3.Xsqlite3_free)
			return m_SQLITE_OK
		}
		libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
		*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
		return int32(m_SQLITE_ERROR)
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+231, libc.VaList(bp+56, Xtype_name(tls, value_type)))
	return int32(m_SQLITE_ERROR)
}

func _bitvec_from_value(tls *libc.TLS, value uintptr, vector uintptr, dimensions uintptr, __ccgo_fp_cleanup uintptr, pzErr uintptr) (r int32) {
	var blob uintptr
	var bytes, value_type int32
	_, _, _ = blob, bytes, value_type
	value_type = libsqlite3.Xsqlite3_value_type(tls, value)
	if value_type == int32(m_SQLITE_BLOB) {
		blob = libsqlite3.Xsqlite3_value_blob(tls, value)
		bytes = libsqlite3.Xsqlite3_value_bytes(tls, value)
		if bytes == 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
			return int32(m_SQLITE_ERROR)
		}
		*(*uintptr)(unsafe.Pointer(vector)) = blob
		*(*Tsize_t)(unsafe.Pointer(dimensions)) = libc.Uint64FromInt32(bytes * int32(m_CHAR_BIT))
		*(*Tvector_cleanup)(unsafe.Pointer(__ccgo_fp_cleanup)) = __ccgo_fp(Xvector_cleanup_noop)
		return m_SQLITE_OK
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+299, 0)
	return int32(m_SQLITE_ERROR)
}

func _int8_vec_from_value(tls *libc.TLS, value uintptr, vector uintptr, dimensions uintptr, __ccgo_fp_cleanup uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var blob, ptr, source uintptr
	var bytes, i, offset, rc, source_len, value_type int32
	var result int64
	var _ /* endptr at bp+32 */ uintptr
	var _ /* res at bp+40 */ Ti8
	var _ /* x at bp+0 */ TArray
	_, _, _, _, _, _, _, _, _, _ = blob, bytes, i, offset, ptr, rc, result, source, source_len, value_type
	value_type = libsqlite3.Xsqlite3_value_type(tls, value)
	if value_type == int32(m_SQLITE_BLOB) {
		blob = libsqlite3.Xsqlite3_value_blob(tls, value)
		bytes = libsqlite3.Xsqlite3_value_bytes(tls, value)
		if bytes == 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
			return int32(m_SQLITE_ERROR)
		}
		*(*uintptr)(unsafe.Pointer(vector)) = blob
		*(*Tsize_t)(unsafe.Pointer(dimensions)) = libc.Uint64FromInt32(bytes)
		*(*Tvector_cleanup)(unsafe.Pointer(__ccgo_fp_cleanup)) = __ccgo_fp(Xvector_cleanup_noop)
		return m_SQLITE_OK
	}
	if value_type == int32(m_SQLITE_TEXT) {
		source = libsqlite3.Xsqlite3_value_text(tls, value)
		source_len = libsqlite3.Xsqlite3_value_bytes(tls, value)
		i = 0
		if source_len == 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
			return int32(m_SQLITE_ERROR)
		}
		rc = Xarray_init(tls, bp, uint64(1), uint64(libc.Xceil(tls, float64(source_len)/float64(2))))
		if rc != m_SQLITE_OK {
			return rc
		}
		// advance leading whitespace to first '['
		for i < source_len {
			if _vecJsonIsSpaceX[*(*uint8)(unsafe.Pointer(source + uintptr(i)))] != 0 {
				i = i + 1
				continue
			}
			if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(i)))) == int32('[') {
				break
			}
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+156, 0)
			Xarray_cleanup(tls, bp)
			return int32(m_SQLITE_ERROR)
		}
		if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(i)))) != int32('[') {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+156, 0)
			Xarray_cleanup(tls, bp)
			return int32(m_SQLITE_ERROR)
		}
		offset = i + int32(1)
		for offset < source_len {
			ptr = source + uintptr(offset)
			*(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) = 0
			result = libc.Xstrtol(tls, ptr, bp+32, int32(10))
			if *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) != 0 && result == 0 || *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == int32(m_ERANGE) && (result == int64(0x7fffffffffffffff) || result == -libc.Int64FromInt64(0x7fffffffffffffff)-libc.Int64FromInt32(1)) {
				libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+212, 0)
				return int32(m_SQLITE_ERROR)
			}
			if *(*uintptr)(unsafe.Pointer(bp + 32)) == ptr {
				if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(ptr))) != int32(']') {
					libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
					*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+212, 0)
					return int32(m_SQLITE_ERROR)
				}
				goto done
			}
			if result < int64(-libc.Int32FromInt32(1)-libc.Int32FromInt32(0x7f)) || result > int64(libc.Int32FromInt32(m_INT8_MAX)) {
				libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+327, 0)
				return int32(m_SQLITE_ERROR)
			}
			*(*Ti8)(unsafe.Pointer(bp + 40)) = int8(result)
			Xarray_append(tls, bp, bp+40)
			offset = int32(int64(offset) + (int64(*(*uintptr)(unsafe.Pointer(bp + 32))) - int64(ptr)))
			for offset < source_len {
				if _vecJsonIsSpaceX[*(*uint8)(unsafe.Pointer(source + uintptr(offset)))] != 0 {
					offset = offset + 1
					continue
				}
				if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(offset)))) == int32(',') {
					offset = offset + 1
					continue
				}
				if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(source + uintptr(offset)))) == int32(']') {
					goto done
				}
				break
			}
		}
		goto done
	done:
		;
		if (*(*TArray)(unsafe.Pointer(bp))).Flength > uint64(0) {
			*(*uintptr)(unsafe.Pointer(vector)) = (*(*TArray)(unsafe.Pointer(bp))).Fz
			*(*Tsize_t)(unsafe.Pointer(dimensions)) = (*(*TArray)(unsafe.Pointer(bp))).Flength
			*(*Tvector_cleanup)(unsafe.Pointer(__ccgo_fp_cleanup)) = __ccgo_fp(libsqlite3.Xsqlite3_free)
			return m_SQLITE_OK
		}
		libsqlite3.Xsqlite3_free(tls, (*(*TArray)(unsafe.Pointer(bp))).Fz)
		*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+47, 0)
		return int32(m_SQLITE_ERROR)
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+375, 0)
	return int32(m_SQLITE_ERROR)
}

type t__ccgo_fp__Xvector_from_value_4 = func(*libc.TLS, uintptr)

// C documentation
//
//	/**
//	 * @brief Extract a vector from a sqlite3_value. Can be a float32, int8, or bit
//	 * vector.
//	 *
//	 * @param value: the sqlite3_value to read from.
//	 * @param vector: Output pointer to vector data.
//	 * @param dimensions: Output number of dimensions
//	 * @param dimensions: Output vector element type
//	 * @param cleanup
//	 * @param pzErrorMessage
//	 * @return int SQLITE_OK on success, error code otherwise
//	 */
func Xvector_from_value(tls *libc.TLS, value uintptr, vector uintptr, dimensions uintptr, element_type uintptr, __ccgo_fp_cleanup uintptr, pzErrorMessage uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc, rc1, rc2, subtype int32
	_, _, _, _ = rc, rc1, rc2, subtype
	subtype = libc.Int32FromUint32(libsqlite3.Xsqlite3_value_subtype(tls, value))
	if !(subtype != 0) || subtype == int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32) || subtype == int32(m_JSON_SUBTYPE) {
		rc = _fvec_from_value(tls, value, vector, dimensions, __ccgo_fp_cleanup, pzErrorMessage)
		if rc == m_SQLITE_OK {
			*(*_VectorElementType)(unsafe.Pointer(element_type)) = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
		}
		return rc
	}
	if subtype == int32(_SQLITE_VEC_ELEMENT_TYPE_BIT) {
		rc1 = _bitvec_from_value(tls, value, vector, dimensions, __ccgo_fp_cleanup, pzErrorMessage)
		if rc1 == m_SQLITE_OK {
			*(*_VectorElementType)(unsafe.Pointer(element_type)) = int32(_SQLITE_VEC_ELEMENT_TYPE_BIT)
		}
		return rc1
	}
	if subtype == int32(_SQLITE_VEC_ELEMENT_TYPE_INT8) {
		rc2 = _int8_vec_from_value(tls, value, vector, dimensions, __ccgo_fp_cleanup, pzErrorMessage)
		if rc2 == m_SQLITE_OK {
			*(*_VectorElementType)(unsafe.Pointer(element_type)) = int32(_SQLITE_VEC_ELEMENT_TYPE_INT8)
		}
		return rc2
	}
	*(*uintptr)(unsafe.Pointer(pzErrorMessage)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+405, libc.VaList(bp+8, subtype))
	return int32(m_SQLITE_ERROR)
}

type t__ccgo_fp__Xensure_vector_match_6 = func(*libc.TLS, uintptr)

type t__ccgo_fp__Xensure_vector_match_7 = func(*libc.TLS, uintptr)

func Xensure_vector_match(tls *libc.TLS, aValue uintptr, bValue uintptr, a uintptr, b uintptr, element_type uintptr, dimensions uintptr, __ccgo_fp_outACleanup uintptr, __ccgo_fp_outBCleanup uintptr, outError uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var rc int32
	var _ /* aCleanup at bp+32 */ Tvector_cleanup
	var _ /* aDims at bp+8 */ Tsize_t
	var _ /* aType at bp+0 */ _VectorElementType
	var _ /* bCleanup at bp+40 */ Tvector_cleanup
	var _ /* bDims at bp+16 */ Tsize_t
	var _ /* bType at bp+4 */ _VectorElementType
	var _ /* error at bp+24 */ uintptr
	_ = rc
	*(*uintptr)(unsafe.Pointer(bp + 24)) = libc.UintptrFromInt32(0)
	rc = Xvector_from_value(tls, aValue, a, bp+8, bp, bp+32, bp+24)
	if rc != m_SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+425, libc.VaList(bp+56, *(*uintptr)(unsafe.Pointer(bp + 24))))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return int32(m_SQLITE_ERROR)
	}
	rc = Xvector_from_value(tls, bValue, b, bp+16, bp+4, bp+40, bp+24)
	if rc != m_SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+454, libc.VaList(bp+56, *(*uintptr)(unsafe.Pointer(bp + 24))))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, a)
		return int32(m_SQLITE_ERROR)
	}
	if *(*_VectorElementType)(unsafe.Pointer(bp)) != *(*_VectorElementType)(unsafe.Pointer(bp + 4)) {
		*(*uintptr)(unsafe.Pointer(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+483, libc.VaList(bp+56, Xvector_subtype_name(tls, *(*_VectorElementType)(unsafe.Pointer(bp))), Xvector_subtype_name(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 4)))))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(a)))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 40)))(tls, *(*uintptr)(unsafe.Pointer(b)))
		return int32(m_SQLITE_ERROR)
	}
	if *(*Tsize_t)(unsafe.Pointer(bp + 8)) != *(*Tsize_t)(unsafe.Pointer(bp + 16)) {
		*(*uintptr)(unsafe.Pointer(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+562, libc.VaList(bp+56, *(*Tsize_t)(unsafe.Pointer(bp + 8)), *(*Tsize_t)(unsafe.Pointer(bp + 16))))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(a)))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 40)))(tls, *(*uintptr)(unsafe.Pointer(b)))
		return int32(m_SQLITE_ERROR)
	}
	*(*_VectorElementType)(unsafe.Pointer(element_type)) = *(*_VectorElementType)(unsafe.Pointer(bp))
	*(*Tsize_t)(unsafe.Pointer(dimensions)) = *(*Tsize_t)(unsafe.Pointer(bp + 8))
	*(*Tvector_cleanup)(unsafe.Pointer(__ccgo_fp_outACleanup)) = *(*Tvector_cleanup)(unsafe.Pointer(bp + 32))
	*(*Tvector_cleanup)(unsafe.Pointer(__ccgo_fp_outBCleanup)) = *(*Tvector_cleanup)(unsafe.Pointer(bp + 40))
	return m_SQLITE_OK
}

func X_cmp(tls *libc.TLS, a uintptr, b uintptr) (r int32) {
	return int32(*(*Ti64)(unsafe.Pointer(a)) - *(*Ti64)(unsafe.Pointer(b)))
}

type TVecNpyFile = struct {
	Fpath       uintptr
	FpathLength Tsize_t
}

type VecNpyFile = TVecNpyFile

func _vec_npy_file(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var f, path uintptr
	var pathLength Tsize_t
	_, _, _ = f, path, pathLength
	path = libsqlite3.Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	pathLength = libc.Uint64FromInt32(libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
	f = libsqlite3.Xsqlite3_malloc(tls, int32(16))
	if !(f != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
		return
	}
	libc.Xmemset(tls, f, 0, uint64(16))
	(*TVecNpyFile)(unsafe.Pointer(f)).Fpath = path
	(*TVecNpyFile)(unsafe.Pointer(f)).FpathLength = pathLength
	libsqlite3.Xsqlite3_result_pointer(tls, context, f, __ccgo_ts+660, __ccgo_fp(libsqlite3.Xsqlite3_free))
}

func _vec_f32(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var _ /* cleanup at bp+16 */ Tfvec_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	rc = _fvec_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(bp)), libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8))*uint64(4)), *(*Tfvec_cleanup)(unsafe.Pointer(bp + 16)))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
}

func _vec_bit(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = _bitvec_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(bp)), libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8))/uint64(m_CHAR_BIT)), uintptr(-libc.Int32FromInt32(1)))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_BIT))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_int8(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = _int8_vec_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(bp)), libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8))), uintptr(-libc.Int32FromInt32(1)))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_length(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+32 */ _VectorElementType
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+32, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8))))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_distance_cosine(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var result, result1 Tf32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+24 */ Tvector_cleanup
	var _ /* b at bp+8 */ uintptr
	var _ /* bCleanup at bp+32 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+48 */ _VectorElementType
	var _ /* error at bp+40 */ uintptr
	_, _, _ = rc, result, result1
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), bp, bp+8, bp+48, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 40)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		return
	}
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 48)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+674, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		result = _distance_cosine_float(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		result1 = _distance_cosine_int8(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result1))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return
}

func _vec_distance_l2(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var result, result1 Tf32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+24 */ Tvector_cleanup
	var _ /* b at bp+8 */ uintptr
	var _ /* bCleanup at bp+32 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+48 */ _VectorElementType
	var _ /* error at bp+40 */ uintptr
	_, _, _ = rc, result, result1
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), bp, bp+8, bp+48, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 40)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		return
	}
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 48)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+731, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		result = _distance_l2_sqr_float(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		result1 = _distance_l2_sqr_int8(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result1))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return
}

func _vec_distance_l1(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var result float64
	var result1 Ti64
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+24 */ Tvector_cleanup
	var _ /* b at bp+8 */ uintptr
	var _ /* bCleanup at bp+32 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+48 */ _VectorElementType
	var _ /* error at bp+40 */ uintptr
	_, _, _ = rc, result, result1
	rc = Xensure_vector_match(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), bp, bp+8, bp+48, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 40)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		return
	}
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 48)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+784, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		result = _distance_l1_f32(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)
		libsqlite3.Xsqlite3_result_double(tls, context, result)
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		result1 = int64(_distance_l1_int8(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16))
		libsqlite3.Xsqlite3_result_int(tls, context, int32(result1))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return
}

func _vec_distance_hamming(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+24 */ Tvector_cleanup
	var _ /* b at bp+8 */ uintptr
	var _ /* bCleanup at bp+32 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+48 */ _VectorElementType
	var _ /* error at bp+40 */ uintptr
	_ = rc
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), bp, bp+8, bp+48, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 40)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		return
	}
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 48)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_double(tls, context, float64(_distance_hamming(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+837, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+900, -int32(1))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return
}

func Xvec_type_name(tls *libc.TLS, elementType _VectorElementType) (r uintptr) {
	switch elementType {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		return __ccgo_ts
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		return __ccgo_ts + 8
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		return __ccgo_ts + 13
	}
	return __ccgo_ts + 17
}

func _vec_type(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+32 */ _VectorElementType
	var _ /* pzError at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+32, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_text(tls, context, Xvec_type_name(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 32))), -int32(1), libc.UintptrFromInt32(0))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_quantize_binary(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, i1 Tsize_t
	var out, v2 uintptr
	var rc, res, res1, sz int32
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+32 */ _VectorElementType
	var _ /* pzError at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	var _ /* vectorCleanup at bp+16 */ Tvector_cleanup
	_, _, _, _, _, _, _, _ = i, i1, out, rc, res, res1, sz, v2
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+32, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	if *(*Tsize_t)(unsafe.Pointer(bp + 8)) <= uint64(0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+960, -int32(1))
		goto cleanup
		return
	}
	if *(*Tsize_t)(unsafe.Pointer(bp + 8))%uint64(m_CHAR_BIT) != uint64(0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+999, -int32(1))
		goto cleanup
		return
	}
	sz = libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8)) / uint64(m_CHAR_BIT))
	out = libsqlite3.Xsqlite3_malloc(tls, sz)
	if !(out != 0) {
		libsqlite3.Xsqlite3_result_error_code(tls, context, int32(m_SQLITE_NOMEM))
		goto cleanup
		return
	}
	libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(sz))
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 32)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		i = uint64(0)
		for {
			if !(i < *(*Tsize_t)(unsafe.Pointer(bp + 8))) {
				break
			}
			res = libc.BoolInt32(float64(*(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i)*4))) > float64(0))
			v2 = out + uintptr(i/uint64(8))
			*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) | res<<(i%libc.Uint64FromInt32(8)))
			goto _1
		_1:
			;
			i = i + 1
		}
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		i1 = uint64(0)
		for {
			if !(i1 < *(*Tsize_t)(unsafe.Pointer(bp + 8))) {
				break
			}
			res1 = libc.BoolInt32(int32(*(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i1)))) > 0)
			v2 = out + uintptr(i1/uint64(8))
			*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) | res1<<(i1%libc.Uint64FromInt32(8)))
			goto _3
		_3:
			;
			i1 = i1 + 1
		}
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1065, -int32(1))
		libsqlite3.Xsqlite3_free(tls, out)
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, out, sz, __ccgo_fp(libsqlite3.Xsqlite3_free))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_BIT))
	goto cleanup
cleanup:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_quantize_int8(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i Tsize_t
	var out uintptr
	var rc, sz int32
	var step Tf32
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* err at bp+24 */ uintptr
	var _ /* srcCleanup at bp+16 */ Tfvec_cleanup
	var _ /* srcVector at bp+0 */ uintptr
	_, _, _, _, _ = i, out, rc, step, sz
	out = libc.UintptrFromInt32(0)
	rc = _fvec_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	sz = libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8)) * uint64(1))
	out = libsqlite3.Xsqlite3_malloc(tls, sz)
	if !(out != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
		goto cleanup
	}
	libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(sz))
	if libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) != int32(m_SQLITE_TEXT) || libc.Uint64FromInt32(libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))) != libc.Xstrlen(tls, __ccgo_ts+1112) || libsqlite3.Xsqlite3_stricmp(tls, libsqlite3.Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))), __ccgo_ts+1112) != 0 {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1117, -int32(1))
		libsqlite3.Xsqlite3_free(tls, out)
		goto cleanup
	}
	step = float32((float64(1) - -libc.Float64FromFloat64(1)) / libc.Float64FromInt32(255))
	i = uint64(0)
	for {
		if !(i < *(*Tsize_t)(unsafe.Pointer(bp + 8))) {
			break
		}
		*(*Ti8)(unsafe.Pointer(out + uintptr(i))) = int8((float64(*(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i)*4))) - -libc.Float64FromFloat64(1))/float64(step) - libc.Float64FromInt32(128))
		goto _1
	_1:
		;
		i = i + 1
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8))*uint64(1)), __ccgo_fp(libsqlite3.Xsqlite3_free))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
	goto cleanup
cleanup:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_add(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i, i1, outSize, outSize1 Tsize_t
	var out, out1 uintptr
	var rc int32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+24 */ Tvector_cleanup
	var _ /* b at bp+8 */ uintptr
	var _ /* bCleanup at bp+32 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+48 */ _VectorElementType
	var _ /* error at bp+40 */ uintptr
	_, _, _, _, _, _, _ = i, i1, out, out1, outSize, outSize1, rc
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), bp, bp+8, bp+48, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 40)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		return
	}
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 48)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1169, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		outSize = *(*Tsize_t)(unsafe.Pointer(bp + 16)) * uint64(4)
		out = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(outSize))
		if !(out != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out, 0, outSize)
		i = uint64(0)
		for {
			if !(i < *(*Tsize_t)(unsafe.Pointer(bp + 16))) {
				break
			}
			*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i)*4)) + *(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i)*4))
			goto _1
		_1:
			;
			i = i + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint64(outSize), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		outSize1 = *(*Tsize_t)(unsafe.Pointer(bp + 16)) * uint64(1)
		out1 = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(outSize1))
		if !(out1 != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out1, 0, outSize1)
		i1 = uint64(0)
		for {
			if !(i1 < *(*Tsize_t)(unsafe.Pointer(bp + 16))) {
				break
			}
			*(*Ti8)(unsafe.Pointer(out1 + uintptr(i1))) = int8(int32(*(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i1)))) + int32(*(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i1)))))
			goto _2
		_2:
			;
			i1 = i1 + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out1, libc.Int32FromUint64(outSize1), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return
}

func _vec_sub(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i, i1, outSize, outSize1 Tsize_t
	var out, out1 uintptr
	var rc int32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+24 */ Tvector_cleanup
	var _ /* b at bp+8 */ uintptr
	var _ /* bCleanup at bp+32 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+48 */ _VectorElementType
	var _ /* error at bp+40 */ uintptr
	_, _, _, _, _, _, _ = i, i1, out, out1, outSize, outSize1, rc
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), bp, bp+8, bp+48, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 40)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		return
	}
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 48)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1205, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		outSize = *(*Tsize_t)(unsafe.Pointer(bp + 16)) * uint64(4)
		out = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(outSize))
		if !(out != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out, 0, outSize)
		i = uint64(0)
		for {
			if !(i < *(*Tsize_t)(unsafe.Pointer(bp + 16))) {
				break
			}
			*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i)*4)) - *(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i)*4))
			goto _1
		_1:
			;
			i = i + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint64(outSize), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		outSize1 = *(*Tsize_t)(unsafe.Pointer(bp + 16)) * uint64(1)
		out1 = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(outSize1))
		if !(out1 != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out1, 0, outSize1)
		i1 = uint64(0)
		for {
			if !(i1 < *(*Tsize_t)(unsafe.Pointer(bp + 16))) {
				break
			}
			*(*Ti8)(unsafe.Pointer(out1 + uintptr(i1))) = int8(int32(*(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i1)))) - int32(*(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i1)))))
			goto _2
		_2:
			;
			i1 = i1 + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out1, libc.Int32FromUint64(outSize1), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return
}

func _vec_slice(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var end, outSize, outSize1, outSize2, rc, start int32
	var i, i1, i2, n Tsize_t
	var out, out1, out2 uintptr
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+32 */ _VectorElementType
	var _ /* err at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = end, i, i1, i2, n, out, out1, out2, outSize, outSize1, outSize2, rc, start
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+32, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	start = libsqlite3.Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	end = libsqlite3.Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
	if start < 0 {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1246, -int32(1))
		goto done
	}
	if end < 0 {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1292, -int32(1))
		goto done
	}
	if libc.Uint64FromInt32(start) > *(*Tsize_t)(unsafe.Pointer(bp + 8)) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1336, -int32(1))
		goto done
	}
	if libc.Uint64FromInt32(end) > *(*Tsize_t)(unsafe.Pointer(bp + 8)) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1397, -int32(1))
		goto done
	}
	if start > end {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1456, -int32(1))
		goto done
	}
	if start == end {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1504, -int32(1))
		goto done
	}
	n = libc.Uint64FromInt32(end - start)
	switch *(*_VectorElementType)(unsafe.Pointer(bp + 32)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		outSize = libc.Int32FromUint64(n * uint64(4))
		out = libsqlite3.Xsqlite3_malloc(tls, outSize)
		if !(out != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto done
		}
		libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(outSize))
		i = uint64(0)
		for {
			if !(i < n) {
				break
			}
			*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(libc.Uint64FromInt32(start)+i)*4))
			goto _1
		_1:
			;
			i = i + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out, outSize, __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
		goto done
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		outSize1 = libc.Int32FromUint64(n * uint64(1))
		out1 = libsqlite3.Xsqlite3_malloc(tls, outSize1)
		if !(out1 != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			return
		}
		libc.Xmemset(tls, out1, 0, libc.Uint64FromInt32(outSize1))
		i1 = uint64(0)
		for {
			if !(i1 < n) {
				break
			}
			*(*Ti8)(unsafe.Pointer(out1 + uintptr(i1))) = *(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(libc.Uint64FromInt32(start)+i1)))
			goto _2
		_2:
			;
			i1 = i1 + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out1, outSize1, __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
		goto done
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		if start%int32(m_CHAR_BIT) != 0 {
			libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1587, -int32(1))
			goto done
		}
		if end%int32(m_CHAR_BIT) != 0 {
			libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1623, -int32(1))
			goto done
		}
		outSize2 = libc.Int32FromUint64(n / uint64(m_CHAR_BIT))
		out2 = libsqlite3.Xsqlite3_malloc(tls, outSize2)
		if !(out2 != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			return
		}
		libc.Xmemset(tls, out2, 0, libc.Uint64FromInt32(outSize2))
		i2 = uint64(0)
		for {
			if !(i2 < n/uint64(m_CHAR_BIT)) {
				break
			}
			*(*Tu8)(unsafe.Pointer(out2 + uintptr(i2))) = *(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(libc.Uint64FromInt32(start/libc.Int32FromInt32(m_CHAR_BIT))+i2)))
			goto _3
		_3:
			;
			i2 = i2 + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out2, outSize2, __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_BIT))
		goto done
	}
	goto done
done:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func _vec_to_json(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var b Tu8
	var i Tsize_t
	var len1, rc int32
	var s, str uintptr
	var value Tf32
	var v2 uint32
	var _ /* __u at bp+0 */ struct {
		F__i [0]uint32
		F__f float32
	}
	var _ /* cleanup at bp+24 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+40 */ _VectorElementType
	var _ /* err at bp+32 */ uintptr
	var _ /* vector at bp+8 */ uintptr
	_, _, _, _, _, _, _, _ = b, i, len1, rc, s, str, value, v2
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp+8, bp+16, bp+40, bp+24, bp+32)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 32)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 32)))
		return
	}
	str = libsqlite3.Xsqlite3_str_new(tls, libsqlite3.Xsqlite3_context_db_handle(tls, context))
	libsqlite3.Xsqlite3_str_appendall(tls, str, __ccgo_ts+1657)
	i = uint64(0)
	for {
		if !(i < *(*Tsize_t)(unsafe.Pointer(bp + 16))) {
			break
		}
		if i != uint64(0) {
			libsqlite3.Xsqlite3_str_appendall(tls, str, __ccgo_ts+1659)
		}
		if *(*_VectorElementType)(unsafe.Pointer(bp + 40)) == int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32) {
			value = *(*Tf32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i)*4))
			*(*float32)(unsafe.Pointer(bp)) = value
			v2 = *(*uint32)(unsafe.Pointer(bp))
			goto _3
		_3:
			if libc.BoolInt32(v2&uint32(0x7fffffff) > uint32(0x7f800000)) != 0 {
				libsqlite3.Xsqlite3_str_appendall(tls, str, __ccgo_ts+1661)
			} else {
				libsqlite3.Xsqlite3_str_appendf(tls, str, __ccgo_ts+1666, libc.VaList(bp+56, float64(value)))
			}
		} else {
			if *(*_VectorElementType)(unsafe.Pointer(bp + 40)) == int32(_SQLITE_VEC_ELEMENT_TYPE_INT8) {
				libsqlite3.Xsqlite3_str_appendf(tls, str, __ccgo_ts+1669, libc.VaList(bp+56, int32(*(*Ti8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i))))))
			} else {
				if *(*_VectorElementType)(unsafe.Pointer(bp + 40)) == int32(_SQLITE_VEC_ELEMENT_TYPE_BIT) {
					b = libc.Uint8FromInt32(libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i/uint64(8))))) >> (i % uint64(m_CHAR_BIT)) & int32(1))
					libsqlite3.Xsqlite3_str_appendf(tls, str, __ccgo_ts+1669, libc.VaList(bp+56, libc.Int32FromUint8(b)))
				}
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	libsqlite3.Xsqlite3_str_appendall(tls, str, __ccgo_ts+1672)
	len1 = libsqlite3.Xsqlite3_str_length(tls, str)
	s = libsqlite3.Xsqlite3_str_finish(tls, str)
	if s != 0 {
		libsqlite3.Xsqlite3_result_text(tls, context, s, len1, __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(m_JSON_SUBTYPE))
	} else {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
	}
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
}

func _vec_normalize(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, i1 Tsize_t
	var norm Tf32
	var out, v uintptr
	var outSize, rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+32 */ _VectorElementType
	var _ /* err at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_, _, _, _, _, _, _ = i, i1, norm, out, outSize, rc, v
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+32, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		return
	}
	if *(*_VectorElementType)(unsafe.Pointer(bp + 32)) != int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1674, -int32(1))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return
	}
	outSize = libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8)) * uint64(4))
	out = libsqlite3.Xsqlite3_malloc(tls, outSize)
	if !(out != 0) {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
		libsqlite3.Xsqlite3_result_error_code(tls, context, int32(m_SQLITE_NOMEM))
		return
	}
	libc.Xmemset(tls, out, 0, libc.Uint64FromInt32(outSize))
	v = *(*uintptr)(unsafe.Pointer(bp))
	norm = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < *(*Tsize_t)(unsafe.Pointer(bp + 8))) {
			break
		}
		norm = norm + Tf32(*(*Tf32)(unsafe.Pointer(v + uintptr(i)*4))**(*Tf32)(unsafe.Pointer(v + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	norm = float32(libc.Xsqrt(tls, float64(norm)))
	i1 = uint64(0)
	for {
		if !(i1 < *(*Tsize_t)(unsafe.Pointer(bp + 8))) {
			break
		}
		*(*Tf32)(unsafe.Pointer(out + uintptr(i1)*4)) = *(*Tf32)(unsafe.Pointer(v + uintptr(i1)*4)) / norm
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 8))*uint64(4)), __ccgo_fp(libsqlite3.Xsqlite3_free))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func __static_text_func(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argc
	_ = argv
	libsqlite3.Xsqlite3_result_text(tls, context, libsqlite3.Xsqlite3_user_data(tls, context), -int32(1), libc.UintptrFromInt32(0))
}

type _Vec0TokenType = int32

const _TOKEN_TYPE_IDENTIFIER = 0
const _TOKEN_TYPE_DIGIT = 1
const _TOKEN_TYPE_LBRACKET = 2
const _TOKEN_TYPE_RBRACKET = 3
const _TOKEN_TYPE_PLUS = 4
const _TOKEN_TYPE_EQ = 5

type TVec0Token = struct {
	Ftoken_type _Vec0TokenType
	Fstart      uintptr
	Fend        uintptr
}

type Vec0Token = TVec0Token

func Xis_alpha(tls *libc.TLS, x uint8) (r int32) {
	return libc.BoolInt32(libc.Int32FromUint8(x) >= int32('a') && libc.Int32FromUint8(x) <= int32('z') || libc.Int32FromUint8(x) >= int32('A') && libc.Int32FromUint8(x) <= int32('Z'))
}

func Xis_digit(tls *libc.TLS, x uint8) (r int32) {
	return libc.BoolInt32(libc.Int32FromUint8(x) >= int32('0') && libc.Int32FromUint8(x) <= int32('9'))
}

func Xis_whitespace(tls *libc.TLS, x uint8) (r int32) {
	return libc.BoolInt32(libc.Int32FromUint8(x) == int32(' ') || libc.Int32FromUint8(x) == int32('\t') || libc.Int32FromUint8(x) == int32('\n') || libc.Int32FromUint8(x) == int32('\r'))
}

func Xvec0_token_next(tls *libc.TLS, start uintptr, end uintptr, out uintptr) (r int32) {
	var curr uint8
	var ptr, start1, start2 uintptr
	_, _, _, _ = curr, ptr, start1, start2
	ptr = start
	for ptr < end {
		curr = *(*uint8)(unsafe.Pointer(ptr))
		if Xis_whitespace(tls, curr) != 0 {
			ptr = ptr + 1
			continue
		} else {
			if libc.Int32FromUint8(curr) == int32('+') {
				ptr = ptr + 1
				(*TVec0Token)(unsafe.Pointer(out)).Fstart = ptr
				(*TVec0Token)(unsafe.Pointer(out)).Fend = ptr
				(*TVec0Token)(unsafe.Pointer(out)).Ftoken_type = int32(_TOKEN_TYPE_PLUS)
				return int32(m_VEC0_TOKEN_RESULT_SOME)
			} else {
				if libc.Int32FromUint8(curr) == int32('[') {
					ptr = ptr + 1
					(*TVec0Token)(unsafe.Pointer(out)).Fstart = ptr
					(*TVec0Token)(unsafe.Pointer(out)).Fend = ptr
					(*TVec0Token)(unsafe.Pointer(out)).Ftoken_type = int32(_TOKEN_TYPE_LBRACKET)
					return int32(m_VEC0_TOKEN_RESULT_SOME)
				} else {
					if libc.Int32FromUint8(curr) == int32(']') {
						ptr = ptr + 1
						(*TVec0Token)(unsafe.Pointer(out)).Fstart = ptr
						(*TVec0Token)(unsafe.Pointer(out)).Fend = ptr
						(*TVec0Token)(unsafe.Pointer(out)).Ftoken_type = int32(_TOKEN_TYPE_RBRACKET)
						return int32(m_VEC0_TOKEN_RESULT_SOME)
					} else {
						if libc.Int32FromUint8(curr) == int32('=') {
							ptr = ptr + 1
							(*TVec0Token)(unsafe.Pointer(out)).Fstart = ptr
							(*TVec0Token)(unsafe.Pointer(out)).Fend = ptr
							(*TVec0Token)(unsafe.Pointer(out)).Ftoken_type = int32(_TOKEN_TYPE_EQ)
							return int32(m_VEC0_TOKEN_RESULT_SOME)
						} else {
							if Xis_alpha(tls, curr) != 0 {
								start1 = ptr
								for ptr < end && (Xis_alpha(tls, *(*uint8)(unsafe.Pointer(ptr))) != 0 || Xis_digit(tls, *(*uint8)(unsafe.Pointer(ptr))) != 0 || libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(ptr))) == int32('_')) {
									ptr = ptr + 1
								}
								(*TVec0Token)(unsafe.Pointer(out)).Fstart = start1
								(*TVec0Token)(unsafe.Pointer(out)).Fend = ptr
								(*TVec0Token)(unsafe.Pointer(out)).Ftoken_type = int32(_TOKEN_TYPE_IDENTIFIER)
								return int32(m_VEC0_TOKEN_RESULT_SOME)
							} else {
								if Xis_digit(tls, curr) != 0 {
									start2 = ptr
									for ptr < end && Xis_digit(tls, *(*uint8)(unsafe.Pointer(ptr))) != 0 {
										ptr = ptr + 1
									}
									(*TVec0Token)(unsafe.Pointer(out)).Fstart = start2
									(*TVec0Token)(unsafe.Pointer(out)).Fend = ptr
									(*TVec0Token)(unsafe.Pointer(out)).Ftoken_type = int32(_TOKEN_TYPE_DIGIT)
									return int32(m_VEC0_TOKEN_RESULT_SOME)
								} else {
									return int32(m_VEC0_TOKEN_RESULT_ERROR)
								}
							}
						}
					}
				}
			}
		}
	}
	return int32(m_VEC0_TOKEN_RESULT_EOF)
}

type TVec0Scanner = struct {
	Fstart uintptr
	Fend   uintptr
	Fptr   uintptr
}

type Vec0Scanner = TVec0Scanner

func Xvec0_scanner_init(tls *libc.TLS, scanner uintptr, source uintptr, source_length int32) {
	(*TVec0Scanner)(unsafe.Pointer(scanner)).Fstart = source
	(*TVec0Scanner)(unsafe.Pointer(scanner)).Fend = source + uintptr(source_length)
	(*TVec0Scanner)(unsafe.Pointer(scanner)).Fptr = source
}

func Xvec0_scanner_next(tls *libc.TLS, scanner uintptr, out uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = Xvec0_token_next(tls, (*TVec0Scanner)(unsafe.Pointer(scanner)).Fstart, (*TVec0Scanner)(unsafe.Pointer(scanner)).Fend, out)
	if rc == int32(m_VEC0_TOKEN_RESULT_SOME) {
		(*TVec0Scanner)(unsafe.Pointer(scanner)).Fstart = (*TVec0Token)(unsafe.Pointer(out)).Fend
	}
	return rc
}

func Xvec0_parse_table_option(tls *libc.TLS, source uintptr, source_length int32, out_key uintptr, out_key_length uintptr, out_value uintptr, out_value_length uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var key, value uintptr
	var keyLength, rc, valueLength int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _, _ = key, keyLength, rc, value, valueLength
	Xvec0_scanner_init(tls, bp, source, source_length)
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	key = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	keyLength = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_EQ) {
		return int32(m_SQLITE_EMPTY)
	}
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && !((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type == int32(_TOKEN_TYPE_IDENTIFIER) || (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type == int32(_TOKEN_TYPE_DIGIT)) {
		return int32(m_SQLITE_ERROR)
	}
	value = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	valueLength = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc == int32(m_VEC0_TOKEN_RESULT_EOF) {
		*(*uintptr)(unsafe.Pointer(out_key)) = key
		*(*int32)(unsafe.Pointer(out_key_length)) = keyLength
		*(*uintptr)(unsafe.Pointer(out_value)) = value
		*(*int32)(unsafe.Pointer(out_value_length)) = valueLength
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's a PARTITION KEY definition.
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a partition key, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: SQLITE_TEXT or SQLITE_INTEGER.
//	 * @return int: SQLITE_EMPTY if not a PK, SQLITE_OK if it is.
//	 */
func Xvec0_parse_partition_key_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var column_name uintptr
	var column_name_length, column_type, rc int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _ = column_name, column_name_length, column_type, rc
	Xvec0_scanner_init(tls, bp, source, source_length)
	// Check first token is identifier, will be the column name
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	column_name = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	column_name_length = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	// Check the next token matches "text" or "integer", as column type
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1726, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
		column_type = int32(m_SQLITE_TEXT)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1731, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1735, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
			column_type = int32(m_SQLITE_INTEGER)
		} else {
			return int32(m_SQLITE_EMPTY)
		}
	}
	// Check the next token is identifier and matches "partition"
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1743, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	// Check the next token is identifier and matches "key"
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1753, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	*(*uintptr)(unsafe.Pointer(out_column_name)) = column_name
	*(*int32)(unsafe.Pointer(out_column_name_length)) = column_name_length
	*(*int32)(unsafe.Pointer(out_column_type)) = column_type
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's an auxiliar column definition, ie `+[name] [type]` like `+contents text`
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a partition key, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: SQLITE_TEXT, SQLITE_INTEGER, SQLITE_FLOAT, or SQLITE_BLOB.
//	 * @return int: SQLITE_EMPTY if not an aux column, SQLITE_OK if it is.
//	 */
func Xvec0_parse_auxiliary_column_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var column_name uintptr
	var column_name_length, column_type, rc int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _ = column_name, column_name_length, column_type, rc
	Xvec0_scanner_init(tls, bp, source, source_length)
	// Check first token is '+', which denotes aux columns
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_PLUS) {
		return int32(m_SQLITE_EMPTY)
	}
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	column_name = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	column_name_length = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	// Check the next token matches "text" or "integer", as column type
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1726, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
		column_type = int32(m_SQLITE_TEXT)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1731, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1735, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
			column_type = int32(m_SQLITE_INTEGER)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1757, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1763, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
				column_type = int32(m_SQLITE_FLOAT)
			} else {
				if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1770, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
					column_type = int32(m_SQLITE_BLOB)
				} else {
					return int32(m_SQLITE_EMPTY)
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(out_column_name)) = column_name
	*(*int32)(unsafe.Pointer(out_column_name_length)) = column_name_length
	*(*int32)(unsafe.Pointer(out_column_type)) = column_type
	return m_SQLITE_OK
}

type Tvec0_metadata_column_kind = int32

type vec0_metadata_column_kind = Tvec0_metadata_column_kind

const _VEC0_METADATA_COLUMN_KIND_BOOLEAN = 0
const _VEC0_METADATA_COLUMN_KIND_INTEGER = 1
const _VEC0_METADATA_COLUMN_KIND_FLOAT = 2
const _VEC0_METADATA_COLUMN_KIND_TEXT = 3

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's an metadata column definition, ie `[name] [type]` like `is_released boolean`
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a metadata column, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: one of vec0_metadata_column_kind
//	 * @return int: SQLITE_EMPTY if not an metadata column, SQLITE_OK if it is.
//	 */
func Xvec0_parse_metadata_column_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var column_name, t uintptr
	var column_name_length, n, rc int32
	var column_type Tvec0_metadata_column_kind
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _, _, _ = column_name, column_name_length, column_type, n, rc, t
	Xvec0_scanner_init(tls, bp, source, source_length)
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	column_name = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	column_name_length = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	// Check the next token matches a valid metadata type
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	t = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	n = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1775, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1783, n) == 0 {
		column_type = int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1788, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1794, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1735, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1731, n) == 0 {
			column_type = int32(_VEC0_METADATA_COLUMN_KIND_INTEGER)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1757, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1763, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1804, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1812, n) == 0 {
				column_type = int32(_VEC0_METADATA_COLUMN_KIND_FLOAT)
			} else {
				if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1726, n) == 0 {
					column_type = int32(_VEC0_METADATA_COLUMN_KIND_TEXT)
				} else {
					return int32(m_SQLITE_EMPTY)
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(out_column_name)) = column_name
	*(*int32)(unsafe.Pointer(out_column_name_length)) = column_name_length
	*(*Tvec0_metadata_column_kind)(unsafe.Pointer(out_column_type)) = column_type
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's a PRIMARY KEY definition.
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a PK, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: SQLITE_TEXT or SQLITE_INTEGER.
//	 * @return int: SQLITE_EMPTY if not a PK, SQLITE_OK if it is.
//	 */
func Xvec0_parse_primary_key_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var column_name uintptr
	var column_name_length, column_type, rc int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _ = column_name, column_name_length, column_type, rc
	Xvec0_scanner_init(tls, bp, source, source_length)
	// Check first token is identifier, will be the column name
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	column_name = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	column_name_length = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	// Check the next token matches "text" or "integer", as column type
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1726, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
		column_type = int32(m_SQLITE_TEXT)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1731, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1735, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) == 0 {
			column_type = int32(m_SQLITE_INTEGER)
		} else {
			return int32(m_SQLITE_EMPTY)
		}
	}
	// Check the next token is identifier and matches "primary"
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1816, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	// Check the next token is identifier and matches "key"
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1753, int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend)-int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	*(*uintptr)(unsafe.Pointer(out_column_name)) = column_name
	*(*int32)(unsafe.Pointer(out_column_name_length)) = column_name_length
	*(*int32)(unsafe.Pointer(out_column_type)) = column_type
	return m_SQLITE_OK
}

type _Vec0DistanceMetrics = int32

const _VEC0_DISTANCE_METRIC_L2 = 1
const _VEC0_DISTANCE_METRIC_COSINE = 2
const _VEC0_DISTANCE_METRIC_L1 = 3

type TVectorColumnDefinition = struct {
	Fname            uintptr
	Fname_length     int32
	Fdimensions      Tsize_t
	Felement_type    _VectorElementType
	Fdistance_metric _Vec0DistanceMetrics
}

type VectorColumnDefinition = TVectorColumnDefinition

type TVec0PartitionColumnDefinition = struct {
	Ftype1       int32
	Fname        uintptr
	Fname_length int32
}

type Vec0PartitionColumnDefinition = TVec0PartitionColumnDefinition

type TVec0AuxiliaryColumnDefinition = struct {
	Ftype1       int32
	Fname        uintptr
	Fname_length int32
}

type Vec0AuxiliaryColumnDefinition = TVec0AuxiliaryColumnDefinition

type TVec0MetadataColumnDefinition = struct {
	Fkind        Tvec0_metadata_column_kind
	Fname        uintptr
	Fname_length int32
}

type Vec0MetadataColumnDefinition = TVec0MetadataColumnDefinition

func Xvector_byte_size(tls *libc.TLS, element_type _VectorElementType, dimensions Tsize_t) (r Tsize_t) {
	switch element_type {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		return dimensions * uint64(4)
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		return dimensions * uint64(1)
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		return dimensions / uint64(m_CHAR_BIT)
	}
	return uint64(0)
}

func Xvector_column_byte_size(tls *libc.TLS, column TVectorColumnDefinition) (r Tsize_t) {
	return Xvector_byte_size(tls, column.Felement_type, column.Fdimensions)
}

// C documentation
//
//	/**
//	 * @brief Parse an vec0 vtab argv[i] column definition and see if
//	 * it's a vector column defintion, ex `contents_embedding float[768]`.
//	 *
//	 * @param source vec0 argv[i] item
//	 * @param source_length length of source in bytes
//	 * @param outColumn Output the parse vector column to this struct, if success
//	 * @return int SQLITE_OK on success, SQLITE_EMPTY is it's not a vector column
//	 * definition, SQLITE_ERROR on error.
//	 */
func Xvec0_parse_vector_column(tls *libc.TLS, source uintptr, source_length int32, outColumn uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var dimensions, keyLength, nameLength, rc, valueLength int32
	var distanceMetric _Vec0DistanceMetrics
	var elementType _VectorElementType
	var key, name, value uintptr
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _, _, _, _, _, _, _ = dimensions, distanceMetric, elementType, key, keyLength, name, nameLength, rc, value, valueLength
	distanceMetric = int32(_VEC0_DISTANCE_METRIC_L2)
	Xvec0_scanner_init(tls, bp, source, source_length)
	// starts with an identifier
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	name = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
	nameLength = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
	// vector column type comes next: float, int, or bit
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1757, int32(5)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1824, int32(3)) == 0 {
		elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+8, int32(4)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+1828, int32(2)) == 0 {
			elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_INT8)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+13, int32(3)) == 0 {
				elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_BIT)
			} else {
				return int32(m_SQLITE_EMPTY)
			}
		}
	}
	// left '[' bracket
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_LBRACKET) {
		return int32(m_SQLITE_EMPTY)
	}
	// digit, for vector dimension length
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_DIGIT) {
		return int32(m_SQLITE_ERROR)
	}
	dimensions = libc.Xatoi(tls, (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart)
	if dimensions <= 0 {
		return int32(m_SQLITE_ERROR)
	}
	// // right ']' bracket
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_RBRACKET) {
		return int32(m_SQLITE_ERROR)
	}
	// any other tokens left should be column-level options , ex `key=value`
	// ex `distance_metric=L2 distance_metric=cosine` should error
	for int32(1) != 0 {
		// should be EOF or identifier (option key)
		rc = Xvec0_scanner_next(tls, bp, bp+24)
		if rc == int32(m_VEC0_TOKEN_RESULT_EOF) {
			break
		}
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
			return int32(m_SQLITE_ERROR)
		}
		key = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
		keyLength = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
		if libsqlite3.Xsqlite3_strnicmp(tls, key, __ccgo_ts+1831, keyLength) == 0 {
			if elementType == int32(_SQLITE_VEC_ELEMENT_TYPE_BIT) {
				return int32(m_SQLITE_ERROR)
			}
			// ensure equal sign after distance_metric
			rc = Xvec0_scanner_next(tls, bp, bp+24)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_EQ) {
				return int32(m_SQLITE_ERROR)
			}
			// distance_metric value, an identifier (L2, cosine, etc)
			rc = Xvec0_scanner_next(tls, bp, bp+24)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
				return int32(m_SQLITE_ERROR)
			}
			value = (*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart
			valueLength = int32(int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fend) - int64((*(*TVec0Token)(unsafe.Pointer(bp + 24))).Fstart))
			if libsqlite3.Xsqlite3_strnicmp(tls, value, __ccgo_ts+1847, valueLength) == 0 {
				distanceMetric = int32(_VEC0_DISTANCE_METRIC_L2)
			} else {
				if libsqlite3.Xsqlite3_strnicmp(tls, value, __ccgo_ts+1850, valueLength) == 0 {
					distanceMetric = int32(_VEC0_DISTANCE_METRIC_L1)
				} else {
					if libsqlite3.Xsqlite3_strnicmp(tls, value, __ccgo_ts+1853, valueLength) == 0 {
						distanceMetric = int32(_VEC0_DISTANCE_METRIC_COSINE)
					} else {
						return int32(m_SQLITE_ERROR)
					}
				}
			}
		} else {
			return int32(m_SQLITE_ERROR)
		}
	}
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1860, libc.VaList(bp+56, nameLength, name))
	if !((*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fname != 0) {
		return int32(m_SQLITE_ERROR)
	}
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fname_length = nameLength
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fdistance_metric = distanceMetric
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Felement_type = elementType
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fdimensions = libc.Uint64FromInt32(dimensions)
	return m_SQLITE_OK
}

type Tvec_each_vtab = struct {
	Fbase Tsqlite3_vtab
}

type vec_each_vtab = Tvec_each_vtab

type Tvec_each_cursor = struct {
	Fbase        Tsqlite3_vtab_cursor
	FiRowid      Ti64
	Fvector_type _VectorElementType
	Fvector      uintptr
	Fdimensions  Tsize_t
	Fcleanup     Tvector_cleanup
}

type vec_each_cursor = Tvec_each_cursor

func _vec_eachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+1865)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(24))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint64(24))
	}
	return rc
}

func _vec_eachDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pVtab
	libsqlite3.Xsqlite3_free(tls, p)
	return m_SQLITE_OK
}

func _vec_eachOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(48))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint64(48))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_eachClose(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fcleanup})))(tls, (*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector)
	libsqlite3.Xsqlite3_free(tls, pCur)
	return m_SQLITE_OK
}

func _vec_eachBestIndex(tls *libc.TLS, pVTab uintptr, pIdxInfo uintptr) (r int32) {
	var hasVector, i int32
	var pCons uintptr
	_, _, _ = hasVector, i, pCons
	_ = pVTab
	hasVector = 0
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		pCons = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12
		// printf("i=%d iColumn=%d, op=%d, usable=%d\n", i, pCons->iColumn,
		// pCons->op, pCons->usable);
		switch (*Tsqlite3_index_constraint)(unsafe.Pointer(pCons)).FiColumn {
		case int32(m_VEC_EACH_COLUMN_VECTOR):
			if libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(pCons)).Fop) == int32(m_SQLITE_INDEX_CONSTRAINT_EQ) && (*Tsqlite3_index_constraint)(unsafe.Pointer(pCons)).Fusable != 0 {
				hasVector = int32(1)
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = int32(1)
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
			}
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if !(hasVector != 0) {
		return int32(m_SQLITE_CONSTRAINT)
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(100000)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
	return m_SQLITE_OK
}

func _vec_eachFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCur uintptr
	var rc int32
	var _ /* pzErrMsg at bp+0 */ uintptr
	_, _ = pCur, rc
	_ = idxNum
	_ = idxStr
	pCur = pVtabCursor
	if (*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fcleanup})))(tls, (*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector)
		(*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector = libc.UintptrFromInt32(0)
	}
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), pCur+24, pCur+32, pCur+16, pCur+40, bp)
	if rc != m_SQLITE_OK {
		return int32(m_SQLITE_ERROR)
	}
	(*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	return m_SQLITE_OK
}

func _vec_eachRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid
	return m_SQLITE_OK
}

func _vec_eachEof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	return libc.BoolInt32((*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid >= libc.Int64FromUint64((*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fdimensions))
}

func _vec_eachNext(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	(*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	return m_SQLITE_OK
}

func _vec_eachColumn(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var pCur uintptr
	var x Tu8
	_, _ = pCur, x
	pCur = cur
	switch i {
	case m_VEC_EACH_COLUMN_VALUE:
		switch (*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector_type {
		case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
			libsqlite3.Xsqlite3_result_double(tls, context, float64(*(*Tf32)(unsafe.Pointer((*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector + uintptr((*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid)*4))))
		case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
			x = *(*Tu8)(unsafe.Pointer((*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector + uintptr((*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid/int64(m_CHAR_BIT))))
			libsqlite3.Xsqlite3_result_int(tls, context, libc.BoolInt32(libc.Int32FromUint8(x)&(int32(0b10000000)>>((*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid%int64(m_CHAR_BIT))) > 0))
		case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
			libsqlite3.Xsqlite3_result_int(tls, context, int32(*(*Ti8)(unsafe.Pointer((*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector + uintptr((*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid)))))
			break
		}
		break
	}
	return m_SQLITE_OK
}

var _vec_eachModule = Tsqlite3_module{}

func init() {
	p := unsafe.Pointer(&_vec_eachModule)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_eachConnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_eachBestIndex)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_eachDisconnect)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_eachOpen)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec_eachClose)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_vec_eachFilter)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_vec_eachNext)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_vec_eachEof)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_vec_eachColumn)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_vec_eachRowid)
}

type _NpyTokenType = int32

const _NPY_TOKEN_TYPE_IDENTIFIER = 0
const _NPY_TOKEN_TYPE_NUMBER = 1
const _NPY_TOKEN_TYPE_LPAREN = 2
const _NPY_TOKEN_TYPE_RPAREN = 3
const _NPY_TOKEN_TYPE_LBRACE = 4
const _NPY_TOKEN_TYPE_RBRACE = 5
const _NPY_TOKEN_TYPE_COLON = 6
const _NPY_TOKEN_TYPE_COMMA = 7
const _NPY_TOKEN_TYPE_STRING = 8
const _NPY_TOKEN_TYPE_FALSE = 9

type TNpyToken = struct {
	Ftoken_type _NpyTokenType
	Fstart      uintptr
	Fend        uintptr
}

type NpyToken = TNpyToken

func Xnpy_token_next(tls *libc.TLS, start uintptr, end uintptr, out uintptr) (r int32) {
	var curr uint8
	var ptr, start1, start2, v1 uintptr
	_, _, _, _, _ = curr, ptr, start1, start2, v1
	ptr = start
	for ptr < end {
		curr = *(*uint8)(unsafe.Pointer(ptr))
		if Xis_whitespace(tls, curr) != 0 {
			ptr = ptr + 1
			continue
		} else {
			if libc.Int32FromUint8(curr) == int32('(') {
				v1 = ptr
				ptr = ptr + 1
				(*TNpyToken)(unsafe.Pointer(out)).Fstart = v1
				(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
				(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_LPAREN)
				return int32(m_VEC0_TOKEN_RESULT_SOME)
			} else {
				if libc.Int32FromUint8(curr) == int32(')') {
					v1 = ptr
					ptr = ptr + 1
					(*TNpyToken)(unsafe.Pointer(out)).Fstart = v1
					(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
					(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_RPAREN)
					return int32(m_VEC0_TOKEN_RESULT_SOME)
				} else {
					if libc.Int32FromUint8(curr) == int32('{') {
						v1 = ptr
						ptr = ptr + 1
						(*TNpyToken)(unsafe.Pointer(out)).Fstart = v1
						(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
						(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_LBRACE)
						return int32(m_VEC0_TOKEN_RESULT_SOME)
					} else {
						if libc.Int32FromUint8(curr) == int32('}') {
							v1 = ptr
							ptr = ptr + 1
							(*TNpyToken)(unsafe.Pointer(out)).Fstart = v1
							(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
							(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_RBRACE)
							return int32(m_VEC0_TOKEN_RESULT_SOME)
						} else {
							if libc.Int32FromUint8(curr) == int32(':') {
								v1 = ptr
								ptr = ptr + 1
								(*TNpyToken)(unsafe.Pointer(out)).Fstart = v1
								(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
								(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_COLON)
								return int32(m_VEC0_TOKEN_RESULT_SOME)
							} else {
								if libc.Int32FromUint8(curr) == int32(',') {
									v1 = ptr
									ptr = ptr + 1
									(*TNpyToken)(unsafe.Pointer(out)).Fstart = v1
									(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
									(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_COMMA)
									return int32(m_VEC0_TOKEN_RESULT_SOME)
								} else {
									if libc.Int32FromUint8(curr) == int32('\'') {
										start1 = ptr
										ptr = ptr + 1
										for ptr < end {
											if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(ptr))) == int32('\'') {
												break
											}
											ptr = ptr + 1
										}
										if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(ptr))) != int32('\'') {
											return int32(m_VEC0_TOKEN_RESULT_ERROR)
										}
										(*TNpyToken)(unsafe.Pointer(out)).Fstart = start1
										ptr = ptr + 1
										v1 = ptr
										(*TNpyToken)(unsafe.Pointer(out)).Fend = v1
										(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_STRING)
										return int32(m_VEC0_TOKEN_RESULT_SOME)
									} else {
										if libc.Int32FromUint8(curr) == int32('F') && libc.Xstrncmp(tls, ptr, __ccgo_ts+1902, libc.Xstrlen(tls, __ccgo_ts+1902)) == 0 {
											(*TNpyToken)(unsafe.Pointer(out)).Fstart = ptr
											(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr + uintptr(libc.Int32FromUint64(libc.Xstrlen(tls, __ccgo_ts+1902)))
											ptr = (*TNpyToken)(unsafe.Pointer(out)).Fend
											(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_FALSE)
											return int32(m_VEC0_TOKEN_RESULT_SOME)
										} else {
											if Xis_digit(tls, curr) != 0 {
												start2 = ptr
												for ptr < end && Xis_digit(tls, *(*uint8)(unsafe.Pointer(ptr))) != 0 {
													ptr = ptr + 1
												}
												(*TNpyToken)(unsafe.Pointer(out)).Fstart = start2
												(*TNpyToken)(unsafe.Pointer(out)).Fend = ptr
												(*TNpyToken)(unsafe.Pointer(out)).Ftoken_type = int32(_NPY_TOKEN_TYPE_NUMBER)
												return int32(m_VEC0_TOKEN_RESULT_SOME)
											} else {
												return int32(m_VEC0_TOKEN_RESULT_ERROR)
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return int32(m_VEC0_TOKEN_RESULT_ERROR)
}

type TNpyScanner = struct {
	Fstart uintptr
	Fend   uintptr
	Fptr   uintptr
}

type NpyScanner = TNpyScanner

func Xnpy_scanner_init(tls *libc.TLS, scanner uintptr, source uintptr, source_length int32) {
	(*TNpyScanner)(unsafe.Pointer(scanner)).Fstart = source
	(*TNpyScanner)(unsafe.Pointer(scanner)).Fend = source + uintptr(source_length)
	(*TNpyScanner)(unsafe.Pointer(scanner)).Fptr = source
}

func Xnpy_scanner_next(tls *libc.TLS, scanner uintptr, out uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = Xnpy_token_next(tls, (*TNpyScanner)(unsafe.Pointer(scanner)).Fstart, (*TNpyScanner)(unsafe.Pointer(scanner)).Fend, out)
	if rc == int32(m_VEC0_TOKEN_RESULT_SOME) {
		(*TNpyScanner)(unsafe.Pointer(scanner)).Fstart = (*TNpyToken)(unsafe.Pointer(out)).Fend
	}
	return rc
}

func Xparse_npy_header(tls *libc.TLS, pVTab uintptr, header uintptr, headerLength Tsize_t, out_element_type uintptr, fortran_order uintptr, numElements uintptr, numDimensions uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var first Tsize_t
	var key uintptr
	var rc, v1 int32
	var _ /* scanner at bp+0 */ TNpyScanner
	var _ /* token at bp+24 */ TNpyToken
	_, _, _, _ = first, key, rc, v1
	Xnpy_scanner_init(tls, bp, header, libc.Int32FromUint64(headerLength))
	if Xnpy_scanner_next(tls, bp, bp+24) != int32(m_VEC0_TOKEN_RESULT_SOME) && (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_LBRACE) {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+1908, 0)
		return int32(m_SQLITE_ERROR)
	}
	for int32(1) != 0 {
		rc = Xnpy_scanner_next(tls, bp, bp+24)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+1971, 0)
			return int32(m_SQLITE_ERROR)
		}
		if (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type == int32(_NPY_TOKEN_TYPE_RBRACE) {
			break
		}
		if (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_STRING) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+2027, 0)
			return int32(m_SQLITE_ERROR)
		}
		key = (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Fstart
		rc = Xnpy_scanner_next(tls, bp, bp+24)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_COLON) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+2095, 0)
			return int32(m_SQLITE_ERROR)
		}
		if libc.Xstrncmp(tls, key, __ccgo_ts+2163, libc.Xstrlen(tls, __ccgo_ts+2163)) == 0 {
			rc = Xnpy_scanner_next(tls, bp, bp+24)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_STRING) {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+2171, 0)
				return int32(m_SQLITE_ERROR)
			}
			if libc.Xstrncmp(tls, (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Fstart, __ccgo_ts+2240, libc.Xstrlen(tls, __ccgo_ts+2240)) != 0 {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+2246, 0)
				return int32(m_SQLITE_ERROR)
			}
			*(*_VectorElementType)(unsafe.Pointer(out_element_type)) = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
		} else {
			if libc.Xstrncmp(tls, key, __ccgo_ts+2335, libc.Xstrlen(tls, __ccgo_ts+2335)) == 0 {
				rc = Xnpy_scanner_next(tls, bp, bp+24)
				if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_FALSE) {
					Xvtab_set_error(tls, pVTab, __ccgo_ts+2351, 0)
					return int32(m_SQLITE_ERROR)
				}
				*(*int32)(unsafe.Pointer(fortran_order)) = 0
			} else {
				if libc.Xstrncmp(tls, key, __ccgo_ts+2448, libc.Xstrlen(tls, __ccgo_ts+2448)) == 0 {
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_LPAREN) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2456, 0)
						return int32(m_SQLITE_ERROR)
					}
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_NUMBER) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2529, 0)
						return int32(m_SQLITE_ERROR)
					}
					first = libc.Uint64FromInt64(libc.Xstrtol(tls, (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Fstart, libc.UintptrFromInt32(0), int32(10)))
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_COMMA) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2598, 0)
						return int32(m_SQLITE_ERROR)
					}
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2664, 0)
						return int32(m_SQLITE_ERROR)
					}
					if (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type == int32(_NPY_TOKEN_TYPE_NUMBER) {
						*(*Tsize_t)(unsafe.Pointer(numElements)) = first
						*(*Tsize_t)(unsafe.Pointer(numDimensions)) = libc.Uint64FromInt64(libc.Xstrtol(tls, (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Fstart, libc.UintptrFromInt32(0), int32(10)))
						rc = Xnpy_scanner_next(tls, bp, bp+24)
						if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_RPAREN) {
							Xvtab_set_error(tls, pVTab, __ccgo_ts+2733, 0)
							return int32(m_SQLITE_ERROR)
						}
					} else {
						if (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type == int32(_NPY_TOKEN_TYPE_RPAREN) {
							// '(0,)' means an empty array!
							if first != 0 {
								v1 = int32(1)
							} else {
								v1 = 0
							}
							*(*Tsize_t)(unsafe.Pointer(numElements)) = libc.Uint64FromInt32(v1)
							*(*Tsize_t)(unsafe.Pointer(numDimensions)) = first
						} else {
							Xvtab_set_error(tls, pVTab, __ccgo_ts+2805, 0)
							return int32(m_SQLITE_ERROR)
						}
					}
				} else {
					Xvtab_set_error(tls, pVTab, __ccgo_ts+2860, 0)
					return int32(m_SQLITE_ERROR)
				}
			}
		}
		rc = Xnpy_scanner_next(tls, bp, bp+24)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (*(*TNpyToken)(unsafe.Pointer(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_COMMA) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+2915, 0)
			return int32(m_SQLITE_ERROR)
		}
	}
	return m_SQLITE_OK
}

type Tvec_npy_each_vtab = struct {
	Fbase Tsqlite3_vtab
}

type vec_npy_each_vtab = Tvec_npy_each_vtab

type Tvec_npy_each_input_type = int32

type vec_npy_each_input_type = Tvec_npy_each_input_type

const _VEC_NPY_EACH_INPUT_BUFFER = 0
const _VEC_NPY_EACH_INPUT_FILE = 1

type Tvec_npy_each_cursor = struct {
	Fbase              Tsqlite3_vtab_cursor
	FiRowid            Ti64
	FelementType       _VectorElementType
	FnElements         Tsize_t
	FnDimensions       Tsize_t
	Finput_type        Tvec_npy_each_input_type
	Fvector            uintptr
	Ffile              uintptr
	FchunksBuffer      uintptr
	FchunksBufferSize  Tsize_t
	FmaxChunks         Tsize_t
	FcurrentChunkIndex Tsize_t
	FcurrentChunkSize  Tsize_t
	Feof               int32
}

type vec_npy_each_cursor = Tvec_npy_each_cursor

var _NPY_MAGIC = [6]uint8{147, 'N', 'U', 'M', 'P', 'Y'}

func Xparse_npy_file(tls *libc.TLS, pVTab uintptr, file uintptr, pCur uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var dataSize, expectedDataSize Ti32
	var fileSize int64
	var headerX uintptr
	var major, minor Tu8
	var n, rc int32
	var totalHeaderLength Tsize_t
	var _ /* element_type at bp+16 */ _VectorElementType
	var _ /* fortran_order at bp+12 */ int32
	var _ /* header at bp+0 */ [10]uint8
	var _ /* headerLength at bp+10 */ Tuint16_t
	var _ /* numDimensions at bp+32 */ Tsize_t
	var _ /* numElements at bp+24 */ Tsize_t
	_, _, _, _, _, _, _, _, _ = dataSize, expectedDataSize, fileSize, headerX, major, minor, n, rc, totalHeaderLength
	libc.Xfseek(tls, file, 0, int32(2))
	fileSize = libc.Xftell(tls, file)
	libc.Xfseek(tls, file, 0, 0)
	n = libc.Int32FromUint64(libc.Xfread(tls, bp, uint64(1), uint64(10), file))
	if n != int32(10) {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+2974, 0)
		return int32(m_SQLITE_ERROR)
	}
	if libc.Xmemcmp(tls, uintptr(unsafe.Pointer(&_NPY_MAGIC)), bp, uint64(6)) != 0 {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3001, 0)
		return int32(m_SQLITE_ERROR)
	}
	major = (*(*[10]uint8)(unsafe.Pointer(bp)))[int32(6)]
	minor = (*(*[10]uint8)(unsafe.Pointer(bp)))[int32(7)]
	*(*Tuint16_t)(unsafe.Pointer(bp + 10)) = uint16(0)
	libc.Xmemcpy(tls, bp+10, bp+8, uint64(2))
	totalHeaderLength = libc.Uint64FromInt64(6) + libc.Uint64FromInt64(1) + libc.Uint64FromInt64(1) + libc.Uint64FromInt64(2) + uint64(*(*Tuint16_t)(unsafe.Pointer(bp + 10)))
	dataSize = libc.Int32FromUint64(libc.Uint64FromInt64(fileSize) - totalHeaderLength)
	if dataSize < 0 {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3054, 0)
		return int32(m_SQLITE_ERROR)
	}
	headerX = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint16(*(*Tuint16_t)(unsafe.Pointer(bp + 10))))
	if *(*Tuint16_t)(unsafe.Pointer(bp + 10)) != 0 && !(headerX != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	n = libc.Int32FromUint64(libc.Xfread(tls, headerX, uint64(1), uint64(*(*Tuint16_t)(unsafe.Pointer(bp + 10))), file))
	if n != libc.Int32FromUint16(*(*Tuint16_t)(unsafe.Pointer(bp + 10))) {
		libsqlite3.Xsqlite3_free(tls, headerX)
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3054, 0)
		return int32(m_SQLITE_ERROR)
	}
	rc = Xparse_npy_header(tls, pVTab, headerX, uint64(*(*Tuint16_t)(unsafe.Pointer(bp + 10))), bp+16, bp+12, bp+24, bp+32)
	libsqlite3.Xsqlite3_free(tls, headerX)
	if rc != m_SQLITE_OK {
		// parse_npy_header already attackes an error emssage
		return rc
	}
	expectedDataSize = libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(bp + 24)) * Xvector_byte_size(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 16)), *(*Tsize_t)(unsafe.Pointer(bp + 32))))
	if expectedDataSize != dataSize {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3096, libc.VaList(bp+48, expectedDataSize, dataSize))
		return int32(m_SQLITE_ERROR)
	}
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FmaxChunks = uint64(1024)
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBufferSize = Xvector_byte_size(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 16)), *(*Tsize_t)(unsafe.Pointer(bp + 32))) * (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FmaxChunks
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBufferSize))
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBufferSize != 0 && !((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize = libc.Xfread(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer, Xvector_byte_size(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 16)), *(*Tsize_t)(unsafe.Pointer(bp + 32))), (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FmaxChunks, file)
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex = uint64(0)
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType = *(*_VectorElementType)(unsafe.Pointer(bp + 16))
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements = *(*Tsize_t)(unsafe.Pointer(bp + 24))
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions = *(*Tsize_t)(unsafe.Pointer(bp + 32))
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type = int32(_VEC_NPY_EACH_INPUT_FILE)
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Feof = libc.BoolInt32((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize == uint64(0))
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile = file
	return m_SQLITE_OK
}

func Xparse_npy_buffer(tls *libc.TLS, pVTab uintptr, buffer uintptr, bufferLength int32, data uintptr, numElements uintptr, numDimensions uintptr, element_type uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dataSize, expectedDataSize, totalHeaderLength Ti32
	var header uintptr
	var major, minor Tu8
	var rc int32
	var _ /* fortran_order at bp+4 */ int32
	var _ /* headerLength at bp+0 */ Tuint16_t
	_, _, _, _, _, _, _ = dataSize, expectedDataSize, header, major, minor, rc, totalHeaderLength
	if bufferLength < int32(10) {
		// IMP: V03312_20150
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3157, 0)
		return int32(m_SQLITE_ERROR)
	}
	if libc.Xmemcmp(tls, uintptr(unsafe.Pointer(&_NPY_MAGIC)), buffer, uint64(6)) != 0 {
		// V11954_28792
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3179, 0)
		return int32(m_SQLITE_ERROR)
	}
	major = *(*uint8)(unsafe.Pointer(buffer + 6))
	minor = *(*uint8)(unsafe.Pointer(buffer + 7))
	*(*Tuint16_t)(unsafe.Pointer(bp)) = uint16(0)
	libc.Xmemcpy(tls, bp, buffer+8, uint64(2))
	totalHeaderLength = libc.Int32FromUint64(libc.Uint64FromInt64(6) + libc.Uint64FromInt64(1) + libc.Uint64FromInt64(1) + libc.Uint64FromInt64(2) + uint64(*(*Tuint16_t)(unsafe.Pointer(bp))))
	dataSize = bufferLength - totalHeaderLength
	if dataSize < 0 {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3227, 0)
		return int32(m_SQLITE_ERROR)
	}
	header = buffer + 10
	rc = Xparse_npy_header(tls, pVTab, header, uint64(*(*Tuint16_t)(unsafe.Pointer(bp))), element_type, bp+4, numElements, numDimensions)
	if rc != m_SQLITE_OK {
		return rc
	}
	expectedDataSize = libc.Int32FromUint64(*(*Tsize_t)(unsafe.Pointer(numElements)) * Xvector_byte_size(tls, *(*_VectorElementType)(unsafe.Pointer(element_type)), *(*Tsize_t)(unsafe.Pointer(numDimensions))))
	if expectedDataSize != dataSize {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3264, libc.VaList(bp+16, expectedDataSize, dataSize))
		return int32(m_SQLITE_ERROR)
	}
	*(*uintptr)(unsafe.Pointer(data)) = buffer + uintptr(totalHeaderLength)
	return m_SQLITE_OK
}

func _vec_npy_eachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+3320)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(24))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint64(24))
	}
	return rc
}

func _vec_npy_eachDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pVtab
	libsqlite3.Xsqlite3_free(tls, p)
	return m_SQLITE_OK
}

func _vec_npy_eachOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(112))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint64(112))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_npy_eachClose(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile != 0 {
		libc.Xfclose(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile)
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile = libc.UintptrFromInt32(0)
	}
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer)
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer = libc.UintptrFromInt32(0)
	}
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector != 0 {
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector = libc.UintptrFromInt32(0)
	}
	libsqlite3.Xsqlite3_free(tls, pCur)
	return m_SQLITE_OK
}

func _vec_npy_eachBestIndex(tls *libc.TLS, pVTab uintptr, pIdxInfo uintptr) (r int32) {
	var hasInput, i int32
	var pCons uintptr
	_, _, _ = hasInput, i, pCons
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		pCons = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12
		// printf("i=%d iColumn=%d, op=%d, usable=%d\n", i, pCons->iColumn,
		// pCons->op, pCons->usable);
		switch (*Tsqlite3_index_constraint)(unsafe.Pointer(pCons)).FiColumn {
		case int32(m_VEC_NPY_EACH_COLUMN_INPUT):
			if libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(pCons)).Fop) == int32(m_SQLITE_INDEX_CONSTRAINT_EQ) && (*Tsqlite3_index_constraint)(unsafe.Pointer(pCons)).Fusable != 0 {
				hasInput = int32(1)
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).FargvIndex = int32(1)
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8))).Fomit = uint8(1)
			}
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if !(hasInput != 0) {
		(*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+3357, 0)
		return int32(m_SQLITE_ERROR)
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(100000)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
	return m_SQLITE_OK
}

func _vec_npy_eachFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var f, file, input, pCur, v1 uintptr
	var inputLength, rc int32
	var _ /* data at bp+0 */ uintptr
	var _ /* element_type at bp+24 */ _VectorElementType
	var _ /* numDimensions at bp+16 */ Tsize_t
	var _ /* numElements at bp+8 */ Tsize_t
	_, _, _, _, _, _, _ = f, file, input, inputLength, pCur, rc, v1
	_ = idxNum
	_ = idxStr
	pCur = pVtabCursor
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile != 0 {
		libc.Xfclose(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile)
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile = libc.UintptrFromInt32(0)
	}
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer)
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer = libc.UintptrFromInt32(0)
	}
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector != 0 {
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector = libc.UintptrFromInt32(0)
	}
	f = libc.UintptrFromInt32(0)
	v1 = libsqlite3.Xsqlite3_value_pointer(tls, *(*uintptr)(unsafe.Pointer(argv)), __ccgo_ts+660)
	f = v1
	if v1 != 0 {
		file = libc.Xfopen(tls, (*TVecNpyFile)(unsafe.Pointer(f)).Fpath, __ccgo_ts+3384)
		if !(file != 0) {
			Xvtab_set_error(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, __ccgo_ts+3386, 0)
			return int32(m_SQLITE_ERROR)
		}
		rc = Xparse_npy_file(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, file, pCur)
		if rc != m_SQLITE_OK {
			libc.Xfclose(tls, file)
			return rc
		}
	} else {
		input = libsqlite3.Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
		inputLength = libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		rc = Xparse_npy_buffer(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, input, inputLength, bp, bp+8, bp+16, bp+24)
		if rc != m_SQLITE_OK {
			return rc
		}
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector = *(*uintptr)(unsafe.Pointer(bp))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType = *(*_VectorElementType)(unsafe.Pointer(bp + 24))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements = *(*Tsize_t)(unsafe.Pointer(bp + 8))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions = *(*Tsize_t)(unsafe.Pointer(bp + 16))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type = int32(_VEC_NPY_EACH_INPUT_BUFFER)
	}
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	return m_SQLITE_OK
}

func _vec_npy_eachRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid
	return m_SQLITE_OK
}

func _vec_npy_eachEof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type == int32(_VEC_NPY_EACH_INPUT_BUFFER) {
		return libc.BoolInt32(!((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements != 0) || libc.Uint64FromInt64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid) >= (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements)
	}
	return (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Feof
}

func _vec_npy_eachNext(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type == int32(_VEC_NPY_EACH_INPUT_BUFFER) {
		return m_SQLITE_OK
	}
	// else: input is a file
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex = (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex + 1
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex >= (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize {
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize = libc.Xfread(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer, Xvector_byte_size(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions), (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FmaxChunks, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile)
		if !((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize != 0) {
			(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Feof = int32(1)
		}
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex = uint64(0)
	}
	return m_SQLITE_OK
}

func _vec_npy_eachColumnBuffer(tls *libc.TLS, pCur uintptr, context uintptr, i int32) (r int32) {
	switch i {
	case m_VEC_NPY_EACH_COLUMN_VECTOR:
		libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType))
		switch (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType {
		case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector+uintptr(libc.Uint64FromInt64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid)*(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), libc.Int32FromUint64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
		case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
			fallthrough
		case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
			// https://github.com/asg017/sqlite-vec/issues/42
			libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+3412, -int32(1))
			break
		}
		break
	}
	return m_SQLITE_OK
}

func _vec_npy_eachColumnFile(tls *libc.TLS, pCur uintptr, context uintptr, i int32) (r int32) {
	switch i {
	case m_VEC_NPY_EACH_COLUMN_VECTOR:
		switch (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType {
		case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer+uintptr((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex*(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), libc.Int32FromUint64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
		case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
			fallthrough
		case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
			// https://github.com/asg017/sqlite-vec/issues/42
			libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+3412, -int32(1))
			break
		}
		break
	}
	return m_SQLITE_OK
}

func _vec_npy_eachColumn(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	switch (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type {
	case int32(_VEC_NPY_EACH_INPUT_BUFFER):
		return _vec_npy_eachColumnBuffer(tls, pCur, context, i)
	case int32(_VEC_NPY_EACH_INPUT_FILE):
		return _vec_npy_eachColumnFile(tls, pCur, context, i)
	}
	return int32(m_SQLITE_ERROR)
}

var _vec_npy_eachModule = Tsqlite3_module{}

func init() {
	p := unsafe.Pointer(&_vec_npy_eachModule)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_npy_eachConnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_npy_eachBestIndex)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_npy_eachDisconnect)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_npy_eachOpen)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec_npy_eachClose)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_vec_npy_eachFilter)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_vec_npy_eachNext)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_vec_npy_eachEof)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_vec_npy_eachColumn)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_vec_npy_eachRowid)
}

/// 1) schema, 2) original vtab table name

/// 1) schema, 2) original vtab table name

// vec0 tables with a text primary keys are still backed by int64 primary keys,
// since a fixed-length rowid is required for vec0 chunks. But we add a new 'id
// text unique' column to emulate a text primary key interface.

/// 1) schema, 2) original vtab table name

/// 1) schema, 2) original vtab table name

type Tvec0_vtab = struct {
	Fbase                       Tsqlite3_vtab
	Fdb                         uintptr
	FpkIsText                   int32
	FnumVectorColumns           int32
	FnumPartitionColumns        int32
	FnumAuxiliaryColumns        int32
	FnumMetadataColumns         int32
	FschemaName                 uintptr
	FtableName                  uintptr
	FshadowRowidsName           uintptr
	FshadowChunksName           uintptr
	Fuser_column_kinds          [52]Tvec0_user_column_kind
	Fuser_column_idxs           [52]Tuint8_t
	FshadowVectorChunksNames    [16]uintptr
	FshadowMetadataChunksNames  [16]uintptr
	Fvector_columns             [16]TVectorColumnDefinition
	Fparitition_columns         [4]TVec0PartitionColumnDefinition
	Fauxiliary_columns          [16]TVec0AuxiliaryColumnDefinition
	Fmetadata_columns           [16]TVec0MetadataColumnDefinition
	Fchunk_size                 int32
	FstmtLatestChunk            uintptr
	FstmtRowidsInsertRowid      uintptr
	FstmtRowidsInsertId         uintptr
	FstmtRowidsUpdatePosition   uintptr
	FstmtRowidsGetChunkPosition uintptr
}

type vec0_vtab = Tvec0_vtab

type Tvec0_user_column_kind = int32

type vec0_user_column_kind = Tvec0_user_column_kind

const
// vector column, ie "contents_embedding float[1024]"
_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR = 1
const

// partition key column, ie "user_id integer partition key"
_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION = 2
const _SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY = 3
const

// metadata column that can be filtered, ie "genre text"
_SQLITE_VEC0_USER_COLUMN_KIND_METADATA = 4

// C documentation
//
//	/**
//	 * @brief Finalize all the sqlite3_stmt members in a vec0_vtab.
//	 *
//	 * @param p vec0_vtab pointer
//	 */
func Xvec0_free_resources(tls *libc.TLS, p uintptr) {
	libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition = libc.UintptrFromInt32(0)
}

// C documentation
//
//	/**
//	 * @brief Free all memory and sqlite3_stmt members of a vec0_vtab
//	 *
//	 * @param p vec0_vtab pointer
//	 */
func Xvec0_free(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	Xvec0_free_resources(tls, p)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FtableName = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowRowidsName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FshadowRowidsName = libc.UintptrFromInt32(0)
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)))
		*(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)) = libc.UintptrFromInt32(0)
		libsqlite3.Xsqlite3_free(tls, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname)
		(*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname = libc.UintptrFromInt32(0)
		goto _1
	_1:
		;
		i = i + 1
	}
}

func Xvec0_num_defined_user_columns(tls *libc.TLS, p uintptr) (r int32) {
	return (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns + (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns + (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns + (*Tvec0_vtab)(unsafe.Pointer(p)).FnumMetadataColumns
}

// C documentation
//
//	/**
//	 * @brief Returns the index of the distance hidden column for the given vec0
//	 * table.
//	 *
//	 * @param p vec0 table
//	 * @return int
//	 */
func Xvec0_column_distance_idx(tls *libc.TLS, p uintptr) (r int32) {
	return int32(m_VEC0_COLUMN_USERN_START) + (Xvec0_num_defined_user_columns(tls, p) - int32(1)) + int32(m_VEC0_COLUMN_OFFSET_DISTANCE)
}

// C documentation
//
//	/**
//	 * @brief Returns the index of the k hidden column for the given vec0 table.
//	 *
//	 * @param p vec0 table
//	 * @return int k column index
//	 */
func Xvec0_column_k_idx(tls *libc.TLS, p uintptr) (r int32) {
	return int32(m_VEC0_COLUMN_USERN_START) + (Xvec0_num_defined_user_columns(tls, p) - int32(1)) + int32(m_VEC0_COLUMN_OFFSET_K)
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a valid vector column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_vector(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && *(*Tvec0_user_column_kind)(unsafe.Pointer(pVtab + 88 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR))
}

// C documentation
//
//	/**
//	 * Returns the vector index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_is_vector before
//	 */
func Xvec0_column_idx_to_vector_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a "partition key" column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_partition(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && *(*Tvec0_user_column_kind)(unsafe.Pointer(pVtab + 88 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION))
}

// C documentation
//
//	/**
//	 * Returns the partition column index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_is_vector before
//	 */
func Xvec0_column_idx_to_partition_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a auxiliary column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_auxiliary(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && *(*Tvec0_user_column_kind)(unsafe.Pointer(pVtab + 88 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY))
}

// C documentation
//
//	/**
//	 * Returns the auxiliary column index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_to_partition_idx before
//	 */
func Xvec0_column_idx_to_auxiliary_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a metadata column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_metadata(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && *(*Tvec0_user_column_kind)(unsafe.Pointer(pVtab + 88 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA))
}

// C documentation
//
//	/**
//	 * Returns the metadata column index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_is_metadata before
//	 */
func Xvec0_column_idx_to_metadata_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * @brief Retrieve the chunk_id, chunk_offset, and possible "id" value
//	 * of a vec0_vtab row with the provided rowid
//	 *
//	 * @param p vec0_vtab
//	 * @param rowid the rowid of the row to query
//	 * @param id output, optional sqlite3_value to provide the id.
//	 *            Useful for text PK rows. Must be freed with sqlite3_value_free()
//	 * @param chunk_id output, the chunk_id the row belongs to
//	 * @param chunk_offset  output, the offset within the chunk the row belongs to
//	 * @return SQLITE_ROW on success, error code otherwise. SQLITE_EMPTY if row DNE
//	 */
func Xvec0_get_chunk_position(tls *libc.TLS, p uintptr, rowid Ti64, id uintptr, chunk_id uintptr, chunk_offset uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var value, zSql uintptr
	_, _, _ = rc, value, zSql
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+3455, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), p+2024, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+3527, 0)
			goto cleanup
		}
	}
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	// special case: when no results, return SQLITE_EMPTY to convey "that chunk
	// position doesnt exist"
	if rc == int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_EMPTY)
		goto cleanup
	}
	if rc != int32(m_SQLITE_ROW) {
		goto cleanup
	}
	if id != 0 {
		value = libsqlite3.Xsqlite3_column_value(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, 0)
		*(*uintptr)(unsafe.Pointer(id)) = libsqlite3.Xsqlite3_value_dup(tls, value)
		if !(*(*uintptr)(unsafe.Pointer(id)) != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
	}
	if chunk_id != 0 {
		*(*Ti64)(unsafe.Pointer(chunk_id)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, int32(1))
	}
	if chunk_offset != 0 {
		*(*Ti64)(unsafe.Pointer(chunk_offset)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, int32(2))
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	return rc
}

// C documentation
//
//	/**
//	 * @brief Return the id value from the _rowids table where _rowids.rowid =
//	 * rowid.
//	 *
//	 * @param pVtab: vec0 table to query
//	 * @param rowid: rowid of the row to query.
//	 * @param out: A dup'ed sqlite3_value of the id column. Might be null.
//	 *                         Must be cleaned up with sqlite3_value_free().
//	 * @returns SQLITE_OK on success, error code on failure
//	 */
func Xvec0_get_id_value_from_rowid(tls *libc.TLS, pVtab uintptr, rowid Ti64, out uintptr) (r int32) {
	// PERF: different strategy than get_chunk_position?
	return Xvec0_get_chunk_position(tls, pVtab, rowid, out, libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
}

func Xvec0_rowid_from_id(tls *libc.TLS, p uintptr, valueId uintptr, rowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _ = rc, zSql
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+3613, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	if !(zSql != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	libsqlite3.Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), valueId)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_EMPTY)
		goto cleanup
	}
	if rc != int32(m_SQLITE_ROW) {
		goto cleanup
	}
	*(*Ti64)(unsafe.Pointer(rowid)) = libsqlite3.Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != int32(m_SQLITE_DONE) {
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func Xvec0_result_id(tls *libc.TLS, p uintptr, context uintptr, rowid Ti64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* valueId at bp+0 */ uintptr
	_ = rc
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0) {
		libsqlite3.Xsqlite3_result_int64(tls, context, rowid)
		return m_SQLITE_OK
	}
	rc = Xvec0_get_id_value_from_rowid(tls, p, rowid, bp)
	if rc != m_SQLITE_OK {
		return rc
	}
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
	} else {
		libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp)))
		libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief
//	 *
//	 * @param pVtab: virtual table to query
//	 * @param rowid: row to lookup
//	 * @param vector_column_idx: which vector column to query
//	 * @param outVector: Output pointer to the vector buffer.
//	 *                    Must be sqlite3_free()'ed.
//	 * @param outVectorSize: Pointer to a int where the size of outVector
//	 *                       will be stored.
//	 * @return int SQLITE_OK on success.
//	 */
func Xvec0_get_vector_data(tls *libc.TLS, pVtab uintptr, rowid Ti64, vector_column_idx int32, outVector uintptr, outVectorSize uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var blobOffset, brc, rc int32
	var buf, p uintptr
	var size Tsize_t
	var _ /* chunk_id at bp+0 */ Ti64
	var _ /* chunk_offset at bp+8 */ Ti64
	var _ /* vectorBlob at bp+16 */ uintptr
	_, _, _, _, _, _ = blobOffset, brc, buf, p, rc, size
	p = pVtab
	buf = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = libc.UintptrFromInt32(0)
	rc = Xvec0_get_chunk_position(tls, pVtab, rowid, libc.UintptrFromInt32(0), bp, bp+8)
	if rc == int32(m_SQLITE_EMPTY) {
		Xvtab_set_error(tls, pVtab, __ccgo_ts+3661, libc.VaList(bp+32, rowid))
		goto cleanup
	}
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(vector_column_idx)*8)), __ccgo_ts+3698, *(*Ti64)(unsafe.Pointer(bp)), 0, bp+16)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, pVtab, __ccgo_ts+3706, libc.VaList(bp+32, rowid))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	size = Xvector_column_byte_size(tls, *(*TVectorColumnDefinition)(unsafe.Pointer(pVtab + 608 + uintptr(vector_column_idx)*32)))
	blobOffset = libc.Int32FromUint64(libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 8))) * size)
	buf = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(size))
	if !(buf != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), buf, libc.Int32FromUint64(size), blobOffset)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, buf)
		buf = libc.UintptrFromInt32(0)
		Xvtab_set_error(tls, pVtab, __ccgo_ts+3764, libc.VaList(bp+32, rowid))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	*(*uintptr)(unsafe.Pointer(outVector)) = buf
	if outVectorSize != 0 {
		*(*int32)(unsafe.Pointer(outVectorSize)) = libc.Int32FromUint64(size)
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	brc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if rc == m_SQLITE_OK && brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+3827, 0)
		return brc
	}
	return rc
}

// C documentation
//
//	/**
//	 * @brief Retrieve the sqlite3_value of the i'th partition value for the given row.
//	 *
//	 * @param pVtab - the vec0_vtab in questions
//	 * @param rowid - rowid of target row
//	 * @param partition_idx - which partition column to retrieve
//	 * @param outValue - output sqlite3_value
//	 * @return int - SQLITE_OK on success, otherwise error code
//	 */
func Xvec0_get_partition_value_for_rowid(tls *libc.TLS, pVtab uintptr, rowid Ti64, partition_idx int32, outValue uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var zSql uintptr
	var _ /* chunk_id at bp+0 */ Ti64
	var _ /* chunk_offset at bp+8 */ Ti64
	var _ /* stmt at bp+16 */ uintptr
	_, _ = rc, zSql
	rc = Xvec0_get_chunk_position(tls, pVtab, rowid, libc.UintptrFromInt32(0), bp, bp+8)
	if rc != m_SQLITE_OK {
		return rc
	}
	*(*uintptr)(unsafe.Pointer(bp + 16)) = libc.UintptrFromInt32(0)
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+3919, libc.VaList(bp+32, partition_idx, (*Tvec0_vtab)(unsafe.Pointer(pVtab)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pVtab)).FtableName))
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(pVtab)).Fdb, zSql, -int32(1), bp+16, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		return rc
	}
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), int32(1), *(*Ti64)(unsafe.Pointer(bp)))
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if rc != int32(m_SQLITE_ROW) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	*(*uintptr)(unsafe.Pointer(outValue)) = libsqlite3.Xsqlite3_value_dup(tls, libsqlite3.Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 0))
	if !(*(*uintptr)(unsafe.Pointer(outValue)) != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto done
	}
	rc = m_SQLITE_OK
	goto done
done:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	return rc
}

// C documentation
//
//	/**
//	 * @brief Get the value of an auxiliary column for the given rowid
//	 *
//	 * @param pVtab vec0_vtab
//	 * @param rowid the rowid of the row to lookup
//	 * @param auxiliary_idx aux index of the column we care about
//	 * @param outValue Output sqlite3_value to store
//	 * @return int SQLITE_OK on success, error code otherwise
//	 */
func Xvec0_get_auxiliary_value_for_rowid(tls *libc.TLS, pVtab uintptr, rowid Ti64, auxiliary_idx int32, outValue uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _ = rc, zSql
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+3981, libc.VaList(bp+16, auxiliary_idx, (*Tvec0_vtab)(unsafe.Pointer(pVtab)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pVtab)).FtableName))
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(pVtab)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		return rc
	}
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != int32(m_SQLITE_ROW) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	*(*uintptr)(unsafe.Pointer(outValue)) = libsqlite3.Xsqlite3_value_dup(tls, libsqlite3.Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp)), 0))
	if !(*(*uintptr)(unsafe.Pointer(outValue)) != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto done
	}
	rc = m_SQLITE_OK
	goto done
done:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

// C documentation
//
//	/**
//	 * @brief Result the given metadata value for the given row and metadata column index.
//	 * Will traverse the metadatachunksNN table with BLOB I/0 for the given rowid.
//	 *
//	 * @param p
//	 * @param rowid
//	 * @param metadata_idx
//	 * @param context
//	 * @return int
//	 */
func Xvec0_result_metadata_value_for_rowid(tls *libc.TLS, p uintptr, rowid Ti64, metadata_idx int32, context uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var length, rc, value int32
	var zSql uintptr
	var _ /* blobValue at bp+16 */ uintptr
	var _ /* block at bp+24 */ Tu8
	var _ /* chunk_id at bp+0 */ Ti64
	var _ /* chunk_offset at bp+8 */ Ti64
	var _ /* stmt at bp+64 */ uintptr
	var _ /* value at bp+32 */ Ti64
	var _ /* value at bp+40 */ float64
	var _ /* view at bp+48 */ [16]Tu8
	_, _, _, _ = length, rc, value, zSql
	rc = Xvec0_get_chunk_position(tls, p, rowid, libc.UintptrFromInt32(0), bp, bp+8)
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 480 + uintptr(metadata_idx)*8)), __ccgo_ts+4039, *(*Ti64)(unsafe.Pointer(bp)), 0, bp+16)
	if rc != m_SQLITE_OK {
		return rc
	}
	switch (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_idx)*24))).Fkind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+24, int32(1), int32(*(*Ti64)(unsafe.Pointer(bp + 8))/int64(m_CHAR_BIT)))
		if rc != m_SQLITE_OK {
			goto done
		}
		value = libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(bp + 24))) >> (*(*Ti64)(unsafe.Pointer(bp + 8)) % int64(m_CHAR_BIT)) & int32(1)
		libsqlite3.Xsqlite3_result_int(tls, context, value)
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+32, int32(8), libc.Int32FromUint64(libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 8)))*uint64(8)))
		if rc != m_SQLITE_OK {
			goto done
		}
		libsqlite3.Xsqlite3_result_int64(tls, context, *(*Ti64)(unsafe.Pointer(bp + 32)))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+40, int32(8), libc.Int32FromUint64(libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 8)))*uint64(8)))
		if rc != m_SQLITE_OK {
			goto done
		}
		libsqlite3.Xsqlite3_result_double(tls, context, *(*float64)(unsafe.Pointer(bp + 40)))
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+48, int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH), int32(*(*Ti64)(unsafe.Pointer(bp + 8))*int64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)))
		if rc != m_SQLITE_OK {
			goto done
		}
		length = *(*int32)(unsafe.Pointer(bp + 48))
		if length <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			libsqlite3.Xsqlite3_result_text(tls, context, bp+48+libc.UintptrFromInt32(4), length, uintptr(-libc.Int32FromInt32(1)))
		} else {
			zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4044, libc.VaList(bp+80, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_idx))
			if !(zSql != 0) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+64, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_free(tls, zSql)
			if rc != m_SQLITE_OK {
				goto done
			}
			libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), int32(1), rowid)
			rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
			if rc != int32(m_SQLITE_ROW) {
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			libsqlite3.Xsqlite3_result_value(tls, context, libsqlite3.Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 0))
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
			rc = m_SQLITE_OK
		}
		break
	}
	goto done
done:
	;
	// blobValue is read-only, will not fail on close
	libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	return rc
}

func Xvec0_get_latest_chunk_rowid(tls *libc.TLS, p uintptr, chunk_rowid uintptr, partitionKeyValues uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1, rc int32
	var s, zSql uintptr
	_, _, _, _, _ = i, i1, rc, s, zSql
	// lazy initialize stmtLatestChunk when needed. May be cleared during xSync()
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk != 0) {
		if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns > 0 {
			s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+4104, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
			i = 0
			for {
				if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
					break
				}
				if i != 0 {
					libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+4151)
				}
				libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+4157, libc.VaList(bp+8, i))
				goto _1
			_1:
				;
				i = i + 1
			}
			zSql = libsqlite3.Xsqlite3_str_finish(tls, s)
		} else {
			zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4177, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		}
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), p+1992, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			// IMP: V21406_05476
			Xvtab_set_error(tls, p, __ccgo_ts+4217, 0)
			goto cleanup
		}
	}
	i1 = 0
	for {
		if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
			break
		}
		libsqlite3.Xsqlite3_bind_value(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk, i1+int32(1), *(*uintptr)(unsafe.Pointer(partitionKeyValues + uintptr(i1)*8)))
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	if rc != int32(m_SQLITE_ROW) {
		// IMP: V31559_15629
		Xvtab_set_error(tls, p, __ccgo_ts+4290, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if libsqlite3.Xsqlite3_column_type(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk, 0) == int32(m_SQLITE_NULL) {
		rc = int32(m_SQLITE_EMPTY)
		goto cleanup
	}
	*(*Ti64)(unsafe.Pointer(chunk_rowid)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk, 0)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	if rc != int32(m_SQLITE_DONE) {
		Xvtab_set_error(tls, p, __ccgo_ts+4345, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName))
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	}
	return rc
}

func Xvec0_rowids_insert_rowid(tls *libc.TLS, p uintptr, rowid Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var entered, rc int32
	var zSql uintptr
	_, _, _ = entered, rc, zSql
	rc = m_SQLITE_OK
	entered = 0
	_ = entered // temporary
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4496, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), p+2000, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+4543, 0)
			goto cleanup
		}
	}
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid, int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
	if rc != int32(m_SQLITE_DONE) {
		if libsqlite3.Xsqlite3_extended_errcode(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb) == libc.Int32FromInt32(m_SQLITE_CONSTRAINT)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8) {
			// IMP: V17090_01160
			Xvtab_set_error(tls, p, __ccgo_ts+4617, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		} else {
			// IMP: V04679_21517
			Xvtab_set_error(tls, p, __ccgo_ts+4660, libc.VaList(bp+8, libsqlite3.Xsqlite3_errmsg(tls, libsqlite3.Xsqlite3_db_handle(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId))))
		}
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
	}
	return rc
}

func Xvec0_rowids_insert_id(tls *libc.TLS, p uintptr, idValue uintptr, rowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var entered, rc int32
	var zSql uintptr
	_, _, _ = entered, rc, zSql
	rc = m_SQLITE_OK
	entered = 0
	_ = entered // temporary
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4711, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto complete
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), p+2008, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+4755, 0)
			goto complete
		}
	}
	if idValue != 0 {
		libsqlite3.Xsqlite3_bind_value(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId, int32(1), idValue)
	}
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
	if rc != int32(m_SQLITE_DONE) {
		if libsqlite3.Xsqlite3_extended_errcode(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb) == libc.Int32FromInt32(m_SQLITE_CONSTRAINT)|libc.Int32FromInt32(8)<<libc.Int32FromInt32(8) {
			// IMP: V20497_04568
			Xvtab_set_error(tls, p, __ccgo_ts+4617, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		} else {
			// IMP: V24016_08086
			// IMP: V15177_32015
			Xvtab_set_error(tls, p, __ccgo_ts+4832, libc.VaList(bp+8, libsqlite3.Xsqlite3_errmsg(tls, libsqlite3.Xsqlite3_db_handle(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId))))
		}
		rc = int32(m_SQLITE_ERROR)
		goto complete
	}
	*(*Ti64)(unsafe.Pointer(rowid)) = libsqlite3.Xsqlite3_last_insert_rowid(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb)
	rc = m_SQLITE_OK
	goto complete
complete:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
	}
	return rc
}

func Xvec0_metadata_chunk_size(tls *libc.TLS, kind Tvec0_metadata_column_kind, chunk_size int32) (r int32) {
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		return chunk_size / int32(8)
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		return libc.Int32FromUint64(libc.Uint64FromInt32(chunk_size) * uint64(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		return libc.Int32FromUint64(libc.Uint64FromInt32(chunk_size) * uint64(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		return chunk_size * int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)
	}
	return 0
}

func Xvec0_rowids_update_position(tls *libc.TLS, p uintptr, rowid Ti64, chunk_rowid Ti64, chunk_offset Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	_, _ = rc, zSql
	rc = m_SQLITE_OK
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4880, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), p+2016, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+4956, 0)
			goto cleanup
		}
	}
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition, int32(1), chunk_rowid)
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition, int32(2), chunk_offset)
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition, int32(3), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
	if rc != int32(m_SQLITE_DONE) {
		// IMP: V21925_05995
		Xvtab_set_error(tls, p, __ccgo_ts+5039, libc.VaList(bp+8, rowid, chunk_rowid, chunk_offset))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
	}
	return rc
}

// C documentation
//
//	/**
//	 * @brief Adds a new chunk for the vec0 table, and the corresponding vector
//	 * chunks.
//	 *
//	 * Inserts a new row into the _chunks table, with blank data, and uses that new
//	 * rowid to insert new blank rows into _vector_chunksXX tables.
//	 *
//	 * @param p: vec0 table to add new chunk
//	 * @param paritionKeyValues: Array of partition key valeus for the new chunk, if available
//	 * @param chunk_rowid: Output pointer, if not NULL, then will be filled with the
//	 * new chunk rowid.
//	 * @return int SQLITE_OK on success, error code otherwise.
//	 */
func Xvec0_new_chunk(tls *libc.TLS, p uintptr, partitionKeyValues uintptr, chunk_rowid uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var failed, i, i1, i2, i3, i4, metadata_column_idx, rc, vector_column_idx int32
	var rowid, vectorsSize Ti64
	var s, zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = failed, i, i1, i2, i3, i4, metadata_column_idx, rc, rowid, s, vector_column_idx, vectorsSize, zSql
	// Step 1: Insert a new row in _chunks, capture that new rowid
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns > 0 {
		s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+5151, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5180)
		i = 0
		for {
			if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
				break
			}
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+5204, libc.VaList(bp+16, i))
			goto _1
		_1:
			;
			i = i + 1
		}
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5220)
		i1 = 0
		for {
			if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
				break
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5238)
			goto _2
		_2:
			;
			i1 = i1 + 1
		}
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5242)
		zSql = libsqlite3.Xsqlite3_str_finish(tls, s)
	} else {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5244, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	}
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return rc
	}
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size))                                                   // size
	libsqlite3.Xsqlite3_bind_zeroblob(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/int32(m_CHAR_BIT))                                     // validity bitmap
	libsqlite3.Xsqlite3_bind_zeroblob(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(3), libc.Int32FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)*uint64(8))) // rowids
	i2 = 0
	for {
		if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
			break
		}
		libsqlite3.Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(4)+i2, *(*uintptr)(unsafe.Pointer(partitionKeyValues + uintptr(i2)*8)))
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	failed = libc.BoolInt32(rc != int32(m_SQLITE_DONE))
	rowid = libsqlite3.Xsqlite3_last_insert_rowid(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb)
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if failed != 0 {
		return int32(m_SQLITE_ERROR)
	}
	// Step 2: Create new vector chunks for each vector column, with
	//          that new chunk_rowid.
	i3 = 0
	for {
		if !(i3 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i3)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _4
		}
		vector_column_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i3))))
		vectorsSize = libc.Int64FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) * Xvector_column_byte_size(tls, *(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))))
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5315, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, vector_column_idx))
		if !(zSql != 0) {
			return int32(m_SQLITE_NOMEM)
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return rc
		}
		libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), rowid)
		libsqlite3.Xsqlite3_bind_zeroblob64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), libc.Uint64FromInt64(vectorsSize))
		rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if rc != int32(m_SQLITE_DONE) {
			return rc
		}
		goto _4
	_4:
		;
		i3 = i3 + 1
	}
	// Step 3: Create new metadata chunks for each metadata column
	i4 = 0
	for {
		if !(i4 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i4)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _5
		}
		metadata_column_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i4))))
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5384, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_column_idx))
		if !(zSql != 0) {
			return int32(m_SQLITE_NOMEM)
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return rc
		}
		libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), rowid)
		libsqlite3.Xsqlite3_bind_zeroblob64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), libc.Uint64FromInt32(Xvec0_metadata_chunk_size(tls, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_column_idx)*24))).Fkind, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)))
		rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if rc != int32(m_SQLITE_DONE) {
			return rc
		}
		goto _5
	_5:
		;
		i4 = i4 + 1
	}
	if chunk_rowid != 0 {
		*(*Ti64)(unsafe.Pointer(chunk_rowid)) = rowid
	}
	return m_SQLITE_OK
}

type Tvec0_query_fullscan_data = struct {
	Frowids_stmt uintptr
	Fdone        Ti8
}

type vec0_query_fullscan_data = Tvec0_query_fullscan_data

func Xvec0_query_fullscan_data_clear(tls *libc.TLS, fullscan_data uintptr) {
	if !(fullscan_data != 0) {
		return
	}
	if (*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Frowids_stmt != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Frowids_stmt)
		(*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Frowids_stmt = libc.UintptrFromInt32(0)
	}
}

type Tvec0_query_knn_data = struct {
	Fk           Ti64
	Fk_used      Ti64
	Frowids      uintptr
	Fdistances   uintptr
	Fcurrent_idx Ti64
}

type vec0_query_knn_data = Tvec0_query_knn_data

func Xvec0_query_knn_data_clear(tls *libc.TLS, knn_data uintptr) {
	if !(knn_data != 0) {
		return
	}
	if (*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Frowids != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Frowids)
		(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Frowids = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances)
		(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances = libc.UintptrFromInt32(0)
	}
}

type Tvec0_query_point_data = struct {
	Frowid   Ti64
	Fvectors [16]uintptr
	Fdone    int32
}

type vec0_query_point_data = Tvec0_query_point_data

func Xvec0_query_point_data_clear(tls *libc.TLS, point_data uintptr) {
	var i int32
	_ = i
	if !(point_data != 0) {
		return
	}
	i = 0
	for {
		if !(i < int32(m_VEC0_MAX_VECTOR_COLUMNS)) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(point_data + 8 + uintptr(i)*8)))
		*(*uintptr)(unsafe.Pointer(point_data + 8 + uintptr(i)*8)) = libc.UintptrFromInt32(0)
		goto _1
	_1:
		;
		i = i + 1
	}
}

type Tvec0_query_plan = int32

type vec0_query_plan = Tvec0_query_plan

const
// If any values are updated, please update the ARCHITECTURE.md docs accordingly!

_VEC0_QUERY_PLAN_FULLSCAN = 49
const _VEC0_QUERY_PLAN_POINT = 50
const _VEC0_QUERY_PLAN_KNN = 51

type Tvec0_cursor = struct {
	Fbase          Tsqlite3_vtab_cursor
	Fquery_plan    Tvec0_query_plan
	Ffullscan_data uintptr
	Fknn_data      uintptr
	Fpoint_data    uintptr
}

type vec0_cursor = Tvec0_cursor

func Xvec0_cursor_clear(tls *libc.TLS, pCur uintptr) {
	if (*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data != 0 {
		Xvec0_query_fullscan_data_clear(tls, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)
		libsqlite3.Xsqlite3_free(tls, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)
		(*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data != 0 {
		Xvec0_query_knn_data_clear(tls, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)
		libsqlite3.Xsqlite3_free(tls, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)
		(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data != 0 {
		Xvec0_query_point_data_clear(tls, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)
		libsqlite3.Xsqlite3_free(tls, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)
		(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data = libc.UintptrFromInt32(0)
	}
}

func _vec0_init(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate uint8) (r int32) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var auxiliary_idx, chunk_size, i, i1, i2, i3, i4, i5, i6, i7, metadata_idx, numAuxiliaryColumns, numMetadataColumns, numPartitionColumns, numVectorColumns, partition_idx, pkColumnNameLength, pkColumnType, rc, rc1, user_column_idx, vector_idx int32
	var createStr, pNew, pkColumnName, s, s1, schemaName, tableName, zCreateInfo, zCreateShadowChunks, zCreateShadowRowids, zSeedInfo, zSql, zSql1, zSql2, zSql3, zSql4 uintptr
	var _ /* auxColumn at bp+56 */ TVec0AuxiliaryColumnDefinition
	var _ /* cName at bp+104 */ uintptr
	var _ /* cNameLength at bp+112 */ int32
	var _ /* cType at bp+116 */ int32
	var _ /* key at bp+128 */ uintptr
	var _ /* keyLength at bp+144 */ int32
	var _ /* kind at bp+120 */ Tvec0_metadata_column_kind
	var _ /* metadataColumn at bp+80 */ TVec0MetadataColumnDefinition
	var _ /* partitionColumn at bp+32 */ TVec0PartitionColumnDefinition
	var _ /* stmt at bp+152 */ uintptr
	var _ /* stmt at bp+160 */ uintptr
	var _ /* value at bp+136 */ uintptr
	var _ /* valueLength at bp+148 */ int32
	var _ /* vecColumn at bp+0 */ TVectorColumnDefinition
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = auxiliary_idx, chunk_size, createStr, i, i1, i2, i3, i4, i5, i6, i7, metadata_idx, numAuxiliaryColumns, numMetadataColumns, numPartitionColumns, numVectorColumns, pNew, partition_idx, pkColumnName, pkColumnNameLength, pkColumnType, rc, rc1, s, s1, schemaName, tableName, user_column_idx, vector_idx, zCreateInfo, zCreateShadowChunks, zCreateShadowRowids, zSeedInfo, zSql, zSql1, zSql2, zSql3, zSql4
	_ = pAux
	pNew = libsqlite3.Xsqlite3_malloc(tls, int32(2032))
	if pNew == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pNew, 0, uint64(2032))
	// Declared chunk_size=N for entire table.
	// -1 to use the defualt, otherwise will get re-assigned on `chunk_size=N`
	// option
	chunk_size = -int32(1)
	numVectorColumns = 0
	numPartitionColumns = 0
	numAuxiliaryColumns = 0
	numMetadataColumns = 0
	user_column_idx = 0
	// track if a "primary key" column is defined
	pkColumnName = libc.UintptrFromInt32(0)
	pkColumnType = int32(m_SQLITE_INTEGER)
	i = int32(3)
	for {
		if !(i < argc) {
			break
		}
		*(*uintptr)(unsafe.Pointer(bp + 104)) = libc.UintptrFromInt32(0)
		// Scenario #1: Constructor argument is a vector column definition, ie `foo float[1024]`
		rc = Xvec0_parse_vector_column(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))), bp)
		if rc == int32(m_SQLITE_ERROR) {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5451, libc.VaList(bp+176, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))))
			goto error
		}
		if rc == m_SQLITE_OK {
			if numVectorColumns >= int32(m_VEC0_MAX_VECTOR_COLUMNS) {
				libsqlite3.Xsqlite3_free(tls, (*(*TVectorColumnDefinition)(unsafe.Pointer(bp))).Fname)
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5510, libc.VaList(bp+176, int32(m_VEC0_MAX_VECTOR_COLUMNS)))
				goto error
			}
			if (*(*TVectorColumnDefinition)(unsafe.Pointer(bp))).Fdimensions > uint64(m_SQLITE_VEC_VEC0_MAX_DIMENSIONS) {
				libsqlite3.Xsqlite3_free(tls, (*(*TVectorColumnDefinition)(unsafe.Pointer(bp))).Fname)
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5579, libc.VaList(bp+176, libc.Int64FromUint64((*(*TVectorColumnDefinition)(unsafe.Pointer(bp))).Fdimensions), int32(m_SQLITE_VEC_VEC0_MAX_DIMENSIONS)))
				goto error
			}
			*(*Tvec0_user_column_kind)(unsafe.Pointer(pNew + 88 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR)
			*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numVectorColumns)
			libc.Xmemcpy(tls, pNew+608+uintptr(numVectorColumns)*32, bp, uint64(32))
			numVectorColumns = numVectorColumns + 1
			user_column_idx = user_column_idx + 1
			goto _1
		}
		// Scenario #2: Constructor argument is a partition key column definition, ie `user_id text partition key`
		rc = Xvec0_parse_partition_key_definition(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))), bp+104, bp+112, bp+116)
		if rc == m_SQLITE_OK {
			if numPartitionColumns >= int32(m_VEC0_MAX_PARTITION_COLUMNS) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5669, libc.VaList(bp+176, int32(m_VEC0_MAX_PARTITION_COLUMNS)))
				goto error
			}
			(*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(bp + 32))).Ftype1 = *(*int32)(unsafe.Pointer(bp + 116))
			(*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(bp + 32))).Fname_length = *(*int32)(unsafe.Pointer(bp + 112))
			(*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(bp + 32))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1860, libc.VaList(bp+176, *(*int32)(unsafe.Pointer(bp + 112)), *(*uintptr)(unsafe.Pointer(bp + 104))))
			if !((*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(bp + 32))).Fname != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto error
			}
			*(*Tvec0_user_column_kind)(unsafe.Pointer(pNew + 88 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION)
			*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numPartitionColumns)
			libc.Xmemcpy(tls, pNew+1120+uintptr(numPartitionColumns)*24, bp+32, uint64(24))
			numPartitionColumns = numPartitionColumns + 1
			user_column_idx = user_column_idx + 1
			goto _1
		}
		// Scenario #3: Constructor argument is a primary key column definition, ie `article_id text primary key`
		rc = Xvec0_parse_primary_key_definition(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))), bp+104, bp+112, bp+116)
		if rc == m_SQLITE_OK {
			if pkColumnName != 0 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5742, libc.VaList(bp+176, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))))
				goto error
			}
			pkColumnName = *(*uintptr)(unsafe.Pointer(bp + 104))
			pkColumnNameLength = *(*int32)(unsafe.Pointer(bp + 112))
			pkColumnType = *(*int32)(unsafe.Pointer(bp + 116))
			goto _1
		}
		// Scenario #4: Constructor argument is a auxiliary column definition, ie `+contents text`
		rc = Xvec0_parse_auxiliary_column_definition(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))), bp+104, bp+112, bp+116)
		if rc == m_SQLITE_OK {
			if numAuxiliaryColumns >= int32(m_VEC0_MAX_AUXILIARY_COLUMNS) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5863, libc.VaList(bp+176, int32(m_VEC0_MAX_AUXILIARY_COLUMNS)))
				goto error
			}
			(*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(bp + 56))).Ftype1 = *(*int32)(unsafe.Pointer(bp + 116))
			(*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(bp + 56))).Fname_length = *(*int32)(unsafe.Pointer(bp + 112))
			(*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(bp + 56))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1860, libc.VaList(bp+176, *(*int32)(unsafe.Pointer(bp + 112)), *(*uintptr)(unsafe.Pointer(bp + 104))))
			if !((*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(bp + 56))).Fname != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto error
			}
			*(*Tvec0_user_column_kind)(unsafe.Pointer(pNew + 88 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY)
			*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numAuxiliaryColumns)
			libc.Xmemcpy(tls, pNew+1216+uintptr(numAuxiliaryColumns)*24, bp+56, uint64(24))
			numAuxiliaryColumns = numAuxiliaryColumns + 1
			user_column_idx = user_column_idx + 1
			goto _1
		}
		rc = Xvec0_parse_metadata_column_definition(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))), bp+104, bp+112, bp+120)
		if rc == m_SQLITE_OK {
			if numMetadataColumns >= int32(m_VEC0_MAX_METADATA_COLUMNS) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5932, libc.VaList(bp+176, int32(m_VEC0_MAX_METADATA_COLUMNS)))
				goto error
			}
			(*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(bp + 80))).Fkind = *(*Tvec0_metadata_column_kind)(unsafe.Pointer(bp + 120))
			(*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(bp + 80))).Fname_length = *(*int32)(unsafe.Pointer(bp + 112))
			(*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(bp + 80))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1860, libc.VaList(bp+176, *(*int32)(unsafe.Pointer(bp + 112)), *(*uintptr)(unsafe.Pointer(bp + 104))))
			if !((*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(bp + 80))).Fname != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto error
			}
			*(*Tvec0_user_column_kind)(unsafe.Pointer(pNew + 88 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA)
			*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numMetadataColumns)
			libc.Xmemcpy(tls, pNew+1600+uintptr(numMetadataColumns)*24, bp+80, uint64(24))
			numMetadataColumns = numMetadataColumns + 1
			user_column_idx = user_column_idx + 1
			goto _1
		}
		rc = Xvec0_parse_table_option(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), libc.Int32FromUint64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))), bp+128, bp+144, bp+136, bp+148)
		if rc == int32(m_SQLITE_ERROR) {
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6000, libc.VaList(bp+176, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))))
			goto error
		}
		if rc == m_SQLITE_OK {
			if libsqlite3.Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(bp + 128)), __ccgo_ts+6058, *(*int32)(unsafe.Pointer(bp + 144))) == 0 {
				chunk_size = libc.Xatoi(tls, *(*uintptr)(unsafe.Pointer(bp + 136)))
				if chunk_size <= 0 {
					// IMP: V01931_18769
					*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6069, 0)
					goto error
				}
				if chunk_size%int32(8) != 0 {
					// IMP: V14110_30948
					*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6140, 0)
					goto error
				}
				if chunk_size > int32(m_SQLITE_VEC_CHUNK_SIZE_MAX) {
					*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6198, 0)
					goto error
				}
			} else {
				// IMP: V27642_11712
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6243, libc.VaList(bp+176, *(*int32)(unsafe.Pointer(bp + 144)), *(*uintptr)(unsafe.Pointer(bp + 128))))
				goto error
			}
			goto _1
		}
		// Scenario #5: Unknown constructor argument
		*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6294, libc.VaList(bp+176, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))))
		goto error
		goto _1
	_1:
		;
		i = i + 1
	}
	if chunk_size < 0 {
		chunk_size = int32(1024)
	}
	if numVectorColumns <= 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6339, 0)
		goto error
	}
	createStr = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6402)
	if pkColumnName != 0 {
		libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6418, libc.VaList(bp+176, pkColumnNameLength, pkColumnName))
	} else {
		libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6439)
	}
	i1 = 0
	for {
		if !(i1 < numVectorColumns+numPartitionColumns+numAuxiliaryColumns+numMetadataColumns) {
			break
		}
		switch *(*Tvec0_user_column_kind)(unsafe.Pointer(pNew + 88 + uintptr(i1)*4)) {
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR):
			vector_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6447, libc.VaList(bp+176, (*(*TVectorColumnDefinition)(unsafe.Pointer(pNew + 608 + uintptr(vector_idx)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(pNew + 608 + uintptr(vector_idx)*32))).Fname))
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION):
			partition_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6447, libc.VaList(bp+176, (*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(pNew + 1120 + uintptr(partition_idx)*24))).Fname_length, (*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(pNew + 1120 + uintptr(partition_idx)*24))).Fname))
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY):
			auxiliary_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6447, libc.VaList(bp+176, (*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(pNew + 1216 + uintptr(auxiliary_idx)*24))).Fname_length, (*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(pNew + 1216 + uintptr(auxiliary_idx)*24))).Fname))
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA):
			metadata_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(pNew + 296 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6447, libc.VaList(bp+176, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pNew + 1600 + uintptr(metadata_idx)*24))).Fname_length, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pNew + 1600 + uintptr(metadata_idx)*24))).Fname))
			break
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6456)
	if pkColumnName != 0 {
		libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6485)
	}
	zSql = libsqlite3.Xsqlite3_str_finish(tls, createStr)
	if !(zSql != 0) {
		goto error
	}
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, zSql)
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6500, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
		goto error
	}
	schemaName = *(*uintptr)(unsafe.Pointer(argv + 1*8))
	tableName = *(*uintptr)(unsafe.Pointer(argv + 2*8))
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).Fdb = db
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FpkIsText = libc.BoolInt32(pkColumnType == int32(m_SQLITE_TEXT))
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6562, libc.VaList(bp+176, schemaName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6562, libc.VaList(bp+176, tableName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowRowidsName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6565, libc.VaList(bp+176, tableName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowRowidsName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowChunksName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6575, libc.VaList(bp+176, tableName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowChunksName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns = numVectorColumns
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns = numPartitionColumns
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns = numAuxiliaryColumns
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns = numMetadataColumns
	i2 = 0
	for {
		if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns) {
			break
		}
		*(*uintptr)(unsafe.Pointer(pNew + 352 + uintptr(i2)*8)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6585, libc.VaList(bp+176, tableName, i2))
		if !(*(*uintptr)(unsafe.Pointer(pNew + 352 + uintptr(i2)*8)) != 0) {
			goto error
		}
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	i3 = 0
	for {
		if !(i3 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns) {
			break
		}
		*(*uintptr)(unsafe.Pointer(pNew + 480 + uintptr(i3)*8)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6606, libc.VaList(bp+176, tableName, i3))
		if !(*(*uintptr)(unsafe.Pointer(pNew + 480 + uintptr(i3)*8)) != 0) {
			goto error
		}
		goto _4
	_4:
		;
		i3 = i3 + 1
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).Fchunk_size = chunk_size
	// if xCreate, then create the necessary shadow tables
	if isCreate != 0 {
		zCreateInfo = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6628, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		if !(zCreateInfo != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zCreateInfo, -int32(1), bp+152, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zCreateInfo)
		if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
			// TODO(IMP)
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6690, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
		zSeedInfo = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6732, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		if !(zSeedInfo != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSeedInfo, -int32(1), bp+152, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSeedInfo)
		if rc1 != m_SQLITE_OK {
			// TODO(IMP)
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6818, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(1), __ccgo_ts+6858, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(2), __ccgo_ts+6873, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(3), __ccgo_ts+6880, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(4), m_SQLITE_VEC_VERSION_MAJOR)
		libsqlite3.Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(5), __ccgo_ts+6901, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(6), int32(m_SQLITE_VEC_VERSION_MINOR))
		libsqlite3.Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(7), __ccgo_ts+6922, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp + 152)), int32(8), int32(m_SQLITE_VEC_VERSION_PATCH))
		if libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
			// TODO(IMP)
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6818, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
		// create the _chunks shadow table
		zCreateShadowChunks = libc.UintptrFromInt32(0)
		if (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns != 0 {
			s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+6943, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+6974)
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+7040)
			i4 = 0
			for {
				if !(i4 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns) {
					break
				}
				libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+7061, libc.VaList(bp+176, i4))
				goto _5
			_5:
				;
				i4 = i4 + 1
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+7076)
			zCreateShadowChunks = libsqlite3.Xsqlite3_str_finish(tls, s)
		} else {
			zCreateShadowChunks = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7123, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		}
		if !(zCreateShadowChunks != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zCreateShadowChunks, -int32(1), bp+152, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zCreateShadowChunks)
		if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
			// IMP: V17740_01811
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7264, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
		if (*Tvec0_vtab)(unsafe.Pointer(pNew)).FpkIsText != 0 {
			// adds a "text unique not null" constraint to the id column
			zCreateShadowRowids = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7308, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		} else {
			zCreateShadowRowids = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7442, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		}
		if !(zCreateShadowRowids != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zCreateShadowRowids, -int32(1), bp+152, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zCreateShadowRowids)
		if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
			// IMP: V11631_28470
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7555, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
		i5 = 0
		for {
			if !(i5 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns) {
				break
			}
			zSql1 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7599, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName, i5))
			if !(zSql1 != 0) {
				goto error
			}
			rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql1, -int32(1), bp+152, uintptr(0))
			libsqlite3.Xsqlite3_free(tls, zSql1)
			if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
				// IMP: V25919_09989
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7682, libc.VaList(bp+176, i5, libsqlite3.Xsqlite3_errmsg(tls, db)))
				goto error
			}
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			goto _6
		_6:
			;
			i5 = i5 + 1
		}
		i6 = 0
		for {
			if !(i6 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns) {
				break
			}
			zSql2 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7737, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName, i6))
			if !(zSql2 != 0) {
				goto error
			}
			rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql2, -int32(1), bp+152, uintptr(0))
			libsqlite3.Xsqlite3_free(tls, zSql2)
			if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7819, libc.VaList(bp+176, i6, libsqlite3.Xsqlite3_errmsg(tls, db)))
				goto error
			}
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			if (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pNew + 1600 + uintptr(i6)*24))).Fkind == int32(_VEC0_METADATA_COLUMN_KIND_TEXT) {
				zSql3 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7874, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName, i6))
				if !(zSql3 != 0) {
					goto error
				}
				rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql3, -int32(1), bp+152, uintptr(0))
				libsqlite3.Xsqlite3_free(tls, zSql3)
				if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 152))) != int32(m_SQLITE_DONE) {
					libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
					*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7945, libc.VaList(bp+176, i6, libsqlite3.Xsqlite3_errmsg(tls, db)))
					goto error
				}
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 152)))
			}
			goto _7
		_7:
			;
			i6 = i6 + 1
		}
		if (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns > 0 {
			s1 = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_str_appendf(tls, s1, __ccgo_ts+7999, libc.VaList(bp+176, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
			i7 = 0
			for {
				if !(i7 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns) {
					break
				}
				libsqlite3.Xsqlite3_str_appendf(tls, s1, __ccgo_ts+8060, libc.VaList(bp+176, i7))
				goto _8
			_8:
				;
				i7 = i7 + 1
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s1, __ccgo_ts+5242)
			zSql4 = libsqlite3.Xsqlite3_str_finish(tls, s1)
			if !(zSql4 != 0) {
				goto error
			}
			rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql4, -int32(1), bp+160, libc.UintptrFromInt32(0))
			if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 160))) != int32(m_SQLITE_DONE) {
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 160)))
				*(*uintptr)(unsafe.Pointer(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8072, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, db)))
				goto error
			}
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 160)))
		}
	}
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
	return m_SQLITE_OK
	goto error
error:
	;
	Xvec0_free(tls, pNew)
	return int32(m_SQLITE_ERROR)
}

func _vec0Create(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _vec0_init(tls, db, pAux, argc, argv, ppVtab, pzErr, libc.BoolUint8(m_true != 0))
}

func _vec0Connect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _vec0_init(tls, db, pAux, argc, argv, ppVtab, pzErr, libc.BoolUint8(m_false != 0))
}

func _vec0Disconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pVtab
	Xvec0_free(tls, p)
	libsqlite3.Xsqlite3_free(tls, p)
	return m_SQLITE_OK
}

func _vec0Destroy(tls *libc.TLS, pVtab uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, i1, rc int32
	var p, zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _, _, _, _ = i, i1, p, rc, zSql
	p = pVtab
	// Free up any sqlite3_stmt, otherwise DROPs on those tables will fail
	Xvec0_free_resources(tls, p)
	// TODO(test) later: can't evidence-of here, bc always gives "SQL logic error" instead of
	// provided error
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8116, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_ERROR)
		Xvtab_set_error(tls, pVtab, __ccgo_ts+8144, 0)
		goto done
	}
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8179, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_ERROR)
		Xvtab_set_error(tls, pVtab, __ccgo_ts+8205, 0)
		goto done
	}
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8238, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8266, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8))))
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		goto _1
	_1:
		;
		i = i + 1
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns > 0 {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8287, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	i1 = 0
	for {
		if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumMetadataColumns) {
			break
		}
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8318, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, i1))
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(i1)*24))).Fkind == int32(_VEC0_METADATA_COLUMN_KIND_TEXT) {
			zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8358, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, i1))
			rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
			libsqlite3.Xsqlite3_free(tls, zSql)
			if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != int32(m_SQLITE_DONE) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	rc = m_SQLITE_OK
	goto done
done:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	Xvec0_free(tls, p)
	// If there was an error
	if rc == m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, p)
	}
	return rc
}

func _vec0Open(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(40))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint64(40))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec0Close(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	Xvec0_cursor_clear(tls, pCur)
	libsqlite3.Xsqlite3_free(tls, pCur)
	return m_SQLITE_OK
}

// C documentation
//
//	// All the different type of "values" provided to argv/argc in vec0Filter.
//	// These enums denote the use and purpose of all of them.
type Tvec0_idxstr_kind = int32

type vec0_idxstr_kind = Tvec0_idxstr_kind

const
// If any values are updated, please update the ARCHITECTURE.md docs accordingly!

_VEC0_IDXSTR_KIND_KNN_MATCH = 123
const _VEC0_IDXSTR_KIND_KNN_K = 125
const _VEC0_IDXSTR_KIND_KNN_ROWID_IN = 91
const _VEC0_IDXSTR_KIND_KNN_PARTITON_CONSTRAINT = 93
const _VEC0_IDXSTR_KIND_POINT_ID = 33
const _VEC0_IDXSTR_KIND_METADATA_CONSTRAINT = 38

// C documentation
//
//	// The different SQLITE_INDEX_CONSTRAINT values that vec0 partition key columns
//	// support, but as characters that fit nicely in idxstr.
type Tvec0_partition_operator = int32

type vec0_partition_operator = Tvec0_partition_operator

const
// If any values are updated, please update the ARCHITECTURE.md docs accordingly!

_VEC0_PARTITION_OPERATOR_EQ = 97
const _VEC0_PARTITION_OPERATOR_GT = 98
const _VEC0_PARTITION_OPERATOR_LE = 99
const _VEC0_PARTITION_OPERATOR_LT = 100
const _VEC0_PARTITION_OPERATOR_GE = 101
const _VEC0_PARTITION_OPERATOR_NE = 102

type Tvec0_metadata_operator = int32

type vec0_metadata_operator = Tvec0_metadata_operator

const _VEC0_METADATA_OPERATOR_EQ = 97
const _VEC0_METADATA_OPERATOR_GT = 98
const _VEC0_METADATA_OPERATOR_LE = 99
const _VEC0_METADATA_OPERATOR_LT = 100
const _VEC0_METADATA_OPERATOR_GE = 101
const _VEC0_METADATA_OPERATOR_NE = 102
const _VEC0_METADATA_OPERATOR_IN = 103

func _vec0BestIndex(tls *libc.TLS, pVTab uintptr, pIdxInfo uintptr) (r int32) {
	var argvIndex, hasAuxConstraint, i, i1, i2, iColumn, iColumn1, iColumn2, iKTerm, iLimitTerm, iMatchTerm, iMatchVectorTerm, iRowidInTerm, iRowidTerm, metadata_idx, op, op1, op2, partition_idx, rc, vtabIn1, v2 int32
	var idxStr, p uintptr
	var value, value1 uint8
	var vtabIn Tu8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = argvIndex, hasAuxConstraint, i, i1, i2, iColumn, iColumn1, iColumn2, iKTerm, iLimitTerm, iMatchTerm, iMatchVectorTerm, iRowidInTerm, iRowidTerm, idxStr, metadata_idx, op, op1, op2, p, partition_idx, rc, value, value1, vtabIn, vtabIn1, v2
	p = pVTab
	/**
	 * Possible query plans are:
	 * 1. KNN when:
	 *    a) An `MATCH` op on vector column
	 *    b) ORDER BY on distance column
	 *    c) LIMIT
	 *    d) rowid in (...) OPTIONAL
	 * 2. Point when:
	 *    a) An `EQ` op on rowid column
	 * 3. else: fullscan
	 *
	 */
	iMatchTerm = -int32(1)
	iMatchVectorTerm = -int32(1)
	iLimitTerm = -int32(1)
	iRowidTerm = -int32(1)
	iKTerm = -int32(1)
	iRowidInTerm = -int32(1)
	hasAuxConstraint = 0
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		vtabIn = uint8(0)
		if libsqlite3.Xsqlite3_libversion_number(tls) >= int32(3038000) {
			vtabIn = libc.Uint8FromInt32(libsqlite3.Xsqlite3_vtab_in(tls, pIdxInfo, i, -int32(1)))
		}
		if !((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fusable != 0) {
			goto _1
		}
		iColumn = (*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).FiColumn
		op = libc.Int32FromUint8((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fop)
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_LIMIT) {
			iLimitTerm = i
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_MATCH) && Xvec0_column_idx_is_vector(tls, p, iColumn) != 0 {
			if iMatchTerm > -int32(1) {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+8396, 0)
				return int32(m_SQLITE_ERROR)
			}
			iMatchTerm = i
			iMatchVectorTerm = Xvec0_column_idx_to_vector_idx(tls, p, iColumn)
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_EQ) && iColumn == m_VEC0_COLUMN_ID {
			if vtabIn != 0 {
				if iRowidInTerm != -int32(1) {
					Xvtab_set_error(tls, pVTab, __ccgo_ts+8452, 0)
					return int32(m_SQLITE_ERROR)
				}
				iRowidInTerm = i
			} else {
				iRowidTerm = i
			}
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_EQ) && iColumn == Xvec0_column_k_idx(tls, p) {
			iKTerm = i
		}
		if op != int32(m_SQLITE_INDEX_CONSTRAINT_LIMIT) && op != int32(m_SQLITE_INDEX_CONSTRAINT_OFFSET) && Xvec0_column_idx_is_auxiliary(tls, p, iColumn) != 0 {
			hasAuxConstraint = int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	idxStr = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
	if iMatchTerm >= 0 {
		if iLimitTerm < 0 && iKTerm < 0 {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+8518, 0)
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		if iLimitTerm >= 0 && iKTerm >= 0 {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+8581, 0)
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy != 0 {
			if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy > int32(1) {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+8628, 0)
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			if (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).FiColumn != Xvec0_column_distance_idx(tls, p) {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+8700, 0)
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			if (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).Fdesc != 0 {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+8794, 0)
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
		}
		if hasAuxConstraint != 0 {
			// IMP: V25623_09693
			Xvtab_set_error(tls, pVTab, __ccgo_ts+8878, 0)
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_QUERY_PLAN_KNN))
		argvIndex = int32(1)
		v2 = argvIndex
		argvIndex = argvIndex + 1
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iMatchTerm)*8))).FargvIndex = v2
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iMatchTerm)*8))).Fomit = uint8(1)
		libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_IDXSTR_KIND_KNN_MATCH))
		libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(3), uint8('_'))
		if iLimitTerm >= 0 {
			v2 = argvIndex
			argvIndex = argvIndex + 1
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iLimitTerm)*8))).FargvIndex = v2
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iLimitTerm)*8))).Fomit = uint8(1)
		} else {
			v2 = argvIndex
			argvIndex = argvIndex + 1
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iKTerm)*8))).FargvIndex = v2
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iKTerm)*8))).Fomit = uint8(1)
		}
		libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_IDXSTR_KIND_KNN_K))
		libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(3), uint8('_'))
		if iRowidInTerm >= 0 {
			// already validated as  >= SQLite 3.38 bc iRowidInTerm is only >= 0 when
			// vtabIn == 1
			libsqlite3.Xsqlite3_vtab_in(tls, pIdxInfo, iRowidInTerm, int32(1))
			v2 = argvIndex
			argvIndex = argvIndex + 1
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidInTerm)*8))).FargvIndex = v2
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidInTerm)*8))).Fomit = uint8(1)
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_IDXSTR_KIND_KNN_ROWID_IN))
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(3), uint8('_'))
		}
		i1 = 0
		for {
			if !(i1 < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
				break
			}
			if !((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i1)*12))).Fusable != 0) {
				goto _6
			}
			iColumn1 = (*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i1)*12))).FiColumn
			op1 = libc.Int32FromUint8((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i1)*12))).Fop)
			if op1 == int32(m_SQLITE_INDEX_CONSTRAINT_LIMIT) || op1 == int32(m_SQLITE_INDEX_CONSTRAINT_OFFSET) {
				goto _6
			}
			if !(Xvec0_column_idx_is_partition(tls, p, iColumn1) != 0) {
				goto _6
			}
			partition_idx = Xvec0_column_idx_to_partition_idx(tls, p, iColumn1)
			value = uint8(0)
			switch op1 {
			case int32(m_SQLITE_INDEX_CONSTRAINT_EQ):
				value = uint8(_VEC0_PARTITION_OPERATOR_EQ)
			case int32(m_SQLITE_INDEX_CONSTRAINT_GT):
				value = uint8(_VEC0_PARTITION_OPERATOR_GT)
			case int32(m_SQLITE_INDEX_CONSTRAINT_LE):
				value = uint8(_VEC0_PARTITION_OPERATOR_LE)
			case int32(m_SQLITE_INDEX_CONSTRAINT_LT):
				value = uint8(_VEC0_PARTITION_OPERATOR_LT)
			case int32(m_SQLITE_INDEX_CONSTRAINT_GE):
				value = uint8(_VEC0_PARTITION_OPERATOR_GE)
			case int32(m_SQLITE_INDEX_CONSTRAINT_NE):
				value = uint8(_VEC0_PARTITION_OPERATOR_NE)
				break
			}
			if value != 0 {
				v2 = argvIndex
				argvIndex = argvIndex + 1
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i1)*8))).FargvIndex = v2
				(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i1)*8))).Fomit = uint8(1)
				libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_IDXSTR_KIND_KNN_PARTITON_CONSTRAINT))
				libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), libc.Uint8FromInt32(int32('A')+partition_idx))
				libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), value)
				libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8('_'))
			}
			goto _6
		_6:
			;
			i1 = i1 + 1
		}
		i2 = 0
		for {
			if !(i2 < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
				break
			}
			if !((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i2)*12))).Fusable != 0) {
				goto _8
			}
			iColumn2 = (*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i2)*12))).FiColumn
			op2 = libc.Int32FromUint8((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i2)*12))).Fop)
			if op2 == int32(m_SQLITE_INDEX_CONSTRAINT_LIMIT) || op2 == int32(m_SQLITE_INDEX_CONSTRAINT_OFFSET) {
				goto _8
			}
			if !(Xvec0_column_idx_is_metadata(tls, p, iColumn2) != 0) {
				goto _8
			}
			metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, p, iColumn2)
			value1 = uint8(0)
			switch op2 {
			case int32(m_SQLITE_INDEX_CONSTRAINT_EQ):
				vtabIn1 = 0
				if libsqlite3.Xsqlite3_libversion_number(tls) >= int32(3038000) {
					vtabIn1 = libsqlite3.Xsqlite3_vtab_in(tls, pIdxInfo, i2, -int32(1))
				}
				if vtabIn1 != 0 {
					switch (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_idx)*24))).Fkind {
					case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
						fallthrough
					case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
						// IMP: V15248_32086
						rc = int32(m_SQLITE_ERROR)
						Xvtab_set_error(tls, pVTab, __ccgo_ts+8962, 0)
						goto done
					case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
						fallthrough
					case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
						break
					}
					value1 = uint8(_VEC0_METADATA_OPERATOR_IN)
					libsqlite3.Xsqlite3_vtab_in(tls, pIdxInfo, i2, int32(1))
				} else {
					value1 = uint8(_VEC0_PARTITION_OPERATOR_EQ)
				}
			case int32(m_SQLITE_INDEX_CONSTRAINT_GT):
				value1 = uint8(_VEC0_METADATA_OPERATOR_GT)
			case int32(m_SQLITE_INDEX_CONSTRAINT_LE):
				value1 = uint8(_VEC0_METADATA_OPERATOR_LE)
			case int32(m_SQLITE_INDEX_CONSTRAINT_LT):
				value1 = uint8(_VEC0_METADATA_OPERATOR_LT)
			case int32(m_SQLITE_INDEX_CONSTRAINT_GE):
				value1 = uint8(_VEC0_METADATA_OPERATOR_GE)
			case int32(m_SQLITE_INDEX_CONSTRAINT_NE):
				value1 = uint8(_VEC0_METADATA_OPERATOR_NE)
			default:
				// IMP: V16511_00582
				rc = int32(m_SQLITE_ERROR)
				Xvtab_set_error(tls, pVTab, __ccgo_ts+9032, 0)
				goto done
			}
			if (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_idx)*24))).Fkind == int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN) {
				if !(libc.Int32FromUint8(value1) == int32(_VEC0_METADATA_OPERATOR_EQ) || libc.Int32FromUint8(value1) == int32(_VEC0_METADATA_OPERATOR_NE)) {
					// IMP: V10145_26984
					rc = int32(m_SQLITE_ERROR)
					Xvtab_set_error(tls, pVTab, __ccgo_ts+9226, 0)
					goto done
				}
			}
			v2 = argvIndex
			argvIndex = argvIndex + 1
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i2)*8))).FargvIndex = v2
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i2)*8))).Fomit = uint8(1)
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_IDXSTR_KIND_METADATA_CONSTRAINT))
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), libc.Uint8FromInt32(int32('A')+metadata_idx))
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), value1)
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8('_'))
			goto _8
		_8:
			;
			i2 = i2 + 1
		}
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = iMatchVectorTerm
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(30)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
	} else {
		if iRowidTerm >= 0 {
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_QUERY_PLAN_POINT))
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).FargvIndex = int32(1)
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8))).Fomit = uint8(1)
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_IDXSTR_KIND_POINT_ID))
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(3), uint8('_'))
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = libc.Int32FromUint64((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FcolUsed)
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(10)
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
		} else {
			libsqlite3.Xsqlite3_str_appendchar(tls, idxStr, int32(1), uint8(_VEC0_QUERY_PLAN_FULLSCAN))
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(3e+06)
			(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
		}
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = libsqlite3.Xsqlite3_str_finish(tls, idxStr)
	idxStr = libc.UintptrFromInt32(0)
	if !((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr != 0) {
		rc = m_SQLITE_OK
		goto done
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = int32(1)
	rc = m_SQLITE_OK
	goto done
done:
	;
	if idxStr != 0 {
		libsqlite3.Xsqlite3_str_finish(tls, idxStr)
	}
	return rc
}

func Xmerge_sorted_lists(tls *libc.TLS, a uintptr, a_rowids uintptr, a_length Ti64, b uintptr, b_rowids uintptr, b_top_idxs uintptr, b_length Ti64, out uintptr, out_rowids uintptr, out_length Ti64, out_used uintptr) {
	var i int32
	var ptrA, ptrB Ti64
	_, _, _ = i, ptrA, ptrB
	// assert((a_length >= out_length) || (b_length >= out_length));
	ptrA = 0
	ptrB = 0
	i = 0
	for {
		if !(int64(i) < out_length) {
			break
		}
		if ptrA >= a_length && ptrB >= b_length {
			*(*Ti64)(unsafe.Pointer(out_used)) = int64(i)
			return
		}
		if ptrA >= a_length {
			*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(b + uintptr(*(*Ti32)(unsafe.Pointer(b_top_idxs + uintptr(ptrB)*4)))*4))
			*(*Ti64)(unsafe.Pointer(out_rowids + uintptr(i)*8)) = *(*Ti64)(unsafe.Pointer(b_rowids + uintptr(*(*Ti32)(unsafe.Pointer(b_top_idxs + uintptr(ptrB)*4)))*8))
			ptrB = ptrB + 1
		} else {
			if ptrB >= b_length {
				*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(a + uintptr(ptrA)*4))
				*(*Ti64)(unsafe.Pointer(out_rowids + uintptr(i)*8)) = *(*Ti64)(unsafe.Pointer(a_rowids + uintptr(ptrA)*8))
				ptrA = ptrA + 1
			} else {
				if *(*Tf32)(unsafe.Pointer(a + uintptr(ptrA)*4)) <= *(*Tf32)(unsafe.Pointer(b + uintptr(*(*Ti32)(unsafe.Pointer(b_top_idxs + uintptr(ptrB)*4)))*4)) {
					*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(a + uintptr(ptrA)*4))
					*(*Ti64)(unsafe.Pointer(out_rowids + uintptr(i)*8)) = *(*Ti64)(unsafe.Pointer(a_rowids + uintptr(ptrA)*8))
					ptrA = ptrA + 1
				} else {
					*(*Tf32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*Tf32)(unsafe.Pointer(b + uintptr(*(*Ti32)(unsafe.Pointer(b_top_idxs + uintptr(ptrB)*4)))*4))
					*(*Ti64)(unsafe.Pointer(out_rowids + uintptr(i)*8)) = *(*Ti64)(unsafe.Pointer(b_rowids + uintptr(*(*Ti32)(unsafe.Pointer(b_top_idxs + uintptr(ptrB)*4)))*8))
					ptrB = ptrB + 1
				}
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	*(*Ti64)(unsafe.Pointer(out_used)) = out_length
}

func Xbitmap_new(tls *libc.TLS, n Ti32) (r uintptr) {
	var p uintptr
	_ = p
	p = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt32(n)*uint64(1)/uint64(m_CHAR_BIT)))
	if p != 0 {
		libc.Xmemset(tls, p, 0, libc.Uint64FromInt32(n)*uint64(1)/uint64(m_CHAR_BIT))
	}
	return p
}

func Xbitmap_new_from(tls *libc.TLS, n Ti32, from uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt32(n)*uint64(1)/uint64(m_CHAR_BIT)))
	if p != 0 {
		libc.Xmemcpy(tls, p, from, libc.Uint64FromInt32(n/int32(m_CHAR_BIT)))
	}
	return p
}

func Xbitmap_copy(tls *libc.TLS, base uintptr, from uintptr, n Ti32) {
	libc.Xmemcpy(tls, base, from, libc.Uint64FromInt32(n/int32(m_CHAR_BIT)))
}

func Xbitmap_and_inplace(tls *libc.TLS, base uintptr, other uintptr, n Ti32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < n/int32(m_CHAR_BIT)) {
			break
		}
		*(*Tu8)(unsafe.Pointer(base + uintptr(i))) = libc.Uint8FromInt32(libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(base + uintptr(i)))) & libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(other + uintptr(i)))))
		goto _1
	_1:
		;
		i = i + 1
	}
}

func Xbitmap_set(tls *libc.TLS, bitmap uintptr, position Ti32, value int32) {
	var v1 uintptr
	_ = v1
	if value != 0 {
		v1 = bitmap + uintptr(position/int32(m_CHAR_BIT))
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(1)<<(position%libc.Int32FromInt32(m_CHAR_BIT)))
	} else {
		v1 = bitmap + uintptr(position/int32(m_CHAR_BIT))
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(1) << (position % libc.Int32FromInt32(m_CHAR_BIT))))
	}
}

func Xbitmap_get(tls *libc.TLS, bitmap uintptr, position Ti32) (r int32) {
	return libc.Int32FromUint8(*(*Tu8)(unsafe.Pointer(bitmap + uintptr(position/int32(m_CHAR_BIT))))) >> (position % int32(m_CHAR_BIT)) & int32(1)
}

func Xbitmap_clear(tls *libc.TLS, bitmap uintptr, n Ti32) {
	libc.Xmemset(tls, bitmap, 0, libc.Uint64FromInt32(n/int32(m_CHAR_BIT)))
}

func Xbitmap_fill(tls *libc.TLS, bitmap uintptr, n Ti32) {
	libc.Xmemset(tls, bitmap, int32(0xFF), libc.Uint64FromInt32(n/int32(m_CHAR_BIT)))
}

// C documentation
//
//	/**
//	 * @brief Finds the minimum k items in distances, and writes the indicies to
//	 * out.
//	 *
//	 * @param distances input f32 array of size n, the items to consider.
//	 * @param n: size of distances array.
//	 * @param out: Output array of size k, will contain at most k element indicies
//	 * @param k: Size of output array
//	 * @return int
//	 */
func Xmin_idx(tls *libc.TLS, distances uintptr, n Ti32, candidates uintptr, out uintptr, k Ti32, bTaken uintptr, k_used uintptr) (r int32) {
	var i, ik, min_idx int32
	_, _, _ = i, ik, min_idx
	Xbitmap_clear(tls, bTaken, n)
	ik = 0
	for {
		if !(ik < k) {
			break
		}
		min_idx = 0
		for min_idx < n && (Xbitmap_get(tls, bTaken, min_idx) != 0 || !(Xbitmap_get(tls, candidates, min_idx) != 0)) {
			min_idx = min_idx + 1
		}
		if min_idx >= n {
			*(*Ti32)(unsafe.Pointer(k_used)) = ik
			return m_SQLITE_OK
		}
		i = 0
		for {
			if !(i < n) {
				break
			}
			if *(*Tf32)(unsafe.Pointer(distances + uintptr(i)*4)) <= *(*Tf32)(unsafe.Pointer(distances + uintptr(min_idx)*4)) && !(Xbitmap_get(tls, bTaken, i) != 0) && Xbitmap_get(tls, candidates, i) != 0 {
				min_idx = i
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		*(*Ti32)(unsafe.Pointer(out + uintptr(ik)*4)) = min_idx
		Xbitmap_set(tls, bTaken, min_idx, int32(1))
		goto _1
	_1:
		;
		ik = ik + 1
	}
	*(*Ti32)(unsafe.Pointer(k_used)) = k
	return m_SQLITE_OK
}

func Xvec0_get_metadata_text_long_value(tls *libc.TLS, p uintptr, stmt uintptr, metadata_idx int32, rowid Ti64, n uintptr, s uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	_, _ = rc, zSql
	if !(*(*uintptr)(unsafe.Pointer(stmt)) != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+9312, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_idx))
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto done
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), stmt, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			goto done
		}
	}
	libsqlite3.Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(stmt)))
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(stmt)), int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(stmt)))
	if rc != int32(m_SQLITE_ROW) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	*(*uintptr)(unsafe.Pointer(s)) = libsqlite3.Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(stmt)), 0)
	*(*int32)(unsafe.Pointer(n)) = libsqlite3.Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(stmt)), 0)
	rc = m_SQLITE_OK
	goto done
done:
	;
	return rc
	return r
}

// C documentation
//
//	/**
//	 * @brief Crete at "iterator" (sqlite3_stmt) of chunks with the given constraints
//	 *
//	 * Any VEC0_IDXSTR_KIND_KNN_PARTITON_CONSTRAINT values in idxStr/argv will be applied
//	 * as WHERE constraints in the underlying stmt SQL, and any consumer of the stmt
//	 * can freely step through the stmt with all constraints satisfied.
//	 *
//	 * @param p - vec0_vtab
//	 * @param idxStr - the xBestIndex/xFilter idxstr containing VEC0_IDXSTR values
//	 * @param argc - number of argv values from xFilter
//	 * @param argv - array of sqlite3_value from xFilter
//	 * @param outStmt - output sqlite3_stmt of chunks with all filters applied
//	 * @return int SQLITE_OK on success, error code otherwise
//	 */
func Xvec0_chunks_iter(tls *libc.TLS, p uintptr, idxStr uintptr, argc int32, argv uintptr, outStmt uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var appendedWhere, i, i1, idx, idx1, idxStrLength, n, numValueEntries, operator, partition_idx, rc, v3 int32
	var kind, kind1 uint8
	var s, zSql, zSql1 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = appendedWhere, i, i1, idx, idx1, idxStrLength, kind, kind1, n, numValueEntries, operator, partition_idx, rc, s, zSql, zSql1, v3
	// always null terminated, enforced by SQLite
	idxStrLength = libc.Int32FromUint64(libc.Xstrlen(tls, idxStr))
	// "1" refers to the initial vec0_query_plan char, 4 is the number of chars per "element"
	numValueEntries = (idxStrLength - int32(1)) / int32(4)
	s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+9372, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	appendedWhere = 0
	i = 0
	for {
		if !(i < numValueEntries) {
			break
		}
		idx = int32(1) + i*int32(4)
		kind = *(*uint8)(unsafe.Pointer(idxStr + uintptr(idx+0)))
		if libc.Int32FromUint8(kind) != int32(_VEC0_IDXSTR_KIND_KNN_PARTITON_CONSTRAINT) {
			goto _1
		}
		partition_idx = libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(idx+int32(1))))) - int32('A')
		operator = libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(idx+int32(2)))))
		// idxStr[idx + 3] is just null, a '_' placeholder
		if !(appendedWhere != 0) {
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+9429)
			appendedWhere = int32(1)
		} else {
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+4151)
		}
		switch operator {
		case int32(_VEC0_PARTITION_OPERATOR_EQ):
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+4157, libc.VaList(bp+8, partition_idx))
		case int32(_VEC0_PARTITION_OPERATOR_GT):
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+9437, libc.VaList(bp+8, partition_idx))
		case int32(_VEC0_PARTITION_OPERATOR_LE):
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+9457, libc.VaList(bp+8, partition_idx))
		case int32(_VEC0_PARTITION_OPERATOR_LT):
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+9478, libc.VaList(bp+8, partition_idx))
		case int32(_VEC0_PARTITION_OPERATOR_GE):
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+9498, libc.VaList(bp+8, partition_idx))
		case int32(_VEC0_PARTITION_OPERATOR_NE):
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+9519, libc.VaList(bp+8, partition_idx))
		default:
			zSql = libsqlite3.Xsqlite3_str_finish(tls, s)
			libsqlite3.Xsqlite3_free(tls, zSql)
			return int32(m_SQLITE_ERROR)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	zSql1 = libsqlite3.Xsqlite3_str_finish(tls, s)
	if !(zSql1 != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql1, -int32(1), outStmt, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql1)
	if rc != m_SQLITE_OK {
		return rc
	}
	n = int32(1)
	i1 = 0
	for {
		if !(i1 < numValueEntries) {
			break
		}
		idx1 = int32(1) + i1*int32(4)
		kind1 = *(*uint8)(unsafe.Pointer(idxStr + uintptr(idx1+0)))
		if libc.Int32FromUint8(kind1) != int32(_VEC0_IDXSTR_KIND_KNN_PARTITON_CONSTRAINT) {
			goto _2
		}
		v3 = n
		n = n + 1
		libsqlite3.Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(outStmt)), v3, *(*uintptr)(unsafe.Pointer(argv + uintptr(i1)*8)))
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	return rc
}

// a single `xxx in (...)` constraint on a metadata column. TEXT or INTEGER only for now.
type TVec0MetadataIn = struct {
	Fargv_idx     int32
	Fmetadata_idx int32
	Farray        TArray
}

type Vec0MetadataIn = TVec0MetadataIn

// Array elements for `xxx in (...)` values for a text column. basically just a string
type TVec0MetadataInTextEntry = struct {
	Fn       int32
	FzString uintptr
}

type Vec0MetadataInTextEntry = TVec0MetadataInTextEntry

func Xvec0_metadata_filter_text(tls *libc.TLS, p uintptr, value uintptr, buffer uintptr, size int32, op Tvec0_metadata_operator, b uintptr, metadata_idx int32, chunk_rowid int32, aMetadataIn uintptr, argv_idx int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aTarget, entry, metadataIn, metadataIn1, rowids, sPrefix, sPrefix1, sTarget, view, view1 uintptr
	var cmpPrefix, cmpPrefix1, cmpPrefix2, cmpPrefix3, cmpPrefix4, cmpPrefix5, cmpPrefix6, i, i1, i2, i3, i4, i5, i7, nPrefix, nPrefix1, nTarget, rc, v10, v12, v14 int32
	var i6, metadataInIdx, target_idx Tsize_t
	var _ /* nFull at bp+24 */ int32
	var _ /* nFull at bp+40 */ int32
	var _ /* rowidsBlob at bp+8 */ uintptr
	var _ /* sFull at bp+16 */ uintptr
	var _ /* sFull at bp+32 */ uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aTarget, cmpPrefix, cmpPrefix1, cmpPrefix2, cmpPrefix3, cmpPrefix4, cmpPrefix5, cmpPrefix6, entry, i, i1, i2, i3, i4, i5, i6, i7, metadataIn, metadataIn1, metadataInIdx, nPrefix, nPrefix1, nTarget, rc, rowids, sPrefix, sPrefix1, sTarget, target_idx, view, view1, v10, v12, v14
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	rowids = libc.UintptrFromInt32(0)
	sTarget = libsqlite3.Xsqlite3_value_text(tls, value)
	nTarget = libsqlite3.Xsqlite3_value_bytes(tls, value)
	// TODO(perf): only text metadata news the rowids BLOB. Make it so that
	// rowids BLOB is re-used when multiple fitlers on text columns,
	// ex "name BETWEEN 'a' and 'b'""
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+9540, int64(chunk_rowid), 0, bp+8)
	if rc != m_SQLITE_OK {
		return rc
	}
	rowids = libsqlite3.Xsqlite3_malloc(tls, libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 8))))
	if !(rowids != 0) {
		libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), rowids, libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 8))), 0)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		return rc
	}
	libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	switch op {
	case int32(_VEC0_METADATA_OPERATOR_EQ):
		goto _1
	case int32(_VEC0_METADATA_OPERATOR_NE):
		goto _2
	case int32(_VEC0_METADATA_OPERATOR_GT):
		goto _3
	case int32(_VEC0_METADATA_OPERATOR_GE):
		goto _4
	case int32(_VEC0_METADATA_OPERATOR_LE):
		goto _5
	case int32(_VEC0_METADATA_OPERATOR_LT):
		goto _6
	case int32(_VEC0_METADATA_OPERATOR_IN):
		goto _7
	}
	goto _8
_1:
	;
	i = 0
	for {
		if !(i < size) {
			break
		}
		view = buffer + uintptr(i*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = *(*int32)(unsafe.Pointer(view))
		sPrefix = view + 4
		// for EQ the text lengths must match
		if nPrefix != nTarget {
			Xbitmap_set(tls, b, i, 0)
			goto _9
		}
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v10 = nPrefix
		} else {
			v10 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		cmpPrefix = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		// for short strings, use the prefix comparison direclty
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			Xbitmap_set(tls, b, i, libc.BoolInt32(cmpPrefix == 0))
			goto _9
		}
		// for EQ on longs strings, the prefix must match
		if cmpPrefix != 0 {
			Xbitmap_set(tls, b, i, 0)
			goto _9
		}
		// consult the full string
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != *(*int32)(unsafe.Pointer(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i, libc.BoolInt32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), sTarget, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 24)))) == 0))
		goto _9
	_9:
		;
		i = i + 1
	}
	goto _8
_2:
	;
	i1 = 0
	for {
		if !(i1 < size) {
			break
		}
		view = buffer + uintptr(i1*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = *(*int32)(unsafe.Pointer(view))
		sPrefix = view + 4
		// for NE if text lengths dont match, it never will
		if nPrefix != nTarget {
			Xbitmap_set(tls, b, i1, int32(1))
			goto _11
		}
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v10 = nPrefix
		} else {
			v10 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		cmpPrefix1 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		// for short strings, use the prefix comparison direclty
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			Xbitmap_set(tls, b, i1, libc.BoolInt32(cmpPrefix1 != 0))
			goto _11
		}
		// for NE on longs strings, if prefixes dont match, then long string wont
		if cmpPrefix1 != 0 {
			Xbitmap_set(tls, b, i1, int32(1))
			goto _11
		}
		// consult the full string
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i1)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != *(*int32)(unsafe.Pointer(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i1, libc.BoolInt32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), sTarget, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 24)))) != 0))
		goto _11
	_11:
		;
		i1 = i1 + 1
	}
	goto _8
_3:
	;
	i2 = 0
	for {
		if !(i2 < size) {
			break
		}
		view = buffer + uintptr(i2*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = *(*int32)(unsafe.Pointer(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix2 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix2 == 0 {
				Xbitmap_set(tls, b, i2, libc.BoolInt32(nPrefix > nTarget))
			} else {
				Xbitmap_set(tls, b, i2, libc.BoolInt32(cmpPrefix2 > 0))
			}
			goto _13
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i2)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != *(*int32)(unsafe.Pointer(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i2, libc.BoolInt32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), sTarget, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 24)))) > 0))
		goto _13
	_13:
		;
		i2 = i2 + 1
	}
	goto _8
_4:
	;
	i3 = 0
	for {
		if !(i3 < size) {
			break
		}
		view = buffer + uintptr(i3*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = *(*int32)(unsafe.Pointer(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix3 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix3 == 0 {
				Xbitmap_set(tls, b, i3, libc.BoolInt32(nPrefix >= nTarget))
			} else {
				Xbitmap_set(tls, b, i3, libc.BoolInt32(cmpPrefix3 >= 0))
			}
			goto _17
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i3)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != *(*int32)(unsafe.Pointer(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i3, libc.BoolInt32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), sTarget, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 24)))) >= 0))
		goto _17
	_17:
		;
		i3 = i3 + 1
	}
	goto _8
_5:
	;
	i4 = 0
	for {
		if !(i4 < size) {
			break
		}
		view = buffer + uintptr(i4*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = *(*int32)(unsafe.Pointer(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix4 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix4 == 0 {
				Xbitmap_set(tls, b, i4, libc.BoolInt32(nPrefix <= nTarget))
			} else {
				Xbitmap_set(tls, b, i4, libc.BoolInt32(cmpPrefix4 <= 0))
			}
			goto _21
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i4)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != *(*int32)(unsafe.Pointer(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i4, libc.BoolInt32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), sTarget, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 24)))) <= 0))
		goto _21
	_21:
		;
		i4 = i4 + 1
	}
	goto _8
_6:
	;
	i5 = 0
	for {
		if !(i5 < size) {
			break
		}
		view = buffer + uintptr(i5*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = *(*int32)(unsafe.Pointer(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix5 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix5 == 0 {
				Xbitmap_set(tls, b, i5, libc.BoolInt32(nPrefix < nTarget))
			} else {
				Xbitmap_set(tls, b, i5, libc.BoolInt32(cmpPrefix5 < 0))
			}
			goto _25
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i5)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != *(*int32)(unsafe.Pointer(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i5, libc.BoolInt32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), sTarget, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 24)))) < 0))
		goto _25
	_25:
		;
		i5 = i5 + 1
	}
	goto _8
_7:
	;
	metadataInIdx = libc.Uint64FromInt32(-libc.Int32FromInt32(1))
	i6 = uint64(0)
	for {
		if !(i6 < (*TArray)(unsafe.Pointer(aMetadataIn)).Flength) {
			break
		}
		metadataIn = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(i6)*40
		if (*TVec0MetadataIn)(unsafe.Pointer(metadataIn)).Fargv_idx == argv_idx {
			metadataInIdx = i6
			break
		}
		goto _29
	_29:
		;
		i6 = i6 + 1
	}
	if metadataInIdx < uint64(0) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	metadataIn1 = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(metadataInIdx)*40
	aTarget = metadataIn1 + 8
	i7 = 0
	for {
		if !(i7 < size) {
			break
		}
		view1 = buffer + uintptr(i7*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix1 = *(*int32)(unsafe.Pointer(view1))
		sPrefix1 = view1 + 4
		target_idx = uint64(0)
		for {
			if !(target_idx < (*TArray)(unsafe.Pointer(aTarget)).Flength) {
				break
			}
			entry = (*TArray)(unsafe.Pointer(aTarget)).Fz + uintptr(target_idx)*16
			if (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).Fn != nPrefix1 {
				goto _31
			}
			if nPrefix1 <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v10 = nPrefix1
			} else {
				v10 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			cmpPrefix6 = libc.Xstrncmp(tls, sPrefix1, (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).FzString, libc.Uint64FromInt32(v10))
			if nPrefix1 <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				if cmpPrefix6 == 0 {
					Xbitmap_set(tls, b, i7, int32(1))
					break
				}
				goto _31
			}
			if cmpPrefix6 != 0 {
				goto _31
			}
			rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, *(*Ti64)(unsafe.Pointer(rowids + uintptr(i7)*8)), bp+40, bp+32)
			if rc != m_SQLITE_OK {
				goto done
			}
			if nPrefix1 != *(*int32)(unsafe.Pointer(bp + 40)) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			if libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(bp + 32)), (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).FzString, libc.Uint64FromInt32(*(*int32)(unsafe.Pointer(bp + 40)))) == 0 {
				Xbitmap_set(tls, b, i7, int32(1))
				break
			}
			goto _31
		_31:
			;
			target_idx = target_idx + 1
		}
		goto _30
	_30:
		;
		i7 = i7 + 1
	}
	goto _8
_8:
	;
	rc = m_SQLITE_OK
	goto done
done:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	libsqlite3.Xsqlite3_free(tls, rowids)
	return rc
}

// C documentation
//
//	/**
//	 * @brief Fill in bitmap of chunk values, whether or not the values match a metadata constraint
//	 *
//	 * @param p vec0_vtab
//	 * @param metadata_idx index of the metatadata column to perfrom constraints on
//	 * @param value sqlite3_value of the constraints value
//	 * @param blob sqlite3_blob that is already opened on the metdata column's shadow chunk table
//	 * @param chunk_rowid rowid of the chunk to calculate on
//	 * @param b pre-allocated and zero'd out bitmap to write results to
//	 * @param size size of the chunk
//	 * @return int SQLITE_OK on success, error code otherwise
//	 */
func Xvec0_set_metadata_filter_bitmap(tls *libc.TLS, p uintptr, metadata_idx int32, op Tvec0_metadata_operator, value uintptr, blob uintptr, chunk_rowid Ti64, b uintptr, size int32, aMetadataIn uintptr, argv_idx int32) (r int32) {
	var aTarget, array, array1, buffer, metadataIn, metadataIn1 uintptr
	var blobSize, i, i1, i10, i11, i12, i13, i14, i15, i2, i3, i4, i5, i6, i7, i9, metadataInIdx, rc, szMatch, target int32
	var i8, target_idx Tsize_t
	var kind Tvec0_metadata_column_kind
	var target1 Ti64
	var target2 float64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aTarget, array, array1, blobSize, buffer, i, i1, i10, i11, i12, i13, i14, i15, i2, i3, i4, i5, i6, i7, i8, i9, kind, metadataIn, metadataIn1, metadataInIdx, rc, szMatch, target, target1, target2, target_idx
	rc = libsqlite3.Xsqlite3_blob_reopen(tls, blob, chunk_rowid)
	if rc != m_SQLITE_OK {
		return rc
	}
	kind = (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_idx)*24))).Fkind
	szMatch = 0
	blobSize = libsqlite3.Xsqlite3_blob_bytes(tls, blob)
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		szMatch = libc.BoolInt32(blobSize == size/int32(m_CHAR_BIT))
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		szMatch = libc.BoolInt32(libc.Uint64FromInt32(blobSize) == libc.Uint64FromInt32(size)*uint64(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		szMatch = libc.BoolInt32(libc.Uint64FromInt32(blobSize) == libc.Uint64FromInt32(size)*uint64(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		szMatch = libc.BoolInt32(blobSize == size*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		break
	}
	if !(szMatch != 0) {
		return int32(m_SQLITE_ERROR)
	}
	buffer = libsqlite3.Xsqlite3_malloc(tls, blobSize)
	if !(buffer != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, blob, buffer, blobSize, 0)
	if rc != m_SQLITE_OK {
		goto done
	}
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		target = libsqlite3.Xsqlite3_value_int(tls, value)
		if target != 0 && op == int32(_VEC0_METADATA_OPERATOR_EQ) || !(target != 0) && op == int32(_VEC0_METADATA_OPERATOR_NE) {
			i = 0
			for {
				if !(i < size) {
					break
				}
				Xbitmap_set(tls, b, i, Xbitmap_get(tls, buffer, i))
				goto _1
			_1:
				;
				i = i + 1
			}
		} else {
			i1 = 0
			for {
				if !(i1 < size) {
					break
				}
				Xbitmap_set(tls, b, i1, libc.BoolInt32(!(Xbitmap_get(tls, buffer, i1) != 0)))
				goto _2
			_2:
				;
				i1 = i1 + 1
			}
		}
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		array = buffer
		target1 = libsqlite3.Xsqlite3_value_int64(tls, value)
		switch op {
		case int32(_VEC0_METADATA_OPERATOR_EQ):
			i2 = 0
			for {
				if !(i2 < size) {
					break
				}
				Xbitmap_set(tls, b, i2, libc.BoolInt32(*(*Ti64)(unsafe.Pointer(array + uintptr(i2)*8)) == target1))
				goto _3
			_3:
				;
				i2 = i2 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_GT):
			i3 = 0
			for {
				if !(i3 < size) {
					break
				}
				Xbitmap_set(tls, b, i3, libc.BoolInt32(*(*Ti64)(unsafe.Pointer(array + uintptr(i3)*8)) > target1))
				goto _4
			_4:
				;
				i3 = i3 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_LE):
			i4 = 0
			for {
				if !(i4 < size) {
					break
				}
				Xbitmap_set(tls, b, i4, libc.BoolInt32(*(*Ti64)(unsafe.Pointer(array + uintptr(i4)*8)) <= target1))
				goto _5
			_5:
				;
				i4 = i4 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_LT):
			i5 = 0
			for {
				if !(i5 < size) {
					break
				}
				Xbitmap_set(tls, b, i5, libc.BoolInt32(*(*Ti64)(unsafe.Pointer(array + uintptr(i5)*8)) < target1))
				goto _6
			_6:
				;
				i5 = i5 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_GE):
			i6 = 0
			for {
				if !(i6 < size) {
					break
				}
				Xbitmap_set(tls, b, i6, libc.BoolInt32(*(*Ti64)(unsafe.Pointer(array + uintptr(i6)*8)) >= target1))
				goto _7
			_7:
				;
				i6 = i6 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_NE):
			i7 = 0
			for {
				if !(i7 < size) {
					break
				}
				Xbitmap_set(tls, b, i7, libc.BoolInt32(*(*Ti64)(unsafe.Pointer(array + uintptr(i7)*8)) != target1))
				goto _8
			_8:
				;
				i7 = i7 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_IN):
			metadataInIdx = -int32(1)
			i8 = uint64(0)
			for {
				if !(i8 < (*TArray)(unsafe.Pointer(aMetadataIn)).Flength) {
					break
				}
				metadataIn = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(i8)*40
				if (*TVec0MetadataIn)(unsafe.Pointer(metadataIn)).Fargv_idx == argv_idx {
					metadataInIdx = libc.Int32FromUint64(i8)
					break
				}
				goto _9
			_9:
				;
				i8 = i8 + 1
			}
			if metadataInIdx < 0 {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			metadataIn1 = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(metadataInIdx)*40
			aTarget = metadataIn1 + 8
			i9 = 0
			for {
				if !(i9 < size) {
					break
				}
				target_idx = uint64(0)
				for {
					if !(target_idx < (*TArray)(unsafe.Pointer(aTarget)).Flength) {
						break
					}
					if *(*Ti64)(unsafe.Pointer((*TArray)(unsafe.Pointer(aTarget)).Fz + uintptr(target_idx)*8)) == *(*Ti64)(unsafe.Pointer(array + uintptr(i9)*8)) {
						Xbitmap_set(tls, b, i9, int32(1))
						break
					}
					goto _11
				_11:
					;
					target_idx = target_idx + 1
				}
				goto _10
			_10:
				;
				i9 = i9 + 1
			}
			break
		}
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		array1 = buffer
		target2 = libsqlite3.Xsqlite3_value_double(tls, value)
		switch op {
		case int32(_VEC0_METADATA_OPERATOR_EQ):
			i10 = 0
			for {
				if !(i10 < size) {
					break
				}
				Xbitmap_set(tls, b, i10, libc.BoolInt32(*(*float64)(unsafe.Pointer(array1 + uintptr(i10)*8)) == target2))
				goto _12
			_12:
				;
				i10 = i10 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_GT):
			i11 = 0
			for {
				if !(i11 < size) {
					break
				}
				Xbitmap_set(tls, b, i11, libc.BoolInt32(*(*float64)(unsafe.Pointer(array1 + uintptr(i11)*8)) > target2))
				goto _13
			_13:
				;
				i11 = i11 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_LE):
			i12 = 0
			for {
				if !(i12 < size) {
					break
				}
				Xbitmap_set(tls, b, i12, libc.BoolInt32(*(*float64)(unsafe.Pointer(array1 + uintptr(i12)*8)) <= target2))
				goto _14
			_14:
				;
				i12 = i12 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_LT):
			i13 = 0
			for {
				if !(i13 < size) {
					break
				}
				Xbitmap_set(tls, b, i13, libc.BoolInt32(*(*float64)(unsafe.Pointer(array1 + uintptr(i13)*8)) < target2))
				goto _15
			_15:
				;
				i13 = i13 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_GE):
			i14 = 0
			for {
				if !(i14 < size) {
					break
				}
				Xbitmap_set(tls, b, i14, libc.BoolInt32(*(*float64)(unsafe.Pointer(array1 + uintptr(i14)*8)) >= target2))
				goto _16
			_16:
				;
				i14 = i14 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_NE):
			i15 = 0
			for {
				if !(i15 < size) {
					break
				}
				Xbitmap_set(tls, b, i15, libc.BoolInt32(*(*float64)(unsafe.Pointer(array1 + uintptr(i15)*8)) != target2))
				goto _17
			_17:
				;
				i15 = i15 + 1
			}
		case int32(_VEC0_METADATA_OPERATOR_IN):
			// should never be reached
			break
		}
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		rc = Xvec0_metadata_filter_text(tls, p, value, buffer, size, op, b, metadata_idx, int32(chunk_rowid), aMetadataIn, argv_idx)
		if rc != m_SQLITE_OK {
			goto done
		}
		break
	}
	goto done
done:
	;
	libsqlite3.Xsqlite3_free(tls, buffer)
	return rc
}

func Xvec0Filter_knn_chunks_iter(tls *libc.TLS, p uintptr, stmtChunks uintptr, vector_column uintptr, vectorColumnIdx int32, arrayRowidsIn uintptr, aMetadataIn uintptr, idxStr uintptr, argc int32, argv uintptr, queryVector uintptr, k Ti64, out_topk_rowids uintptr, out_topk_distances uintptr, out_used uintptr) (r int32) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var b, bTaken, baseVectors, base_i, base_i1, base_i2, bmMetadata, bmRowids, chunkRowids, chunkValidity, chunk_distances, chunk_topk_idxs, in, tmp_topk_distances, tmp_topk_rowids, topk_distances, topk_rowids, v1 uintptr
	var baseVectorsSize, chunk_id, currentBaseVectorsSize, expectedBaseVectorsSize, k_used, rowidsSize, validitySize Ti64
	var hasMetadataFilters, i, i1, i2, i3, i4, i5, idx, idx1, idxStrLength, metadata_idx, numValueEntries, operator, rc, v4 int32
	var kind, kind1 uint8
	var result Tf32
	var v7, v8, v9 int64
	var _ /* blobVectors at bp+0 */ uintptr
	var _ /* metadataBlobs at bp+8 */ [16]uintptr
	var _ /* rowid at bp+136 */ Ti64
	var _ /* used at bp+152 */ Ti64
	var _ /* used1 at bp+144 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, bTaken, baseVectors, baseVectorsSize, base_i, base_i1, base_i2, bmMetadata, bmRowids, chunkRowids, chunkValidity, chunk_distances, chunk_id, chunk_topk_idxs, currentBaseVectorsSize, expectedBaseVectorsSize, hasMetadataFilters, i, i1, i2, i3, i4, i5, idx, idx1, idxStrLength, in, k_used, kind, kind1, metadata_idx, numValueEntries, operator, rc, result, rowidsSize, tmp_topk_distances, tmp_topk_rowids, topk_distances, topk_rowids, validitySize, v1, v4, v7, v8, v9
	// for each chunk, get top min(k, chunk_size) rowid + distances to query vec.
	// then reconcile all topk_chunks for a true top k.
	// output only rowids + distances for now
	rc = m_SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	baseVectors = libc.UintptrFromInt32(0) // memory: chunk_size * dimensions * element_size
	// OWNED BY CALLER ON SUCCESS
	topk_rowids = libc.UintptrFromInt32(0) // memory: k * 4
	// OWNED BY CALLER ON SUCCESS
	topk_distances = libc.UintptrFromInt32(0)     // memory: k * 4
	tmp_topk_rowids = libc.UintptrFromInt32(0)    // memory: k * 4
	tmp_topk_distances = libc.UintptrFromInt32(0) // memory: k * 4
	chunk_distances = libc.UintptrFromInt32(0)    // memory: chunk_size * 4
	b = libc.UintptrFromInt32(0)                  // memory: chunk_size / 8
	bTaken = libc.UintptrFromInt32(0)             // memory: chunk_size / 8
	chunk_topk_idxs = libc.UintptrFromInt32(0)    // memory: k * 4
	bmRowids = libc.UintptrFromInt32(0)           // memory: chunk_size / 8
	bmMetadata = libc.UintptrFromInt32(0)         // memory: chunk_size / 8
	//                        // total: a lot???
	// 6 * (k * 4) + (k * 2) + (chunk_size / 8) + (chunk_size * dimensions * 4)
	topk_rowids = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(k)*uint64(8)))
	if !(topk_rowids != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	libc.Xmemset(tls, topk_rowids, 0, uint64(libc.Uint64FromInt64(k)*uint64(8)))
	topk_distances = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(k)*uint64(4)))
	if !(topk_distances != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	libc.Xmemset(tls, topk_distances, 0, uint64(libc.Uint64FromInt64(k)*uint64(4)))
	tmp_topk_rowids = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(k)*uint64(8)))
	if !(tmp_topk_rowids != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	libc.Xmemset(tls, tmp_topk_rowids, 0, uint64(libc.Uint64FromInt64(k)*uint64(8)))
	tmp_topk_distances = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(k)*uint64(4)))
	if !(tmp_topk_distances != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	libc.Xmemset(tls, tmp_topk_distances, 0, uint64(libc.Uint64FromInt64(k)*uint64(4)))
	k_used = 0
	baseVectorsSize = libc.Int64FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) * Xvector_column_byte_size(tls, *(*TVectorColumnDefinition)(unsafe.Pointer(vector_column))))
	baseVectors = libsqlite3.Xsqlite3_malloc(tls, int32(baseVectorsSize))
	if !(baseVectors != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	chunk_distances = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)*uint64(4)))
	if !(chunk_distances != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	b = Xbitmap_new(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
	if !(b != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	bTaken = Xbitmap_new(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
	if !(bTaken != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	chunk_topk_idxs = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(k)*uint64(4)))
	if !(chunk_topk_idxs != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	if arrayRowidsIn != 0 {
		v1 = Xbitmap_new(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
	} else {
		v1 = libc.UintptrFromInt32(0)
	}
	bmRowids = v1
	if arrayRowidsIn != 0 && !(bmRowids != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	libc.Xmemset(tls, bp+8, 0, libc.Uint64FromInt64(8)*libc.Uint64FromInt32(m_VEC0_MAX_METADATA_COLUMNS))
	bmMetadata = Xbitmap_new(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
	if !(bmMetadata != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	idxStrLength = libc.Int32FromUint64(libc.Xstrlen(tls, idxStr))
	numValueEntries = (idxStrLength - int32(1)) / int32(4)
	hasMetadataFilters = 0
	i = 0
	for {
		if !(i < argc) {
			break
		}
		idx = int32(1) + i*int32(4)
		kind = *(*uint8)(unsafe.Pointer(idxStr + uintptr(idx+0)))
		if libc.Int32FromUint8(kind) == int32(_VEC0_IDXSTR_KIND_METADATA_CONSTRAINT) {
			hasMetadataFilters = int32(1)
			break
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	for int32(m_true) != 0 {
		rc = libsqlite3.Xsqlite3_step(tls, stmtChunks)
		if rc == int32(m_SQLITE_DONE) {
			break
		}
		if rc != int32(m_SQLITE_ROW) {
			Xvtab_set_error(tls, p, __ccgo_ts+9547, 0)
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		libc.Xmemset(tls, chunk_distances, 0, libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)*uint64(4))
		libc.Xmemset(tls, chunk_topk_idxs, 0, uint64(libc.Uint64FromInt64(k)*uint64(4)))
		Xbitmap_clear(tls, b, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
		chunk_id = libsqlite3.Xsqlite3_column_int64(tls, stmtChunks, 0)
		chunkValidity = libsqlite3.Xsqlite3_column_blob(tls, stmtChunks, int32(1))
		validitySize = int64(libsqlite3.Xsqlite3_column_bytes(tls, stmtChunks, int32(1)))
		if validitySize != int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/int32(m_CHAR_BIT)) {
			// IMP: V05271_22109
			Xvtab_set_error(tls, p, __ccgo_ts+9565, libc.VaList(bp+168, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/int32(m_CHAR_BIT), validitySize))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		chunkRowids = libsqlite3.Xsqlite3_column_blob(tls, stmtChunks, int32(2))
		rowidsSize = int64(libsqlite3.Xsqlite3_column_bytes(tls, stmtChunks, int32(2)))
		if libc.Uint64FromInt64(rowidsSize) != uint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)*uint64(8)) {
			// IMP: V02796_19635
			Xvtab_set_error(tls, p, __ccgo_ts+9627, 0)
			Xvtab_set_error(tls, p, __ccgo_ts+9653, libc.VaList(bp+168, libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)*uint64(8), rowidsSize))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		// open the vector chunk blob for the current chunk
		rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(vectorColumnIdx)*8)), __ccgo_ts+3698, chunk_id, 0, bp)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+9713, libc.VaList(bp+168, chunk_id))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		currentBaseVectorsSize = int64(libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(bp))))
		expectedBaseVectorsSize = libc.Int64FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) * Xvector_column_byte_size(tls, *(*TVectorColumnDefinition)(unsafe.Pointer(vector_column))))
		if currentBaseVectorsSize != expectedBaseVectorsSize {
			// IMP: V16465_00535
			Xvtab_set_error(tls, p, __ccgo_ts+9756, libc.VaList(bp+168, expectedBaseVectorsSize, currentBaseVectorsSize))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp)), baseVectors, int32(currentBaseVectorsSize), 0)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+9816, libc.VaList(bp+168, chunk_id))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		Xbitmap_copy(tls, b, chunkValidity, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
		if arrayRowidsIn != 0 {
			Xbitmap_clear(tls, bmRowids, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
			i1 = 0
			for {
				if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) {
					break
				}
				if !(Xbitmap_get(tls, chunkValidity, i1) != 0) {
					goto _3
				}
				*(*Ti64)(unsafe.Pointer(bp + 136)) = *(*Ti64)(unsafe.Pointer(chunkRowids + uintptr(i1)*8))
				in = libc.Xbsearch(tls, bp+136, (*TArray)(unsafe.Pointer(arrayRowidsIn)).Fz, (*TArray)(unsafe.Pointer(arrayRowidsIn)).Flength, uint64(8), __ccgo_fp(X_cmp))
				if in != 0 {
					v4 = int32(1)
				} else {
					v4 = 0
				}
				Xbitmap_set(tls, bmRowids, i1, v4)
				goto _3
			_3:
				;
				i1 = i1 + 1
			}
			Xbitmap_and_inplace(tls, b, bmRowids, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
		}
		if hasMetadataFilters != 0 {
			i2 = 0
			for {
				if !(i2 < argc) {
					break
				}
				idx1 = int32(1) + i2*int32(4)
				kind1 = *(*uint8)(unsafe.Pointer(idxStr + uintptr(idx1+0)))
				if libc.Int32FromUint8(kind1) != int32(_VEC0_IDXSTR_KIND_METADATA_CONSTRAINT) {
					goto _5
				}
				metadata_idx = libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(idx1+int32(1))))) - int32('A')
				operator = libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(idx1+int32(2)))))
				if !((*(*[16]uintptr)(unsafe.Pointer(bp + 8)))[metadata_idx] != 0) {
					rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 480 + uintptr(metadata_idx)*8)), __ccgo_ts+4039, chunk_id, 0, bp+8+uintptr(metadata_idx)*8)
					Xvtab_set_error(tls, p, __ccgo_ts+9849, 0)
					if rc != m_SQLITE_OK {
						goto cleanup
					}
				}
				Xbitmap_clear(tls, bmMetadata, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
				rc = Xvec0_set_metadata_filter_bitmap(tls, p, metadata_idx, operator, *(*uintptr)(unsafe.Pointer(argv + uintptr(i2)*8)), (*(*[16]uintptr)(unsafe.Pointer(bp + 8)))[metadata_idx], chunk_id, bmMetadata, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size, aMetadataIn, i2)
				if rc != m_SQLITE_OK {
					Xvtab_set_error(tls, p, __ccgo_ts+9878, 0)
					if rc != m_SQLITE_OK {
						goto cleanup
					}
				}
				Xbitmap_and_inplace(tls, b, bmMetadata, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
				goto _5
			_5:
				;
				i2 = i2 + 1
			}
		}
		i3 = 0
		for {
			if !(i3 < (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) {
				break
			}
			if !(Xbitmap_get(tls, b, i3) != 0) {
				goto _6
			}
			switch (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Felement_type {
			case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
				base_i = baseVectors + uintptr(libc.Uint64FromInt32(i3)*(*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdimensions)*4
				switch (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdistance_metric {
				case int32(_VEC0_DISTANCE_METRIC_L2):
					result = _distance_l2_sqr_float(tls, base_i, queryVector, vector_column+16)
				case int32(_VEC0_DISTANCE_METRIC_L1):
					result = float32(_distance_l1_f32(tls, base_i, queryVector, vector_column+16))
				case int32(_VEC0_DISTANCE_METRIC_COSINE):
					result = _distance_cosine_float(tls, base_i, queryVector, vector_column+16)
					break
				}
			case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
				base_i1 = baseVectors + uintptr(libc.Uint64FromInt32(i3)*(*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdimensions)
				switch (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdistance_metric {
				case int32(_VEC0_DISTANCE_METRIC_L2):
					result = _distance_l2_sqr_int8(tls, base_i1, queryVector, vector_column+16)
				case int32(_VEC0_DISTANCE_METRIC_L1):
					result = float32(_distance_l1_int8(tls, base_i1, queryVector, vector_column+16))
				case int32(_VEC0_DISTANCE_METRIC_COSINE):
					result = _distance_cosine_int8(tls, base_i1, queryVector, vector_column+16)
					break
				}
			case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
				base_i2 = baseVectors + uintptr(libc.Uint64FromInt32(i3)*((*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdimensions/libc.Uint64FromInt32(m_CHAR_BIT)))
				result = _distance_hamming(tls, base_i2, queryVector, vector_column+16)
				break
			}
			*(*Tf32)(unsafe.Pointer(chunk_distances + uintptr(i3)*4)) = result
			goto _6
		_6:
			;
			i3 = i3 + 1
		}
		if k <= int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) {
			v7 = k
		} else {
			v7 = int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
		}
		Xmin_idx(tls, chunk_distances, (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size, b, chunk_topk_idxs, int32(v7), bTaken, bp+144)
		if k <= int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) {
			v8 = k
		} else {
			v8 = int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
		}
		if v8 <= int64(*(*int32)(unsafe.Pointer(bp + 144))) {
			if k <= int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) {
				v9 = k
			} else {
				v9 = int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size)
			}
			v7 = v9
		} else {
			v7 = int64(*(*int32)(unsafe.Pointer(bp + 144)))
		}
		Xmerge_sorted_lists(tls, topk_distances, topk_rowids, k_used, chunk_distances, chunkRowids, chunk_topk_idxs, v7, tmp_topk_distances, tmp_topk_rowids, k, bp+152)
		i4 = 0
		for {
			if !(int64(i4) < *(*Ti64)(unsafe.Pointer(bp + 152))) {
				break
			}
			*(*Ti64)(unsafe.Pointer(topk_rowids + uintptr(i4)*8)) = *(*Ti64)(unsafe.Pointer(tmp_topk_rowids + uintptr(i4)*8))
			*(*Tf32)(unsafe.Pointer(topk_distances + uintptr(i4)*4)) = *(*Tf32)(unsafe.Pointer(tmp_topk_distances + uintptr(i4)*4))
			goto _11
		_11:
			;
			i4 = i4 + 1
		}
		k_used = *(*Ti64)(unsafe.Pointer(bp + 152))
		// blobVectors is always opened with read-only permissions, so this never
		// fails.
		libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
		*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	}
	*(*uintptr)(unsafe.Pointer(out_topk_rowids)) = topk_rowids
	*(*uintptr)(unsafe.Pointer(out_topk_distances)) = topk_distances
	*(*Ti64)(unsafe.Pointer(out_used)) = k_used
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, topk_rowids)
		libsqlite3.Xsqlite3_free(tls, topk_distances)
	}
	libsqlite3.Xsqlite3_free(tls, chunk_topk_idxs)
	libsqlite3.Xsqlite3_free(tls, tmp_topk_rowids)
	libsqlite3.Xsqlite3_free(tls, tmp_topk_distances)
	libsqlite3.Xsqlite3_free(tls, b)
	libsqlite3.Xsqlite3_free(tls, bTaken)
	libsqlite3.Xsqlite3_free(tls, bmRowids)
	libsqlite3.Xsqlite3_free(tls, baseVectors)
	libsqlite3.Xsqlite3_free(tls, chunk_distances)
	libsqlite3.Xsqlite3_free(tls, bmMetadata)
	i5 = 0
	for {
		if !(i5 < int32(m_VEC0_MAX_METADATA_COLUMNS)) {
			break
		}
		libsqlite3.Xsqlite3_blob_close(tls, (*(*[16]uintptr)(unsafe.Pointer(bp + 8)))[i5])
		goto _12
	_12:
		;
		i5 = i5 + 1
	}
	// blobVectors is always opened with read-only permissions, so this never
	// fails.
	libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func Xvec0Filter_knn(tls *libc.TLS, pCur uintptr, p uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var aMetadataIn, arrayRowidsIn, item2, knn_data, s, vector_column uintptr
	var entry3 TVec0MetadataInTextEntry
	var i, i1, k_idx, metadata_idx, n, query_idx, rc, rc1, rowid_in_idx, vectorColumnIdx int32
	var i2, j Tsize_t
	var k Ti64
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+24 */ _VectorElementType
	var _ /* entry at bp+104 */ uintptr
	var _ /* entry at bp+120 */ uintptr
	var _ /* entry at bp+128 */ TVec0MetadataInTextEntry
	var _ /* item at bp+48 */ uintptr
	var _ /* item at bp+64 */ TVec0MetadataIn
	var _ /* k_used at bp+160 */ Ti64
	var _ /* pzError at bp+40 */ uintptr
	var _ /* queryVector at bp+8 */ uintptr
	var _ /* queryVectorCleanup at bp+32 */ Tvector_cleanup
	var _ /* rowid at bp+56 */ Ti64
	var _ /* stmtChunks at bp+0 */ uintptr
	var _ /* topk_distances at bp+152 */ uintptr
	var _ /* topk_rowids at bp+144 */ uintptr
	var _ /* v at bp+112 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aMetadataIn, arrayRowidsIn, entry3, i, i1, i2, item2, j, k, k_idx, knn_data, metadata_idx, n, query_idx, rc, rc1, rowid_in_idx, s, vectorColumnIdx, vector_column
	vectorColumnIdx = idxNum
	vector_column = p + 608 + uintptr(vectorColumnIdx)*32
	arrayRowidsIn = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*Tvector_cleanup)(unsafe.Pointer(bp + 32)) = __ccgo_fp(Xvector_cleanup_noop)
	knn_data = libsqlite3.Xsqlite3_malloc(tls, int32(40))
	if !(knn_data != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, knn_data, 0, uint64(40))
	// array of `struct Vec0MetadataIn`, IF there are any `xxx in (...)` metadata constraints
	aMetadataIn = libc.UintptrFromInt32(0)
	query_idx = -int32(1)
	k_idx = -int32(1)
	rowid_in_idx = -int32(1)
	i = 0
	for {
		if !(i < argc) {
			break
		}
		if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(int32(1)+i*int32(4))))) == int32(_VEC0_IDXSTR_KIND_KNN_MATCH) {
			query_idx = i
		}
		if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(int32(1)+i*int32(4))))) == int32(_VEC0_IDXSTR_KIND_KNN_K) {
			k_idx = i
		}
		if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(int32(1)+i*int32(4))))) == int32(_VEC0_IDXSTR_KIND_KNN_ROWID_IN) {
			rowid_in_idx = i
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	// make sure the query vector matches the vector column (type dimensions etc.)
	rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(query_idx)*8)), bp+8, bp+16, bp+24, bp+32, bp+40)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+9911, libc.VaList(bp+176, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fname_length, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fname, *(*uintptr)(unsafe.Pointer(bp + 40))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if *(*_VectorElementType)(unsafe.Pointer(bp + 24)) != (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Felement_type {
		Xvtab_set_error(tls, p, __ccgo_ts+9960, libc.VaList(bp+176, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fname_length, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fname, Xvector_subtype_name(tls, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Felement_type), Xvector_subtype_name(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 24)))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if *(*Tsize_t)(unsafe.Pointer(bp + 16)) != (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdimensions {
		Xvtab_set_error(tls, p, __ccgo_ts+10055, libc.VaList(bp+176, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fname_length, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fname, (*TVectorColumnDefinition)(unsafe.Pointer(vector_column)).Fdimensions, *(*Tsize_t)(unsafe.Pointer(bp + 16))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	k = libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(k_idx)*8)))
	if k < 0 {
		Xvtab_set_error(tls, p, __ccgo_ts+10154, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if k > int64(m_SQLITE_VEC_VEC0_K_MAX) {
		Xvtab_set_error(tls, p, __ccgo_ts+10213, libc.VaList(bp+176, k, int32(m_SQLITE_VEC_VEC0_K_MAX)))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if k == 0 {
		(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fk = 0
		(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data = knn_data
		(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_KNN)
		rc = m_SQLITE_OK
		goto cleanup
	}
	// handle when a `rowid in (...)` operation was provided
	// Array of all the rowids that appear in any `rowid in (...)` constraint.
	// NULL if none were provided, which means a "full" scan.
	if rowid_in_idx >= 0 {
		arrayRowidsIn = libsqlite3.Xsqlite3_malloc(tls, int32(32))
		if !(arrayRowidsIn != 0) {
			rc1 = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		libc.Xmemset(tls, arrayRowidsIn, 0, uint64(32))
		rc1 = Xarray_init(tls, arrayRowidsIn, uint64(8), uint64(32))
		if rc1 != m_SQLITE_OK {
			goto cleanup
		}
		rc1 = libsqlite3.Xsqlite3_vtab_in_first(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(rowid_in_idx)*8)), bp+48)
		for {
			if !(rc1 == m_SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 48)) != 0) {
				break
			}
			if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
				rc1 = Xvec0_rowid_from_id(tls, p, *(*uintptr)(unsafe.Pointer(bp + 48)), bp+56)
				if rc1 != m_SQLITE_OK {
					goto cleanup
				}
			} else {
				*(*Ti64)(unsafe.Pointer(bp + 56)) = libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 48)))
			}
			rc1 = Xarray_append(tls, arrayRowidsIn, bp+56)
			if rc1 != m_SQLITE_OK {
				goto cleanup
			}
			goto _2
		_2:
			;
			rc1 = libsqlite3.Xsqlite3_vtab_in_next(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(rowid_in_idx)*8)), bp+48)
		}
		if rc1 != int32(m_SQLITE_DONE) {
			Xvtab_set_error(tls, p, __ccgo_ts+10281, 0)
			goto cleanup
		}
		libc.Xqsort(tls, (*TArray)(unsafe.Pointer(arrayRowidsIn)).Fz, (*TArray)(unsafe.Pointer(arrayRowidsIn)).Flength, (*TArray)(unsafe.Pointer(arrayRowidsIn)).Felement_size, __ccgo_fp(X_cmp))
	}
	i1 = 0
	for {
		if !(i1 < argc) {
			break
		}
		if !(libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(int32(1)+i1*int32(4))))) == int32(_VEC0_IDXSTR_KIND_METADATA_CONSTRAINT) && libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(int32(1)+i1*int32(4)+int32(2))))) == int32(_VEC0_METADATA_OPERATOR_IN)) {
			goto _3
		}
		metadata_idx = libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(idxStr + uintptr(int32(1)+i1*int32(4)+int32(1))))) - int32('A')
		if !(aMetadataIn != 0) {
			aMetadataIn = libsqlite3.Xsqlite3_malloc(tls, int32(32))
			if !(aMetadataIn != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto cleanup
			}
			libc.Xmemset(tls, aMetadataIn, 0, uint64(32))
			rc = Xarray_init(tls, aMetadataIn, uint64(40), uint64(8))
			if rc != m_SQLITE_OK {
				goto cleanup
			}
		}
		libc.Xmemset(tls, bp+64, 0, uint64(40))
		(*(*TVec0MetadataIn)(unsafe.Pointer(bp + 64))).Fmetadata_idx = metadata_idx
		(*(*TVec0MetadataIn)(unsafe.Pointer(bp + 64))).Fargv_idx = i1
		switch (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_idx)*24))).Fkind {
		case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
			rc = Xarray_init(tls, bp+64+8, uint64(8), uint64(16))
			if rc != m_SQLITE_OK {
				goto cleanup
			}
			rc = libsqlite3.Xsqlite3_vtab_in_first(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i1)*8)), bp+104)
			for {
				if !(rc == m_SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 104)) != 0) {
					break
				}
				*(*Ti64)(unsafe.Pointer(bp + 112)) = libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 104)))
				rc = Xarray_append(tls, bp+64+8, bp+112)
				if rc != m_SQLITE_OK {
					goto cleanup
				}
				goto _4
			_4:
				;
				rc = libsqlite3.Xsqlite3_vtab_in_next(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i1)*8)), bp+104)
			}
			if rc != int32(m_SQLITE_DONE) {
				Xvtab_set_error(tls, p, __ccgo_ts+10319, 0)
				goto cleanup
			}
		case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
			rc = Xarray_init(tls, bp+64+8, uint64(16), uint64(16))
			if rc != m_SQLITE_OK {
				goto cleanup
			}
			rc = libsqlite3.Xsqlite3_vtab_in_first(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i1)*8)), bp+120)
			for {
				if !(rc == m_SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 120)) != 0) {
					break
				}
				s = libsqlite3.Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(bp + 120)))
				n = libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 120)))
				(*(*TVec0MetadataInTextEntry)(unsafe.Pointer(bp + 128))).FzString = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1860, libc.VaList(bp+176, n, s))
				if !((*(*TVec0MetadataInTextEntry)(unsafe.Pointer(bp + 128))).FzString != 0) {
					rc = int32(m_SQLITE_NOMEM)
					goto cleanup
				}
				(*(*TVec0MetadataInTextEntry)(unsafe.Pointer(bp + 128))).Fn = n
				rc = Xarray_append(tls, bp+64+8, bp+128)
				if rc != m_SQLITE_OK {
					goto cleanup
				}
				goto _5
			_5:
				;
				rc = libsqlite3.Xsqlite3_vtab_in_next(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i1)*8)), bp+120)
			}
			if rc != int32(m_SQLITE_DONE) {
				Xvtab_set_error(tls, p, __ccgo_ts+10380, 0)
				goto cleanup
			}
		default:
			Xvtab_set_error(tls, p, __ccgo_ts+10438, 0)
			goto cleanup
		}
		rc = Xarray_append(tls, aMetadataIn, bp+64)
		if rc != m_SQLITE_OK {
			goto cleanup
		}
		goto _3
	_3:
		;
		i1 = i1 + 1
	}
	rc = Xvec0_chunks_iter(tls, p, idxStr, argc, argv, bp)
	if rc != m_SQLITE_OK {
		// IMP: V06942_23781
		Xvtab_set_error(tls, p, __ccgo_ts+10464, libc.VaList(bp+176, libsqlite3.Xsqlite3_errmsg(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb)))
		goto cleanup
	}
	*(*uintptr)(unsafe.Pointer(bp + 144)) = libc.UintptrFromInt32(0)
	*(*uintptr)(unsafe.Pointer(bp + 152)) = libc.UintptrFromInt32(0)
	*(*Ti64)(unsafe.Pointer(bp + 160)) = 0
	rc = Xvec0Filter_knn_chunks_iter(tls, p, *(*uintptr)(unsafe.Pointer(bp)), vector_column, vectorColumnIdx, arrayRowidsIn, aMetadataIn, idxStr, argc, argv, *(*uintptr)(unsafe.Pointer(bp + 8)), k, bp+144, bp+152, bp+160)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fcurrent_idx = 0
	(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fk = k
	(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Frowids = *(*uintptr)(unsafe.Pointer(bp + 144))
	(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances = *(*uintptr)(unsafe.Pointer(bp + 152))
	(*Tvec0_query_knn_data)(unsafe.Pointer(knn_data)).Fk_used = *(*Ti64)(unsafe.Pointer(bp + 160))
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data = knn_data
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_KNN)
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	Xarray_cleanup(tls, arrayRowidsIn)
	libsqlite3.Xsqlite3_free(tls, arrayRowidsIn)
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 32)))(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	if aMetadataIn != 0 {
		i2 = uint64(0)
		for {
			if !(i2 < (*TArray)(unsafe.Pointer(aMetadataIn)).Flength) {
				break
			}
			item2 = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(i2)*40
			j = uint64(0)
			for {
				if !(j < (*TVec0MetadataIn)(unsafe.Pointer(item2)).Farray.Flength) {
					break
				}
				if (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr((*TVec0MetadataIn)(unsafe.Pointer(item2)).Fmetadata_idx)*24))).Fkind == int32(_VEC0_METADATA_COLUMN_KIND_TEXT) {
					entry3 = *(*TVec0MetadataInTextEntry)(unsafe.Pointer((*TVec0MetadataIn)(unsafe.Pointer(item2)).Farray.Fz + uintptr(j)*16))
					libsqlite3.Xsqlite3_free(tls, entry3.FzString)
				}
				goto _7
			_7:
				;
				j = j + 1
			}
			Xarray_cleanup(tls, item2+8)
			goto _6
		_6:
			;
			i2 = i2 + 1
		}
		Xarray_cleanup(tls, aMetadataIn)
	}
	libsqlite3.Xsqlite3_free(tls, aMetadataIn)
	return rc
}

func Xvec0Filter_fullscan(tls *libc.TLS, p uintptr, pCur uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var fullscan_data, zSql uintptr
	var rc int32
	_, _, _ = fullscan_data, rc, zSql
	fullscan_data = libsqlite3.Xsqlite3_malloc(tls, int32(16))
	if !(fullscan_data != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, fullscan_data, 0, uint64(16))
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10494, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	if !(zSql != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto error
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), fullscan_data, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		// IMP: V09901_26739
		Xvtab_set_error(tls, p, __ccgo_ts+10564, libc.VaList(bp+8, libsqlite3.Xsqlite3_errmsg(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb)))
		goto error
	}
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Frowids_stmt)
	// DONE when there's no rowids, ROW when there are, both "success"
	if !(rc == int32(m_SQLITE_ROW) || rc == int32(m_SQLITE_DONE)) {
		goto error
	}
	(*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Fdone = libc.BoolInt8(rc == int32(m_SQLITE_DONE))
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_FULLSCAN)
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data = fullscan_data
	return m_SQLITE_OK
	goto error
error:
	;
	Xvec0_query_fullscan_data_clear(tls, fullscan_data)
	libsqlite3.Xsqlite3_free(tls, fullscan_data)
	return rc
}

func Xvec0Filter_point(tls *libc.TLS, pCur uintptr, p uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var point_data uintptr
	var _ /* rowid at bp+0 */ Ti64
	_, _, _ = i, point_data, rc
	point_data = libc.UintptrFromInt32(0)
	point_data = libsqlite3.Xsqlite3_malloc(tls, int32(144))
	if !(point_data != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto error
	}
	libc.Xmemset(tls, point_data, 0, uint64(144))
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
		rc = Xvec0_rowid_from_id(tls, p, *(*uintptr)(unsafe.Pointer(argv)), bp)
		if rc == int32(m_SQLITE_EMPTY) {
			goto eof
		}
		if rc != m_SQLITE_OK {
			goto error
		}
	} else {
		*(*Ti64)(unsafe.Pointer(bp)) = libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	}
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		rc = Xvec0_get_vector_data(tls, p, *(*Ti64)(unsafe.Pointer(bp)), i, point_data+8+uintptr(i)*8, libc.UintptrFromInt32(0))
		if rc == int32(m_SQLITE_EMPTY) {
			goto eof
		}
		if rc != m_SQLITE_OK {
			goto error
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Frowid = *(*Ti64)(unsafe.Pointer(bp))
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Fdone = 0
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data = point_data
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_POINT)
	return m_SQLITE_OK
	goto eof
eof:
	;
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Frowid = *(*Ti64)(unsafe.Pointer(bp))
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Fdone = int32(1)
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data = point_data
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_POINT)
	return m_SQLITE_OK
	goto error
error:
	;
	Xvec0_query_point_data_clear(tls, point_data)
	libsqlite3.Xsqlite3_free(tls, point_data)
	return rc
}

func _vec0Filter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var idxStrLength, numValueEntries int32
	var p, pCur uintptr
	var query_plan uint8
	_, _, _, _, _ = idxStrLength, numValueEntries, p, pCur, query_plan
	p = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	pCur = pVtabCursor
	Xvec0_cursor_clear(tls, pCur)
	idxStrLength = libc.Int32FromUint64(libc.Xstrlen(tls, idxStr))
	if idxStrLength <= 0 {
		return int32(m_SQLITE_ERROR)
	}
	if (idxStrLength-int32(1))%int32(4) != 0 {
		return int32(m_SQLITE_ERROR)
	}
	numValueEntries = (idxStrLength - int32(1)) / int32(4)
	if numValueEntries != argc {
		return int32(m_SQLITE_ERROR)
	}
	query_plan = *(*uint8)(unsafe.Pointer(idxStr))
	switch libc.Int32FromUint8(query_plan) {
	case int32(_VEC0_QUERY_PLAN_FULLSCAN):
		return Xvec0Filter_fullscan(tls, p, pCur)
	case int32(_VEC0_QUERY_PLAN_KNN):
		return Xvec0Filter_knn(tls, pCur, p, idxNum, idxStr, argc, argv)
	case int32(_VEC0_QUERY_PLAN_POINT):
		return Xvec0Filter_point(tls, pCur, p, argc, argv)
	default:
		Xvtab_set_error(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, __ccgo_ts+10595, libc.VaList(bp+8, idxStr))
		return int32(m_SQLITE_ERROR)
	}
	return r
}

func _vec0Rowid(tls *libc.TLS, cur uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCur uintptr
	_ = pCur
	pCur = cur
	switch (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC0_QUERY_PLAN_FULLSCAN):
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)).Frowids_stmt, 0)
		return m_SQLITE_OK
	case int32(_VEC0_QUERY_PLAN_POINT):
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
		return m_SQLITE_OK
	case int32(_VEC0_QUERY_PLAN_KNN):
		Xvtab_set_error(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab, __ccgo_ts+10615, libc.VaList(bp+8, (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan))
		return int32(m_SQLITE_ERROR)
	}
	return int32(m_SQLITE_ERROR)
}

func _vec0Next(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	var rc int32
	_, _ = pCur, rc
	pCur = cur
	switch (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC0_QUERY_PLAN_FULLSCAN):
		if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data != 0) {
			return int32(m_SQLITE_ERROR)
		}
		rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)).Frowids_stmt)
		if rc == int32(m_SQLITE_DONE) {
			(*Tvec0_query_fullscan_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)).Fdone = int8(1)
			return m_SQLITE_OK
		}
		if rc == int32(m_SQLITE_ROW) {
			return m_SQLITE_OK
		}
		return int32(m_SQLITE_ERROR)
	case int32(_VEC0_QUERY_PLAN_KNN):
		if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data != 0) {
			return int32(m_SQLITE_ERROR)
		}
		(*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx = (*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx + 1
		return m_SQLITE_OK
	case int32(_VEC0_QUERY_PLAN_POINT):
		if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data != 0) {
			return int32(m_SQLITE_ERROR)
		}
		(*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Fdone = int32(1)
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

func _vec0Eof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	switch (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC0_QUERY_PLAN_FULLSCAN):
		if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data != 0) {
			return int32(1)
		}
		return int32((*Tvec0_query_fullscan_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)).Fdone)
	case int32(_VEC0_QUERY_PLAN_KNN):
		if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data != 0) {
			return int32(1)
		}
		// return (pCur->knn_data->current_idx >= pCur->knn_data->k) ||
		// (pCur->knn_data->distances[pCur->knn_data->current_idx] == FLT_MAX);
		return libc.BoolInt32((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx >= (*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fk_used)
	case int32(_VEC0_QUERY_PLAN_POINT):
		if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data != 0) {
			return int32(1)
		}
		return (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Fdone
	}
	return int32(1)
}

func _vec0Column_fullscan(tls *libc.TLS, pVtab uintptr, pCur uintptr, context uintptr, i int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, vector_idx int32
	var rowid Ti64
	var zErr uintptr
	var _ /* sz at bp+8 */ int32
	var _ /* v at bp+0 */ uintptr
	var _ /* v at bp+16 */ uintptr
	var _ /* v at bp+24 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, rowid, vector_idx, zErr
	if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data != 0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+10691, -int32(1))
		return int32(m_SQLITE_ERROR)
	}
	rowid = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)).Frowids_stmt, 0)
	if i == m_VEC0_COLUMN_ID {
		return Xvec0_result_id(tls, pVtab, context, rowid)
	} else {
		if Xvec0_column_idx_is_vector(tls, pVtab, i) != 0 {
			vector_idx = Xvec0_column_idx_to_vector_idx(tls, pVtab, i)
			rc = Xvec0_get_vector_data(tls, pVtab, rowid, vector_idx, bp, bp+8)
			if rc != m_SQLITE_OK {
				return rc
			}
			libsqlite3.Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), __ccgo_fp(libsqlite3.Xsqlite3_free))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*(*TVectorColumnDefinition)(unsafe.Pointer(pVtab + 608 + uintptr(vector_idx)*32))).Felement_type))
		} else {
			if i == Xvec0_column_distance_idx(tls, pVtab) {
				libsqlite3.Xsqlite3_result_null(tls, context)
			} else {
				if Xvec0_column_idx_is_partition(tls, pVtab, i) != 0 {
					partition_idx = Xvec0_column_idx_to_partition_idx(tls, pVtab, i)
					rc1 = Xvec0_get_partition_value_for_rowid(tls, pVtab, rowid, partition_idx, bp+16)
					if rc1 == m_SQLITE_OK {
						libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp + 16)))
						libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
					} else {
						libsqlite3.Xsqlite3_result_error_code(tls, context, rc1)
					}
				} else {
					if Xvec0_column_idx_is_auxiliary(tls, pVtab, i) != 0 {
						auxiliary_idx = Xvec0_column_idx_to_auxiliary_idx(tls, pVtab, i)
						rc2 = Xvec0_get_auxiliary_value_for_rowid(tls, pVtab, rowid, auxiliary_idx, bp+24)
						if rc2 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)))
							libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
						} else {
							libsqlite3.Xsqlite3_result_error_code(tls, context, rc2)
						}
					} else {
						if Xvec0_column_idx_is_metadata(tls, pVtab, i) != 0 {
							if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
								return m_SQLITE_OK
							}
							metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, pVtab, i)
							rc3 = Xvec0_result_metadata_value_for_rowid(tls, pVtab, rowid, metadata_idx, context)
							if rc3 != m_SQLITE_OK {
								// IMP: V15466_32305
								zErr = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10741, libc.VaList(bp+40, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname_length, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname, rowid))
								if zErr != 0 {
									libsqlite3.Xsqlite3_result_error(tls, context, zErr, -int32(1))
									libsqlite3.Xsqlite3_free(tls, zErr)
								} else {
									libsqlite3.Xsqlite3_result_error_nomem(tls, context)
								}
							}
						}
					}
				}
			}
		}
	}
	return m_SQLITE_OK
}

func _vec0Column_point(tls *libc.TLS, pVtab uintptr, pCur uintptr, context uintptr, i int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, vector_idx int32
	var rowid, rowid1, rowid2 Ti64
	var zErr uintptr
	var _ /* v at bp+0 */ uintptr
	var _ /* v at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rowid, rowid1, rowid2, vector_idx, zErr
	if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data != 0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+10804, -int32(1))
		return int32(m_SQLITE_ERROR)
	}
	if i == m_VEC0_COLUMN_ID {
		return Xvec0_result_id(tls, pVtab, context, (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid)
	} else {
		if i == Xvec0_column_distance_idx(tls, pVtab) {
			libsqlite3.Xsqlite3_result_null(tls, context)
			return m_SQLITE_OK
		} else {
			if Xvec0_column_idx_is_vector(tls, pVtab, i) != 0 {
				if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
					libsqlite3.Xsqlite3_result_null(tls, context)
					return m_SQLITE_OK
				}
				vector_idx = Xvec0_column_idx_to_vector_idx(tls, pVtab, i)
				libsqlite3.Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data + 8 + uintptr(vector_idx)*8)), libc.Int32FromUint64(Xvector_column_byte_size(tls, *(*TVectorColumnDefinition)(unsafe.Pointer(pVtab + 608 + uintptr(vector_idx)*32)))), uintptr(-libc.Int32FromInt32(1)))
				libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*(*TVectorColumnDefinition)(unsafe.Pointer(pVtab + 608 + uintptr(vector_idx)*32))).Felement_type))
				return m_SQLITE_OK
			} else {
				if Xvec0_column_idx_is_partition(tls, pVtab, i) != 0 {
					if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
						return m_SQLITE_OK
					}
					partition_idx = Xvec0_column_idx_to_partition_idx(tls, pVtab, i)
					rowid = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
					rc = Xvec0_get_partition_value_for_rowid(tls, pVtab, rowid, partition_idx, bp)
					if rc == m_SQLITE_OK {
						libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp)))
						libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
					} else {
						libsqlite3.Xsqlite3_result_error_code(tls, context, rc)
					}
				} else {
					if Xvec0_column_idx_is_auxiliary(tls, pVtab, i) != 0 {
						if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
							return m_SQLITE_OK
						}
						rowid1 = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
						auxiliary_idx = Xvec0_column_idx_to_auxiliary_idx(tls, pVtab, i)
						rc1 = Xvec0_get_auxiliary_value_for_rowid(tls, pVtab, rowid1, auxiliary_idx, bp+8)
						if rc1 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp + 8)))
							libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
						} else {
							libsqlite3.Xsqlite3_result_error_code(tls, context, rc1)
						}
					} else {
						if Xvec0_column_idx_is_metadata(tls, pVtab, i) != 0 {
							if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
								return m_SQLITE_OK
							}
							rowid2 = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
							metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, pVtab, i)
							rc2 = Xvec0_result_metadata_value_for_rowid(tls, pVtab, rowid2, metadata_idx, context)
							if rc2 != m_SQLITE_OK {
								zErr = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10741, libc.VaList(bp+24, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname_length, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname, rowid2))
								if zErr != 0 {
									libsqlite3.Xsqlite3_result_error(tls, context, zErr, -int32(1))
									libsqlite3.Xsqlite3_free(tls, zErr)
								} else {
									libsqlite3.Xsqlite3_result_error_nomem(tls, context)
								}
							}
						}
					}
				}
			}
		}
	}
	return m_SQLITE_OK
}

func _vec0Column_knn(tls *libc.TLS, pVtab uintptr, pCur uintptr, context uintptr, i int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, vector_idx int32
	var rowid, rowid1, rowid2, rowid3 Ti64
	var zErr uintptr
	var _ /* out at bp+0 */ uintptr
	var _ /* sz at bp+8 */ int32
	var _ /* v at bp+16 */ uintptr
	var _ /* v at bp+24 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, rowid, rowid1, rowid2, rowid3, vector_idx, zErr
	if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data != 0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+10851, -int32(1))
		return int32(m_SQLITE_ERROR)
	}
	if i == m_VEC0_COLUMN_ID {
		rowid = *(*Ti64)(unsafe.Pointer((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
		return Xvec0_result_id(tls, pVtab, context, rowid)
	} else {
		if i == Xvec0_column_distance_idx(tls, pVtab) {
			libsqlite3.Xsqlite3_result_double(tls, context, float64(*(*Tf32)(unsafe.Pointer((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fdistances + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*4))))
			return m_SQLITE_OK
		} else {
			if Xvec0_column_idx_is_vector(tls, pVtab, i) != 0 {
				vector_idx = Xvec0_column_idx_to_vector_idx(tls, pVtab, i)
				rc = Xvec0_get_vector_data(tls, pVtab, *(*Ti64)(unsafe.Pointer((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8)), vector_idx, bp, bp+8)
				if rc != m_SQLITE_OK {
					return rc
				}
				libsqlite3.Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), __ccgo_fp(libsqlite3.Xsqlite3_free))
				libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*(*TVectorColumnDefinition)(unsafe.Pointer(pVtab + 608 + uintptr(vector_idx)*32))).Felement_type))
				return m_SQLITE_OK
			} else {
				if Xvec0_column_idx_is_partition(tls, pVtab, i) != 0 {
					partition_idx = Xvec0_column_idx_to_partition_idx(tls, pVtab, i)
					rowid1 = *(*Ti64)(unsafe.Pointer((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
					rc1 = Xvec0_get_partition_value_for_rowid(tls, pVtab, rowid1, partition_idx, bp+16)
					if rc1 == m_SQLITE_OK {
						libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp + 16)))
						libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
					} else {
						libsqlite3.Xsqlite3_result_error_code(tls, context, rc1)
					}
				} else {
					if Xvec0_column_idx_is_auxiliary(tls, pVtab, i) != 0 {
						auxiliary_idx = Xvec0_column_idx_to_auxiliary_idx(tls, pVtab, i)
						rowid2 = *(*Ti64)(unsafe.Pointer((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
						rc2 = Xvec0_get_auxiliary_value_for_rowid(tls, pVtab, rowid2, auxiliary_idx, bp+24)
						if rc2 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(bp + 24)))
							libsqlite3.Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
						} else {
							libsqlite3.Xsqlite3_result_error_code(tls, context, rc2)
						}
					} else {
						if Xvec0_column_idx_is_metadata(tls, pVtab, i) != 0 {
							metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, pVtab, i)
							rowid3 = *(*Ti64)(unsafe.Pointer((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
							rc3 = Xvec0_result_metadata_value_for_rowid(tls, pVtab, rowid3, metadata_idx, context)
							if rc3 != m_SQLITE_OK {
								zErr = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10741, libc.VaList(bp+40, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname_length, (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname, rowid3))
								if zErr != 0 {
									libsqlite3.Xsqlite3_result_error(tls, context, zErr, -int32(1))
									libsqlite3.Xsqlite3_free(tls, zErr)
								} else {
									libsqlite3.Xsqlite3_result_error_nomem(tls, context)
								}
							}
						}
					}
				}
			}
		}
	}
	return m_SQLITE_OK
}

func _vec0Column(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var pCur, pVtab uintptr
	_, _ = pCur, pVtab
	pCur = cur
	pVtab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	switch (*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC0_QUERY_PLAN_FULLSCAN):
		return _vec0Column_fullscan(tls, pVtab, pCur, context, i)
	case int32(_VEC0_QUERY_PLAN_KNN):
		return _vec0Column_knn(tls, pVtab, pCur, context, i)
	case int32(_VEC0_QUERY_PLAN_POINT):
		return _vec0Column_point(tls, pVtab, pCur, context, i)
	}
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Handles the "insert rowid" step of a row insert operation of a vec0
//	 * table.
//	 *
//	 * This function will insert a new row into the _rowids vec0 shadow table.
//	 *
//	 * @param p: virtual table
//	 * @param idValue: Value containing the inserted rowid/id value.
//	 * @param rowid: Output rowid, will point to the "real" i64 rowid
//	 * value that was inserted
//	 * @return int SQLITE_OK on success, error code on failure
//	 */
func Xvec0Update_InsertRowidStep(tls *libc.TLS, p uintptr, idValue uintptr, rowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var suppliedRowid Ti64
	_, _ = rc, suppliedRowid
	// Option 3: vtab has a user-defined TEXT primary key, so ensure a text value
	// is provided.
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
		if libsqlite3.Xsqlite3_value_type(tls, idValue) != int32(m_SQLITE_TEXT) {
			// IMP: V04200_21039
			Xvtab_set_error(tls, p, __ccgo_ts+10896, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
			return int32(m_SQLITE_ERROR)
		}
		return Xvec0_rowids_insert_id(tls, p, idValue, rowid)
	}
	// Option 1: User supplied a i64 rowid
	if libsqlite3.Xsqlite3_value_type(tls, idValue) == int32(m_SQLITE_INTEGER) {
		suppliedRowid = libsqlite3.Xsqlite3_value_int64(tls, idValue)
		rc = Xvec0_rowids_insert_rowid(tls, p, suppliedRowid)
		if rc == m_SQLITE_OK {
			*(*Ti64)(unsafe.Pointer(rowid)) = suppliedRowid
		}
		return rc
	}
	// Option 2: User did not suppled a rowid
	if libsqlite3.Xsqlite3_value_type(tls, idValue) != int32(m_SQLITE_NULL) {
		// IMP: V30855_14925
		Xvtab_set_error(tls, p, __ccgo_ts+11003, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		return int32(m_SQLITE_ERROR)
	}
	// NULL to get next auto-incremented value
	return Xvec0_rowids_insert_id(tls, p, libc.UintptrFromInt32(0), rowid)
}

// C documentation
//
//	/**
//	 * @brief Determines the "next available" chunk position for a newly inserted
//	 * vec0 row.
//	 *
//	 * This operation may insert a new "blank" chunk the _chunks table, if there is
//	 * no more space in previous chunks.
//	 *
//	 * @param p: virtual table
//	 * @param partitionKeyValues: array of partition key column values, to constrain
//	 * against any partition key columns.
//	 * @param chunk_rowid: Output rowid of the chunk in the _chunks virtual table
//	 * that has the avialabiity.
//	 * @param chunk_offset: Output the index of the available space insert the
//	 * chunk, based on the index of the first available validity bit.
//	 * @param pBlobValidity: Output blob of the validity column of the available
//	 * chunk. Will be opened with read/write permissions.
//	 * @param pValidity: Output buffer of the original chunk's validity column.
//	 *    Needs to be cleaned up with sqlite3_free().
//	 * @return int SQLITE_OK on success, error code on failure
//	 */
func Xvec0Update_InsertNextAvailableStep(tls *libc.TLS, p uintptr, partitionKeyValues uintptr, chunk_rowid uintptr, chunk_offset uintptr, blobChunksValidity uintptr, bufferChunksValidity uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, j, rc int32
	var validitySize Ti64
	_, _, _, _ = i, j, rc, validitySize
	*(*Ti64)(unsafe.Pointer(chunk_offset)) = int64(-int32(1))
	rc = Xvec0_get_latest_chunk_rowid(tls, p, chunk_rowid, partitionKeyValues)
	if rc == int32(m_SQLITE_EMPTY) {
		goto done
	}
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+11057, *(*Ti64)(unsafe.Pointer(chunk_rowid)), int32(1), blobChunksValidity)
	if rc != m_SQLITE_OK {
		// IMP: V22053_06123
		Xvtab_set_error(tls, p, __ccgo_ts+11066, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, *(*Ti64)(unsafe.Pointer(chunk_rowid))))
		goto cleanup
	}
	validitySize = int64(libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(blobChunksValidity))))
	if validitySize != int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/int32(m_CHAR_BIT)) {
		// IMP: V29362_13432
		Xvtab_set_error(tls, p, __ccgo_ts+11136, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, *(*Ti64)(unsafe.Pointer(chunk_rowid)), int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/libc.Int32FromInt32(m_CHAR_BIT)), validitySize))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	*(*uintptr)(unsafe.Pointer(bufferChunksValidity)) = libsqlite3.Xsqlite3_malloc(tls, int32(validitySize))
	if !(*(*uintptr)(unsafe.Pointer(bufferChunksValidity)) != 0) {
		Xvtab_set_error(tls, p, __ccgo_ts+11239, 0)
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(blobChunksValidity)), *(*uintptr)(unsafe.Pointer(bufferChunksValidity)), int32(validitySize), 0)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+11312, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, *(*Ti64)(unsafe.Pointer(chunk_rowid))))
		goto cleanup
	}
	// find the next available offset, ie first `0` in the bitmap.
	i = 0
	for {
		if !(int64(i) < validitySize) {
			break
		}
		if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bufferChunksValidity)) + uintptr(i)))) == int32(0b11111111) {
			goto _1
		}
		j = 0
		for {
			if !(j < int32(m_CHAR_BIT)) {
				break
			}
			if libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bufferChunksValidity)) + uintptr(i))))>>j&int32(1) == 0 {
				*(*Ti64)(unsafe.Pointer(chunk_offset)) = int64(i*int32(m_CHAR_BIT) + j)
				goto done
			}
			goto _2
		_2:
			;
			j = j + 1
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	goto done
done:
	;
	// latest chunk was full, so need to create a new one
	if *(*Ti64)(unsafe.Pointer(chunk_offset)) == int64(-int32(1)) {
		rc = Xvec0_new_chunk(tls, p, partitionKeyValues, chunk_rowid)
		if rc != m_SQLITE_OK {
			// IMP: V08441_25279
			Xvtab_set_error(tls, p, __ccgo_ts+11385, 0)
			rc = int32(m_SQLITE_ERROR) // otherwise raises a DatabaseError and not operational
			// error?
			goto cleanup
		}
		*(*Ti64)(unsafe.Pointer(chunk_offset)) = 0
		// blobChunksValidity and pValidity are stale, pointing to the previous
		// (full) chunk. to re-assign them
		rc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(blobChunksValidity)))
		libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bufferChunksValidity)))
		*(*uintptr)(unsafe.Pointer(blobChunksValidity)) = libc.UintptrFromInt32(0)
		*(*uintptr)(unsafe.Pointer(bufferChunksValidity)) = libc.UintptrFromInt32(0)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+11448, 0)
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+11057, *(*Ti64)(unsafe.Pointer(chunk_rowid)), int32(1), blobChunksValidity)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+11552, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, *(*Ti64)(unsafe.Pointer(chunk_rowid))))
			goto cleanup
		}
		validitySize = int64(libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(blobChunksValidity))))
		if validitySize != int64((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/int32(m_CHAR_BIT)) {
			Xvtab_set_error(tls, p, __ccgo_ts+11643, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, *(*Ti64)(unsafe.Pointer(chunk_rowid)), (*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size/int32(m_CHAR_BIT), validitySize))
			goto cleanup
		}
		*(*uintptr)(unsafe.Pointer(bufferChunksValidity)) = libsqlite3.Xsqlite3_malloc(tls, int32(validitySize))
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(blobChunksValidity)), *(*uintptr)(unsafe.Pointer(bufferChunksValidity)), int32(validitySize), 0)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+11758, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, *(*Ti64)(unsafe.Pointer(chunk_rowid))))
			goto cleanup
		}
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	return rc
	return r
}

// C documentation
//
//	/**
//	 * @brief Write the vector data into the provided vector blob at the given
//	 * offset
//	 *
//	 * @param blobVectors SQLite BLOB to write to
//	 * @param chunk_offset the "offset" (ie validity bitmap position) to write the
//	 * vector to
//	 * @param bVector pointer to the vector containing data
//	 * @param dimensions how many dimensions the vector has
//	 * @param element_type the vector type
//	 * @return result of sqlite3_blob_write, SQLITE_OK on success, otherwise failure
//	 */
func _vec0_write_vector_to_vector_blob(tls *libc.TLS, blobVectors uintptr, chunk_offset Ti64, bVector uintptr, dimensions Tsize_t, element_type _VectorElementType) (r int32) {
	var n, offset int32
	_, _ = n, offset
	switch element_type {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		n = libc.Int32FromUint64(dimensions * uint64(4))
		offset = libc.Int32FromUint64(libc.Uint64FromInt64(chunk_offset) * dimensions * uint64(4))
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		n = libc.Int32FromUint64(dimensions * uint64(1))
		offset = libc.Int32FromUint64(libc.Uint64FromInt64(chunk_offset) * dimensions * uint64(1))
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		n = libc.Int32FromUint64(dimensions / uint64(m_CHAR_BIT))
		offset = libc.Int32FromUint64(libc.Uint64FromInt64(chunk_offset) * dimensions / uint64(m_CHAR_BIT))
		break
	}
	return libsqlite3.Xsqlite3_blob_write(tls, blobVectors, bVector, n, offset)
}

// C documentation
//
//	/**
//	 * @brief
//	 *
//	 * @param p vec0 virtual table
//	 * @param chunk_rowid: which chunk to write to
//	 * @param chunk_offset: the offset inside the chunk to write the vector to.
//	 * @param rowid: the rowid of the inserting row
//	 * @param vectorDatas: array of the vector data to insert
//	 * @param blobValidity: writeable validity blob of the row's assigned chunk.
//	 * @param validity: snapshot buffer of the valdity column from the row's
//	 * assigned chunk.
//	 * @return int SQLITE_OK on success, error code on failure
//	 */
func Xvec0Update_InsertWriteFinalStep(tls *libc.TLS, p uintptr, chunk_rowid Ti64, chunk_offset Ti64, _rowid Ti64, vectorDatas uintptr, blobChunksValidity uintptr, bufferChunksValidity uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	*(*Ti64)(unsafe.Pointer(bp)) = _rowid
	var actual, actual1, expected, expected1 Ti64
	var brc, i, rc int32
	var _ /* blobChunksRowids at bp+8 */ uintptr
	var _ /* blobVectors at bp+24 */ uintptr
	var _ /* bx at bp+16 */ uint8
	_, _, _, _, _, _, _ = actual, actual1, brc, expected, expected1, i, rc
	*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.UintptrFromInt32(0)
	// mark the validity bit for this row in the chunk's validity bitmap
	// Get the byte offset of the bitmap
	*(*uint8)(unsafe.Pointer(bp + 16)) = *(*uint8)(unsafe.Pointer(bufferChunksValidity + uintptr(chunk_offset/int64(m_CHAR_BIT))))
	// set the bit at the chunk_offset position inside that byte
	*(*uint8)(unsafe.Pointer(bp + 16)) = libc.Uint8FromInt32(libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(bp + 16))) | int32(1)<<(chunk_offset%int64(m_CHAR_BIT)))
	// write that 1 byte
	rc = libsqlite3.Xsqlite3_blob_write(tls, blobChunksValidity, bp+16, int32(1), int32(chunk_offset/int64(m_CHAR_BIT)))
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+11845, 0)
		return rc
	}
	// Go insert the vector data into the vector chunk shadow tables
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), __ccgo_ts+3698, chunk_rowid, int32(1), bp+24)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+11901, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_rowid))
			goto cleanup
		}
		expected = libc.Int64FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) * Xvector_column_byte_size(tls, *(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))))
		actual = int64(libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 24))))
		if actual != expected {
			// IMP: V16386_00456
			Xvtab_set_error(tls, p, __ccgo_ts+11941, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_rowid, expected, actual))
			rc = int32(m_SQLITE_ERROR)
			// already error, can ignore result code
			libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
			goto cleanup
		}
		rc = _vec0_write_vector_to_vector_blob(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), chunk_offset, *(*uintptr)(unsafe.Pointer(vectorDatas + uintptr(i)*8)), (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fdimensions, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Felement_type)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+12036, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_rowid))
			rc = int32(m_SQLITE_ERROR)
			// already error, can ignore result code
			libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+12105, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_rowid))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	// write the new rowid to the rowids column of the _chunks table
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+9540, chunk_rowid, int32(1), bp+8)
	if rc != m_SQLITE_OK {
		// IMP: V09221_26060
		Xvtab_set_error(tls, p, __ccgo_ts+12174, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_rowid))
		goto cleanup
	}
	expected1 = libc.Int64FromUint64(libc.Uint64FromInt32((*Tvec0_vtab)(unsafe.Pointer(p)).Fchunk_size) * uint64(8))
	actual1 = int64(libsqlite3.Xsqlite3_blob_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 8))))
	if expected1 != actual1 {
		// IMP: V12779_29618
		Xvtab_set_error(tls, p, __ccgo_ts+12242, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_rowid, expected1, actual1))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), bp, int32(8), libc.Int32FromUint64(libc.Uint64FromInt64(chunk_offset)*uint64(8)))
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+12337, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_rowid))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	// Now with all the vectors inserted, go back and update the _rowids table
	// with the new chunk_rowid/chunk_offset values
	rc = Xvec0_rowids_update_position(tls, p, *(*Ti64)(unsafe.Pointer(bp)), chunk_rowid, chunk_offset)
	goto cleanup
cleanup:
	;
	brc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	if rc == m_SQLITE_OK && brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+12406, libc.VaList(bp+40, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_rowid))
		return brc
	}
	return rc
}

func Xvec0_write_metadata_value(tls *libc.TLS, p uintptr, metadata_column_idx int32, rowid Ti64, chunk_id Ti64, chunk_offset Ti64, v uintptr, isupdate int32) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var kind Tvec0_metadata_column_kind
	var metadata_column, s, zSql, zSql1 uintptr
	var rc, value, v1 int32
	var _ /* blobValue at bp+0 */ uintptr
	var _ /* block at bp+8 */ Tu8
	var _ /* n at bp+36 */ int32
	var _ /* prev_n at bp+32 */ int32
	var _ /* stmt at bp+56 */ uintptr
	var _ /* stmt at bp+64 */ uintptr
	var _ /* value at bp+16 */ Ti64
	var _ /* value at bp+24 */ float64
	var _ /* view at bp+40 */ [16]Tu8
	_, _, _, _, _, _, _, _ = kind, metadata_column, rc, s, value, zSql, zSql1, v1
	metadata_column = p + 1600 + uintptr(metadata_column_idx)*24
	kind = (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fkind
	// verify input value matches column type
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		if libsqlite3.Xsqlite3_value_type(tls, v) != int32(m_SQLITE_INTEGER) || libsqlite3.Xsqlite3_value_int(tls, v) != 0 && libsqlite3.Xsqlite3_value_int(tls, v) != int32(1) {
			rc = int32(m_SQLITE_ERROR)
			Xvtab_set_error(tls, p, __ccgo_ts+12475, libc.VaList(bp+80, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname_length, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname))
			goto done
		}
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		if libsqlite3.Xsqlite3_value_type(tls, v) != int32(m_SQLITE_INTEGER) {
			rc = int32(m_SQLITE_ERROR)
			Xvtab_set_error(tls, p, __ccgo_ts+12524, libc.VaList(bp+80, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname_length, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname, Xtype_name(tls, libsqlite3.Xsqlite3_value_type(tls, v))))
			goto done
		}
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		if libsqlite3.Xsqlite3_value_type(tls, v) != int32(m_SQLITE_FLOAT) {
			rc = int32(m_SQLITE_ERROR)
			Xvtab_set_error(tls, p, __ccgo_ts+12587, libc.VaList(bp+80, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname_length, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname, Xtype_name(tls, libsqlite3.Xsqlite3_value_type(tls, v))))
			goto done
		}
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		if libsqlite3.Xsqlite3_value_type(tls, v) != int32(m_SQLITE_TEXT) {
			rc = int32(m_SQLITE_ERROR)
			Xvtab_set_error(tls, p, __ccgo_ts+12646, libc.VaList(bp+80, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname_length, (*TVec0MetadataColumnDefinition)(unsafe.Pointer(metadata_column)).Fname, Xtype_name(tls, libsqlite3.Xsqlite3_value_type(tls, v))))
			goto done
		}
		break
	}
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 480 + uintptr(metadata_column_idx)*8)), __ccgo_ts+4039, chunk_id, int32(1), bp)
	if rc != m_SQLITE_OK {
		goto done
	}
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		value = libsqlite3.Xsqlite3_value_int(tls, v)
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+8, int32(1), int32(chunk_offset/libc.Int64FromInt32(m_CHAR_BIT)))
		if rc != m_SQLITE_OK {
			goto done
		}
		if value != 0 {
			*(*Tu8)(unsafe.Pointer(bp + 8)) = libc.Uint8FromInt32(int32(*(*Tu8)(unsafe.Pointer(bp + 8))) | libc.Int32FromInt32(1)<<(chunk_offset%libc.Int64FromInt32(m_CHAR_BIT)))
		} else {
			*(*Tu8)(unsafe.Pointer(bp + 8)) = libc.Uint8FromInt32(int32(*(*Tu8)(unsafe.Pointer(bp + 8))) & ^(libc.Int32FromInt32(1) << (chunk_offset % libc.Int64FromInt32(m_CHAR_BIT))))
		}
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+8, int32(1), int32(chunk_offset/int64(m_CHAR_BIT)))
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		*(*Ti64)(unsafe.Pointer(bp + 16)) = libsqlite3.Xsqlite3_value_int64(tls, v)
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+16, int32(8), libc.Int32FromUint64(libc.Uint64FromInt64(chunk_offset)*uint64(8)))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		*(*float64)(unsafe.Pointer(bp + 24)) = libsqlite3.Xsqlite3_value_double(tls, v)
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+24, int32(8), libc.Int32FromUint64(libc.Uint64FromInt64(chunk_offset)*uint64(8)))
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+32, int32(4), int32(chunk_offset*int64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)))
		if rc != m_SQLITE_OK {
			goto done
		}
		s = libsqlite3.Xsqlite3_value_text(tls, v)
		*(*int32)(unsafe.Pointer(bp + 36)) = libsqlite3.Xsqlite3_value_bytes(tls, v)
		libc.Xmemset(tls, bp+40, 0, uint64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		libc.Xmemcpy(tls, bp+40, bp+36, uint64(4))
		if *(*int32)(unsafe.Pointer(bp + 36)) <= libc.Int32FromInt32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)-libc.Int32FromInt32(4) {
			v1 = *(*int32)(unsafe.Pointer(bp + 36))
		} else {
			v1 = libc.Int32FromInt32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH) - libc.Int32FromInt32(4)
		}
		libc.Xmemcpy(tls, bp+40+uintptr(4), s, libc.Uint64FromInt32(v1))
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+40, int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH), int32(chunk_offset*int64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)))
		if *(*int32)(unsafe.Pointer(bp + 36)) > int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			if isupdate != 0 && *(*int32)(unsafe.Pointer(bp + 32)) > int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+12703, libc.VaList(bp+80, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_column_idx))
			} else {
				zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+12768, libc.VaList(bp+80, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_column_idx))
			}
			if !(zSql != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto done
			}
			rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+56, libc.UintptrFromInt32(0))
			if rc != m_SQLITE_OK {
				goto done
			}
			libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), int32(1), rowid)
			libsqlite3.Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), int32(2), s, *(*int32)(unsafe.Pointer(bp + 36)), libc.UintptrFromInt32(0))
			rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
			if rc != int32(m_SQLITE_DONE) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
		} else {
			if *(*int32)(unsafe.Pointer(bp + 32)) > int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				zSql1 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+12837, libc.VaList(bp+80, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_column_idx))
				if !(zSql1 != 0) {
					rc = int32(m_SQLITE_NOMEM)
					goto done
				}
				rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql1, -int32(1), bp+64, libc.UintptrFromInt32(0))
				if rc != m_SQLITE_OK {
					goto done
				}
				libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), int32(1), rowid)
				rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
				if rc != int32(m_SQLITE_DONE) {
					rc = int32(m_SQLITE_ERROR)
					goto done
				}
			}
		}
		break
	}
	if rc != m_SQLITE_OK {
	}
	rc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != m_SQLITE_OK {
		goto done
	}
	goto done
done:
	;
	return rc
	return r
}

// C documentation
//
//	/**
//	 * @brief Handles INSERT INTO operations on a vec0 table.
//	 *
//	 * @return int SQLITE_OK on success, otherwise error code on failure
//	 */
func Xvec0Update_Insert(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(400)
	defer tls.Free(400)
	var auxiliary_key_idx, brc, i, i1, i2, i3, i4, i5, i6, metadata_idx, new_value_type, numReadVectors, partition_key_idx, rc, v_type, vector_column_idx int32
	var p, s, v, v1, valueVector, zSql uintptr
	var _ /* blobChunksValidity at bp+312 */ uintptr
	var _ /* bufferChunksValidity at bp+320 */ uintptr
	var _ /* chunk_offset at bp+304 */ Ti64
	var _ /* chunk_rowid at bp+296 */ Ti64
	var _ /* cleanups at bp+136 */ [16]Tvector_cleanup
	var _ /* dimensions at bp+328 */ Tsize_t
	var _ /* elementType at bp+344 */ _VectorElementType
	var _ /* partitionKeyValues at bp+264 */ [4]uintptr
	var _ /* pzError at bp+336 */ uintptr
	var _ /* rowid at bp+0 */ Ti64
	var _ /* stmt at bp+352 */ uintptr
	var _ /* vectorDatas at bp+8 */ [16]uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = auxiliary_key_idx, brc, i, i1, i2, i3, i4, i5, i6, metadata_idx, new_value_type, numReadVectors, p, partition_key_idx, rc, s, v, v1, v_type, valueVector, vector_column_idx, zSql
	_ = argc
	p = pVTab
	// a write-able blob of the validity column for the given chunk. Used to mark
	// validity bit
	*(*uintptr)(unsafe.Pointer(bp + 312)) = libc.UintptrFromInt32(0)
	// buffer for the valididty column for the given chunk. Maybe not needed here?
	*(*uintptr)(unsafe.Pointer(bp + 320)) = libc.UintptrFromInt32(0)
	numReadVectors = 0
	// Read all provided partition key values into partitionKeyValues
	i = 0
	for {
		if !(i < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
			goto _1
		}
		partition_key_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i))))
		(*(*[4]uintptr)(unsafe.Pointer(bp + 264)))[partition_key_idx] = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i)*8))
		new_value_type = libsqlite3.Xsqlite3_value_type(tls, (*(*[4]uintptr)(unsafe.Pointer(bp + 264)))[partition_key_idx])
		if new_value_type != int32(m_SQLITE_NULL) && new_value_type != (*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(p + 1120 + uintptr(partition_key_idx)*24))).Ftype1 {
			// IMP: V11454_28292
			Xvtab_set_error(tls, pVTab, __ccgo_ts+12892, libc.VaList(bp+368, (*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(p + 1120 + uintptr(partition_key_idx)*24))).Fname_length, (*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(p + 1120 + uintptr(partition_key_idx)*24))).Fname, Xtype_name(tls, (*(*TVec0PartitionColumnDefinition)(unsafe.Pointer(p + 1120 + uintptr(partition_key_idx)*24))).Ftype1), Xtype_name(tls, new_value_type)))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	// read all the inserted vectors  into vectorDatas, validate their lengths.
	i1 = 0
	for {
		if !(i1 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i1)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _2
		}
		vector_column_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i1))))
		valueVector = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i1)*8))
		rc = Xvector_from_value(tls, valueVector, bp+8+uintptr(vector_column_idx)*8, bp+328, bp+344, bp+136+uintptr(vector_column_idx)*8, bp+336)
		if rc != m_SQLITE_OK {
			// IMP: V06519_23358
			Xvtab_set_error(tls, pVTab, __ccgo_ts+12984, libc.VaList(bp+368, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Fname, *(*uintptr)(unsafe.Pointer(bp + 336))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		numReadVectors = numReadVectors + 1
		if *(*_VectorElementType)(unsafe.Pointer(bp + 344)) != (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Felement_type {
			// IMP: V08221_25059
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13037, libc.VaList(bp+368, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i1)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i1)*32))).Fname, Xvector_subtype_name(tls, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i1)*32))).Felement_type), Xvector_subtype_name(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 344)))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		if *(*Tsize_t)(unsafe.Pointer(bp + 328)) != (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Fdimensions {
			// IMP: V01145_17984
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13135, libc.VaList(bp+368, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Fname, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(vector_column_idx)*32))).Fdimensions, *(*Tsize_t)(unsafe.Pointer(bp + 328))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	// Cannot insert a value in the hidden "distance" column
	if libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(int32(2)+Xvec0_column_distance_idx(tls, p))*8))) != int32(m_SQLITE_NULL) {
		// IMP: V24228_08298
		Xvtab_set_error(tls, pVTab, __ccgo_ts+13237, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	// Cannot insert a value in the hidden "k" column
	if libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(int32(2)+Xvec0_column_k_idx(tls, p))*8))) != int32(m_SQLITE_NULL) {
		// IMP: V11875_28713
		Xvtab_set_error(tls, pVTab, __ccgo_ts+13292, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	// Step #1: Insert/get a rowid for this row, from the _rowids table.
	rc = Xvec0Update_InsertRowidStep(tls, p, *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_ID))*8)), bp)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	// Step #2: Find the next "available" position in the _chunks table for this
	// row.
	rc = Xvec0Update_InsertNextAvailableStep(tls, p, bp+264, bp+296, bp+304, bp+312, bp+320)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	// Step #3: With the next available chunk position, write out all the vectors
	//          to their specified location.
	rc = Xvec0Update_InsertWriteFinalStep(tls, p, *(*Ti64)(unsafe.Pointer(bp + 296)), *(*Ti64)(unsafe.Pointer(bp + 304)), *(*Ti64)(unsafe.Pointer(bp)), bp+8, *(*uintptr)(unsafe.Pointer(bp + 312)), *(*uintptr)(unsafe.Pointer(bp + 320)))
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns > 0 {
		s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+13340, libc.VaList(bp+368, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		i2 = 0
		for {
			if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns) {
				break
			}
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+8060, libc.VaList(bp+368, i2))
			goto _3
		_3:
			;
			i2 = i2 + 1
		}
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+13379)
		i3 = 0
		for {
			if !(i3 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns) {
				break
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5238)
			goto _4
		_4:
			;
			i3 = i3 + 1
		}
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5242)
		zSql = libsqlite3.Xsqlite3_str_finish(tls, s)
		// TODO double check error handling ehre
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+352, libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			goto cleanup
		}
		libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 352)), int32(1), *(*Ti64)(unsafe.Pointer(bp)))
		i4 = 0
		for {
			if !(i4 < Xvec0_num_defined_user_columns(tls, p)) {
				break
			}
			if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i4)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY) {
				goto _5
			}
			auxiliary_key_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i4))))
			v = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i4)*8))
			v_type = libsqlite3.Xsqlite3_value_type(tls, v)
			if v_type != int32(m_SQLITE_NULL) && v_type != (*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(p + 1216 + uintptr(auxiliary_key_idx)*24))).Ftype1 {
				libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 352)))
				rc = int32(m_SQLITE_CONSTRAINT)
				Xvtab_set_error(tls, pVTab, __ccgo_ts+13392, libc.VaList(bp+368, (*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(p + 1216 + uintptr(auxiliary_key_idx)*24))).Fname_length, (*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(p + 1216 + uintptr(auxiliary_key_idx)*24))).Fname, Xtype_name(tls, (*(*TVec0AuxiliaryColumnDefinition)(unsafe.Pointer(p + 1216 + uintptr(auxiliary_key_idx)*24))).Ftype1), Xtype_name(tls, v_type)))
				goto cleanup
			}
			// first 1 is for 1-based indexing on sqlite3_bind_*, second 1 is to account for initial rowid parameter
			libsqlite3.Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 352)), libc.Int32FromInt32(1)+libc.Int32FromInt32(1)+auxiliary_key_idx, v)
			goto _5
		_5:
			;
			i4 = i4 + 1
		}
		rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 352)))
		if rc != int32(m_SQLITE_DONE) {
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 352)))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 352)))
	}
	i5 = 0
	for {
		if !(i5 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i5)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _6
		}
		metadata_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i5))))
		v1 = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i5)*8))
		rc = Xvec0_write_metadata_value(tls, p, metadata_idx, *(*Ti64)(unsafe.Pointer(bp)), *(*Ti64)(unsafe.Pointer(bp + 296)), *(*Ti64)(unsafe.Pointer(bp + 304)), v1, 0)
		if rc != m_SQLITE_OK {
			goto cleanup
		}
		goto _6
	_6:
		;
		i5 = i5 + 1
	}
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = *(*Ti64)(unsafe.Pointer(bp))
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	i6 = 0
	for {
		if !(i6 < numReadVectors) {
			break
		}
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*(*[16]Tvector_cleanup)(unsafe.Pointer(bp + 136)))[i6]})))(tls, (*(*[16]uintptr)(unsafe.Pointer(bp + 8)))[i6])
		goto _7
	_7:
		;
		i6 = i6 + 1
	}
	libsqlite3.Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 320)))
	brc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 312)))
	if rc == m_SQLITE_OK && brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+13484, 0)
		return brc
	}
	return rc
}

func Xvec0Update_Delete_ClearValidity(tls *libc.TLS, p uintptr, chunk_id Ti64, chunk_offset Tu64) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var brc, rc, validityOffset int32
	var mask uint8
	var _ /* blobChunksValidity at bp+0 */ uintptr
	var _ /* bx at bp+8 */ uint8
	var _ /* result at bp+9 */ uint8
	_, _, _, _ = brc, mask, rc, validityOffset
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	validityOffset = libc.Int32FromUint64(chunk_offset / uint64(m_CHAR_BIT))
	// 2. ensure chunks.validity bit is 1, then set to 0
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+11057, chunk_id, int32(1), bp)
	if rc != m_SQLITE_OK {
		// IMP: V26002_10073
		Xvtab_set_error(tls, p, __ccgo_ts+13587, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_id))
		return int32(m_SQLITE_ERROR)
	}
	// will skip the sqlite3_blob_bytes(blobChunksValidity) check for now,
	// the read below would catch it
	rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+8, int32(1), validityOffset)
	if rc != m_SQLITE_OK {
		// IMP: V21193_05263
		Xvtab_set_error(tls, p, __ccgo_ts+13631, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_id, validityOffset))
		goto cleanup
	}
	if !(libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(bp + 8)))>>(chunk_offset%libc.Uint64FromInt32(m_CHAR_BIT)) != 0) {
		// IMP: V21193_05263
		rc = int32(m_SQLITE_ERROR)
		Xvtab_set_error(tls, p, __ccgo_ts+13681, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_id, validityOffset))
		goto cleanup
	}
	mask = libc.Uint8FromInt32(^(libc.Int32FromInt32(1) << (chunk_offset % libc.Uint64FromInt32(m_CHAR_BIT))))
	*(*uint8)(unsafe.Pointer(bp + 9)) = libc.Uint8FromInt32(libc.Int32FromUint8(*(*uint8)(unsafe.Pointer(bp + 8))) & libc.Int32FromUint8(mask))
	rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+9, int32(1), validityOffset)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+13747, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_id, validityOffset))
		goto cleanup
	}
	goto cleanup
cleanup:
	;
	brc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != m_SQLITE_OK {
		return rc
	}
	if brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+13801, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, chunk_id, validityOffset))
		return brc
	}
	return m_SQLITE_OK
}

func Xvec0Update_Delete_DeleteRowids(tls *libc.TLS, p uintptr, rowid Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _ = rc, zSql
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+13884, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != int32(m_SQLITE_DONE) {
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func Xvec0Update_Delete_DeleteAux(tls *libc.TLS, p uintptr, rowid Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _ = rc, zSql
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+13929, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != int32(m_SQLITE_DONE) {
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func Xvec0Update_Delete_ClearMetadata(tls *libc.TLS, p uintptr, metadata_idx int32, rowid Ti64, chunk_id Ti64, chunk_offset Tu64) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var kind Tvec0_metadata_column_kind
	var rc, rc2 int32
	var zSql uintptr
	var _ /* blobValue at bp+0 */ uintptr
	var _ /* block at bp+8 */ Tu8
	var _ /* n at bp+32 */ int32
	var _ /* stmt at bp+56 */ uintptr
	var _ /* v at bp+16 */ Ti64
	var _ /* v at bp+24 */ float64
	var _ /* view at bp+36 */ [16]Tu8
	_, _, _, _ = kind, rc, rc2, zSql
	kind = (*(*TVec0MetadataColumnDefinition)(unsafe.Pointer(p + 1600 + uintptr(metadata_idx)*24))).Fkind
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 480 + uintptr(metadata_idx)*8)), __ccgo_ts+4039, chunk_id, int32(1), bp)
	if rc != m_SQLITE_OK {
		return rc
	}
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+8, int32(1), libc.Int32FromUint64(chunk_offset/libc.Uint64FromInt32(m_CHAR_BIT)))
		if rc != m_SQLITE_OK {
			goto done
		}
		*(*Tu8)(unsafe.Pointer(bp + 8)) = libc.Uint8FromInt32(int32(*(*Tu8)(unsafe.Pointer(bp + 8))) & ^(libc.Int32FromInt32(1) << (chunk_offset % libc.Uint64FromInt32(m_CHAR_BIT))))
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+8, int32(1), libc.Int32FromUint64(chunk_offset/uint64(m_CHAR_BIT)))
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		*(*Ti64)(unsafe.Pointer(bp + 16)) = 0
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+16, int32(8), libc.Int32FromUint64(chunk_offset*uint64(8)))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		*(*float64)(unsafe.Pointer(bp + 24)) = libc.Float64FromInt32(0)
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+24, int32(8), libc.Int32FromUint64(chunk_offset*uint64(8)))
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		rc = libsqlite3.Xsqlite3_blob_read(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+32, int32(4), libc.Int32FromUint64(chunk_offset*uint64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)))
		if rc != m_SQLITE_OK {
			goto done
		}
		libc.Xmemset(tls, bp+36, 0, uint64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		rc = libsqlite3.Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+36, int32(16), libc.Int32FromUint64(chunk_offset*uint64(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)))
		if rc != m_SQLITE_OK {
			goto done
		}
		if *(*int32)(unsafe.Pointer(bp + 32)) > int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+12837, libc.VaList(bp+72, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, metadata_idx))
			if !(zSql != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto done
			}
			rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+56, libc.UintptrFromInt32(0))
			if rc != m_SQLITE_OK {
				goto done
			}
			libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), int32(1), rowid)
			rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
			if rc != int32(m_SQLITE_DONE) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
		}
		break
	}
	goto done
done:
	;
	rc2 = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == m_SQLITE_OK {
		return rc2
	}
	return rc
}

func Xvec0Update_Delete(tls *libc.TLS, pVTab uintptr, idValue uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, rc int32
	var p uintptr
	var _ /* chunk_id at bp+8 */ Ti64
	var _ /* chunk_offset at bp+16 */ Ti64
	var _ /* rowid at bp+0 */ Ti64
	_, _, _ = i, p, rc
	p = pVTab
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
		rc = Xvec0_rowid_from_id(tls, p, idValue, bp)
		if rc != m_SQLITE_OK {
			return rc
		}
	} else {
		*(*Ti64)(unsafe.Pointer(bp)) = libsqlite3.Xsqlite3_value_int64(tls, idValue)
	}
	// 1. Find chunk position for given rowid
	// 2. Ensure that validity bit for position is 1, then set to 0
	// 3. Zero out rowid in chunks.rowid
	// 4. Zero out vector data in all vector column chunks
	// 5. Delete value in _rowids table
	// 1. get chunk_id and chunk_offset from _rowids
	rc = Xvec0_get_chunk_position(tls, p, *(*Ti64)(unsafe.Pointer(bp)), libc.UintptrFromInt32(0), bp+8, bp+16)
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = Xvec0Update_Delete_ClearValidity(tls, p, *(*Ti64)(unsafe.Pointer(bp + 8)), libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 16))))
	if rc != m_SQLITE_OK {
		return rc
	}
	// 3. zero out rowid in chunks.rowids
	// https://github.com/asg017/sqlite-vec/issues/54
	// 4. zero out any data in vector chunks tables
	// https://github.com/asg017/sqlite-vec/issues/54
	// 5. delete from _rowids table
	rc = Xvec0Update_Delete_DeleteRowids(tls, p, *(*Ti64)(unsafe.Pointer(bp)))
	if rc != m_SQLITE_OK {
		return rc
	}
	// 6. delete any auxiliary rows
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns > 0 {
		rc = Xvec0Update_Delete_DeleteAux(tls, p, *(*Ti64)(unsafe.Pointer(bp)))
		if rc != m_SQLITE_OK {
			return rc
		}
	}
	// 6. delete metadata
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumMetadataColumns) {
			break
		}
		rc = Xvec0Update_Delete_ClearMetadata(tls, p, i, *(*Ti64)(unsafe.Pointer(bp)), *(*Ti64)(unsafe.Pointer(bp + 8)), libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 16))))
		goto _1
	_1:
		;
		i = i + 1
	}
	return m_SQLITE_OK
}

func Xvec0Update_UpdateAuxColumn(tls *libc.TLS, p uintptr, auxiliary_column_idx int32, value uintptr, rowid Ti64) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _ = rc, zSql
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+13977, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, auxiliary_column_idx))
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	libsqlite3.Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(1), value)
	libsqlite3.Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(2), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != int32(m_SQLITE_DONE) {
		libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return int32(m_SQLITE_ERROR)
	}
	libsqlite3.Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return m_SQLITE_OK
}

func Xvec0Update_UpdateVectorColumn(tls *libc.TLS, p uintptr, chunk_id Ti64, chunk_offset Ti64, i int32, valueVector uintptr) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var brc, rc int32
	var _ /* blobVectors at bp+0 */ uintptr
	var _ /* cleanup at bp+40 */ Tvector_cleanup
	var _ /* dimensions at bp+16 */ Tsize_t
	var _ /* elementType at bp+24 */ _VectorElementType
	var _ /* pzError at bp+8 */ uintptr
	var _ /* vector at bp+32 */ uintptr
	_, _ = brc, rc
	*(*uintptr)(unsafe.Pointer(bp)) = libc.UintptrFromInt32(0)
	*(*Tvector_cleanup)(unsafe.Pointer(bp + 40)) = __ccgo_fp(Xvector_cleanup_noop)
	// https://github.com/asg017/sqlite-vec/issues/53
	rc = Xvector_from_value(tls, valueVector, bp+32, bp+16, bp+24, bp+40, bp+8)
	if rc != m_SQLITE_OK {
		// IMP: V15203_32042
		Xvtab_set_error(tls, p, __ccgo_ts+14038, libc.VaList(bp+56, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname, *(*uintptr)(unsafe.Pointer(bp + 8))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if *(*_VectorElementType)(unsafe.Pointer(bp + 24)) != (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Felement_type {
		// IMP: V03643_20481
		Xvtab_set_error(tls, p, __ccgo_ts+14090, libc.VaList(bp+56, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname, Xvector_subtype_name(tls, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Felement_type), Xvector_subtype_name(tls, *(*_VectorElementType)(unsafe.Pointer(bp + 24)))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if *(*Tsize_t)(unsafe.Pointer(bp + 16)) != (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fdimensions {
		// IMP: V25739_09810
		Xvtab_set_error(tls, p, __ccgo_ts+14187, libc.VaList(bp+56, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname_length, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fname, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fdimensions, *(*Tsize_t)(unsafe.Pointer(bp + 16))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), __ccgo_ts+3698, chunk_id, int32(1), bp)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+14292, libc.VaList(bp+56, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_id))
		goto cleanup
	}
	rc = _vec0_write_vector_to_vector_blob(tls, *(*uintptr)(unsafe.Pointer(bp)), chunk_offset, *(*uintptr)(unsafe.Pointer(bp + 32)), (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Fdimensions, (*(*TVectorColumnDefinition)(unsafe.Pointer(p + 608 + uintptr(i)*32))).Felement_type)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+14335, libc.VaList(bp+56, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_id))
		goto cleanup
	}
	goto cleanup
cleanup:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 40)))(tls, *(*uintptr)(unsafe.Pointer(bp + 32)))
	brc = libsqlite3.Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc != m_SQLITE_OK {
		return rc
	}
	if brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+14382, libc.VaList(bp+56, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, *(*uintptr)(unsafe.Pointer(p + 352 + uintptr(i)*8)), chunk_id))
		return brc
	}
	return m_SQLITE_OK
}

func Xvec0Update_Update(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, b, p, value, value1, value2, valueVector uintptr
	var auxiliary_column_idx, i, i1, i2, i3, metadata_column_idx, rc, vector_idx int32
	var _ /* chunk_id at bp+0 */ Ti64
	var _ /* chunk_offset at bp+8 */ Ti64
	var _ /* rowid at bp+16 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, auxiliary_column_idx, b, i, i1, i2, i3, metadata_column_idx, p, rc, value, value1, value2, valueVector, vector_idx
	_ = argc
	p = pVTab
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
		a = libsqlite3.Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		b = libsqlite3.Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		// IMP: V08886_25725
		if libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))) != libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) || libc.Xstrncmp(tls, a, b, libc.Uint64FromInt32(libsqlite3.Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))) != 0 {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+14448, 0)
			return int32(m_SQLITE_ERROR)
		}
		rc = Xvec0_rowid_from_id(tls, p, *(*uintptr)(unsafe.Pointer(argv)), bp+16)
		if rc != m_SQLITE_OK {
			return rc
		}
	} else {
		*(*Ti64)(unsafe.Pointer(bp + 16)) = libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	}
	// 1) get chunk_id and chunk_offset from _rowids
	rc = Xvec0_get_chunk_position(tls, p, *(*Ti64)(unsafe.Pointer(bp + 16)), libc.UintptrFromInt32(0), bp, bp+8)
	if rc != m_SQLITE_OK {
		return rc
	}
	// 2) update any partition key values
	i = 0
	for {
		if !(i < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
			goto _1
		}
		value = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i)*8))
		if libsqlite3.Xsqlite3_value_nochange(tls, value) != 0 {
			goto _1
		}
		Xvtab_set_error(tls, pVTab, __ccgo_ts+14500, 0)
		return int32(m_SQLITE_ERROR)
		goto _1
	_1:
		;
		i = i + 1
	}
	// 3) handle auxiliary column updates
	i1 = 0
	for {
		if !(i1 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i1)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY) {
			goto _2
		}
		auxiliary_column_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i1))))
		value1 = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i1)*8))
		if libsqlite3.Xsqlite3_value_nochange(tls, value1) != 0 {
			goto _2
		}
		rc = Xvec0Update_UpdateAuxColumn(tls, p, auxiliary_column_idx, value1, *(*Ti64)(unsafe.Pointer(bp + 16)))
		if rc != m_SQLITE_OK {
			return int32(m_SQLITE_ERROR)
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	// 4) handle metadata column updates
	i2 = 0
	for {
		if !(i2 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i2)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _3
		}
		metadata_column_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i2))))
		value2 = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i2)*8))
		if libsqlite3.Xsqlite3_value_nochange(tls, value2) != 0 {
			goto _3
		}
		rc = Xvec0_write_metadata_value(tls, p, metadata_column_idx, *(*Ti64)(unsafe.Pointer(bp + 16)), *(*Ti64)(unsafe.Pointer(bp)), *(*Ti64)(unsafe.Pointer(bp + 8)), value2, int32(1))
		if rc != m_SQLITE_OK {
			return rc
		}
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	// 5) iterate over all new vectors, update the vectors
	i3 = 0
	for {
		if !(i3 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if *(*Tvec0_user_column_kind)(unsafe.Pointer(p + 88 + uintptr(i3)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _4
		}
		vector_idx = libc.Int32FromUint8(*(*Tuint8_t)(unsafe.Pointer(p + 296 + uintptr(i3))))
		valueVector = *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i3)*8))
		// in vec0Column, we check sqlite3_vtab_nochange() on vector columns.
		// If the vector column isn't being changed, we return NULL;
		// That's not great, that means vector columns can never be NULLABLE
		// (bc we cant distinguish if an updated vector is truly NULL or nochange).
		// Also it means that if someone tries to run `UPDATE v SET X = NULL`,
		// we can't effectively detect and raise an error.
		// A better solution would be to use a custom result_type for "empty",
		// but subtypes don't appear to survive xColumn -> xUpdate, it's always 0.
		// So for now, we'll just use NULL and warn people to not SET X = NULL
		// in the docs.
		if libsqlite3.Xsqlite3_value_type(tls, valueVector) == int32(m_SQLITE_NULL) {
			goto _4
		}
		rc = Xvec0Update_UpdateVectorColumn(tls, p, *(*Ti64)(unsafe.Pointer(bp)), *(*Ti64)(unsafe.Pointer(bp + 8)), vector_idx, valueVector)
		if rc != m_SQLITE_OK {
			return int32(m_SQLITE_ERROR)
		}
		goto _4
	_4:
		;
		i3 = i3 + 1
	}
	return m_SQLITE_OK
}

func _vec0Update(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
	// DELETE operation
	if argc == int32(1) && libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) != int32(m_SQLITE_NULL) {
		return Xvec0Update_Delete(tls, pVTab, *(*uintptr)(unsafe.Pointer(argv)))
	} else {
		if argc > int32(1) && libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(m_SQLITE_NULL) {
			return Xvec0Update_Insert(tls, pVTab, argc, argv, pRowid)
		} else {
			if argc > int32(1) && libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) != int32(m_SQLITE_NULL) {
				return Xvec0Update_Update(tls, pVTab, argc, argv)
			} else {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+14556, 0)
				return int32(m_SQLITE_ERROR)
			}
		}
	}
	return r
}

func _vec0ShadowName(tls *libc.TLS, zName uintptr) (r int32) {
	var i Tsize_t
	_ = i
	i = uint64(0)
	for {
		if !(i < libc.Uint64FromInt64(288)/libc.Uint64FromInt64(8)) {
			break
		}
		if libsqlite3.Xsqlite3_stricmp(tls, zName, _azName[i]) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	//for(size_t i = 0; i < )"vector_chunks", "metadatachunks"
	return 0
}

var _azName = [36]uintptr{
	0:  __ccgo_ts + 9540,
	1:  __ccgo_ts + 14606,
	2:  __ccgo_ts + 14613,
	3:  __ccgo_ts + 14623,
	4:  __ccgo_ts + 14628,
	5:  __ccgo_ts + 14645,
	6:  __ccgo_ts + 14662,
	7:  __ccgo_ts + 14679,
	8:  __ccgo_ts + 14696,
	9:  __ccgo_ts + 14713,
	10: __ccgo_ts + 14730,
	11: __ccgo_ts + 14747,
	12: __ccgo_ts + 14764,
	13: __ccgo_ts + 14781,
	14: __ccgo_ts + 14798,
	15: __ccgo_ts + 14815,
	16: __ccgo_ts + 14832,
	17: __ccgo_ts + 14849,
	18: __ccgo_ts + 14866,
	19: __ccgo_ts + 14883,
	20: __ccgo_ts + 14900,
	21: __ccgo_ts + 14915,
	22: __ccgo_ts + 14930,
	23: __ccgo_ts + 14945,
	24: __ccgo_ts + 14960,
	25: __ccgo_ts + 14975,
	26: __ccgo_ts + 14990,
	27: __ccgo_ts + 15005,
	28: __ccgo_ts + 15020,
	29: __ccgo_ts + 15035,
	30: __ccgo_ts + 15050,
	31: __ccgo_ts + 15065,
	32: __ccgo_ts + 15080,
	33: __ccgo_ts + 15095,
	34: __ccgo_ts + 15110,
	35: __ccgo_ts + 15125,
}

func _vec0Begin(tls *libc.TLS, pVTab uintptr) (r int32) {
	_ = pVTab
	return m_SQLITE_OK
}

func _vec0Sync(tls *libc.TLS, pVTab uintptr) (r int32) {
	var p uintptr
	_ = p
	_ = pVTab
	p = pVTab
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
		(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
		(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
		(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
		(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition = libc.UintptrFromInt32(0)
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
		(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition = libc.UintptrFromInt32(0)
	}
	return m_SQLITE_OK
}

func _vec0Commit(tls *libc.TLS, pVTab uintptr) (r int32) {
	_ = pVTab
	return m_SQLITE_OK
}

func _vec0Rollback(tls *libc.TLS, pVTab uintptr) (r int32) {
	_ = pVTab
	return m_SQLITE_OK
}

var _vec0Module = Tsqlite3_module{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_vec0Module)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec0Create)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec0Connect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec0BestIndex)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec0Disconnect)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec0Destroy)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec0Open)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec0Close)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_vec0Filter)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_vec0Next)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_vec0Eof)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_vec0Column)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_vec0Rowid)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(_vec0Update)
	*(*uintptr)(unsafe.Add(p, 112)) = __ccgo_fp(_vec0Begin)
	*(*uintptr)(unsafe.Add(p, 120)) = __ccgo_fp(_vec0Sync)
	*(*uintptr)(unsafe.Add(p, 128)) = __ccgo_fp(_vec0Commit)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_vec0Rollback)
	*(*uintptr)(unsafe.Add(p, 184)) = __ccgo_fp(_vec0ShadowName)
}

var _POINTER_NAME_STATIC_BLOB_DEF = __ccgo_ts + 15140

type Tstatic_blob_definition = struct {
	Fp            uintptr
	Fdimensions   Tsize_t
	Fnvectors     Tsize_t
	Felement_type _VectorElementType
}

type static_blob_definition = Tstatic_blob_definition

func _vec_static_blob_from_raw(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = libsqlite3.Xsqlite3_malloc(tls, int32(32))
	if !(p != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
		return
	}
	libc.Xmemset(tls, p, 0, uint64(32))
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Fp = uintptr(libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv))))
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Felement_type = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Fdimensions = libc.Uint64FromInt64(libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Fnvectors = libc.Uint64FromInt64(libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8))))
	libsqlite3.Xsqlite3_result_pointer(tls, context, p, _POINTER_NAME_STATIC_BLOB_DEF, __ccgo_fp(libsqlite3.Xsqlite3_free))
}

type Tstatic_blob = struct {
	Fname         uintptr
	Fp            uintptr
	Fdimensions   Tsize_t
	Fnvectors     Tsize_t
	Felement_type _VectorElementType
}

type static_blob = Tstatic_blob

type Tvec_static_blob_data = struct {
	Fstatic_blobs [16]Tstatic_blob
}

type vec_static_blob_data = Tvec_static_blob_data

type Tvec_static_blobs_vtab = struct {
	Fbase Tsqlite3_vtab
	Fdata uintptr
}

type vec_static_blobs_vtab = Tvec_static_blobs_vtab

type Tvec_static_blobs_cursor = struct {
	Fbase   Tsqlite3_vtab_cursor
	FiRowid Tsqlite3_int64
}

type vec_static_blobs_cursor = Tvec_static_blobs_cursor

func _vec_static_blobsConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	_ = argc
	_ = argv
	_ = pzErr
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+15161)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(32))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint64(32))
		(*Tvec_static_blobs_vtab)(unsafe.Pointer(pNew)).Fdata = pAux
	}
	return rc
}

func _vec_static_blobsDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pVtab
	libsqlite3.Xsqlite3_free(tls, p)
	return m_SQLITE_OK
}

func _vec_static_blobsUpdate(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var def, key, p uintptr
	var i, idx int32
	_, _, _, _, _ = def, i, idx, key, p
	_ = pRowid
	p = pVTab
	// DELETE operation
	if argc == int32(1) && libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) != int32(m_SQLITE_NULL) {
		return int32(m_SQLITE_ERROR)
	} else {
		if argc > int32(1) && libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == int32(m_SQLITE_NULL) {
			key = libsqlite3.Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC_STATIC_BLOBS_NAME))*8)))
			idx = -int32(1)
			i = 0
			for {
				if !(i < int32(m_MAX_STATIC_BLOBS)) {
					break
				}
				if !((*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(i)*40))).Fname != 0) {
					(*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(i)*40))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6562, libc.VaList(bp+8, key))
					idx = i
					break
				}
				goto _1
			_1:
				;
				i = i + 1
			}
			if idx < 0 {
				libc.Xabort(tls)
			}
			def = libsqlite3.Xsqlite3_value_pointer(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC_STATIC_BLOBS_DATA))*8)), _POINTER_NAME_STATIC_BLOB_DEF)
			(*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*40))).Fp = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Fp
			(*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*40))).Fdimensions = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Fdimensions
			(*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*40))).Fnvectors = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Fnvectors
			(*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*40))).Felement_type = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Felement_type
			return m_SQLITE_OK
		} else {
			if argc > int32(1) && libsqlite3.Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) != int32(m_SQLITE_NULL) {
				return int32(m_SQLITE_ERROR)
			}
		}
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_static_blobsOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(16))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint64(16))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_static_blobsClose(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	libsqlite3.Xsqlite3_free(tls, pCur)
	return m_SQLITE_OK
}

func _vec_static_blobsBestIndex(tls *libc.TLS, pVTab uintptr, pIdxInfo uintptr) (r int32) {
	_ = pVTab
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(1)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(10)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
	return m_SQLITE_OK
}

func _vec_static_blobsFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = idxNum
	_ = idxStr
	_ = argc
	_ = argv
	pCur = pVtabCursor
	(*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid = int64(-int32(1))
	_vec_static_blobsNext(tls, pVtabCursor)
	return m_SQLITE_OK
}

func _vec_static_blobsRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid
	return m_SQLITE_OK
}

func _vec_static_blobsNext(tls *libc.TLS, cur uintptr) (r int32) {
	var p, pCur uintptr
	_, _ = p, pCur
	pCur = cur
	p = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	(*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	for (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid < int64(m_MAX_STATIC_BLOBS) {
		if (*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fname != 0 {
			return m_SQLITE_OK
		}
		(*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	}
	return m_SQLITE_OK
}

func _vec_static_blobsEof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	return libc.BoolInt32((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid >= int64(m_MAX_STATIC_BLOBS))
}

func _vec_static_blobsColumn(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var p, pCur uintptr
	_, _ = p, pCur
	pCur = cur
	p = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	switch i {
	case m_VEC_STATIC_BLOBS_NAME:
		libsqlite3.Xsqlite3_result_text(tls, context, (*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fname, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	case int32(m_VEC_STATIC_BLOBS_DATA):
		libsqlite3.Xsqlite3_result_null(tls, context)
	case int32(m_VEC_STATIC_BLOBS_DIMENSIONS):
		libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint64((*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fdimensions))
	case int32(m_VEC_STATIC_BLOBS_COUNT):
		libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint64((*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fnvectors))
		break
	}
	return m_SQLITE_OK
}

var _vec_static_blobsModule = Tsqlite3_module{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_vec_static_blobsModule)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_static_blobsConnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_static_blobsBestIndex)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_static_blobsDisconnect)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_static_blobsOpen)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec_static_blobsClose)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_vec_static_blobsFilter)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_vec_static_blobsNext)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_vec_static_blobsEof)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_vec_static_blobsColumn)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_vec_static_blobsRowid)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(_vec_static_blobsUpdate)
}

type Tvec_static_blob_entries_vtab = struct {
	Fbase Tsqlite3_vtab
	Fblob uintptr
}

type vec_static_blob_entries_vtab = Tvec_static_blob_entries_vtab

type Tvec_sbe_query_plan = int32

type vec_sbe_query_plan = Tvec_sbe_query_plan

const _VEC_SBE__QUERYPLAN_FULLSCAN = 1
const _VEC_SBE__QUERYPLAN_KNN = 2

type Tsbe_query_knn_data = struct {
	Fk           Ti64
	Fk_used      Ti64
	Frowids      uintptr
	Fdistances   uintptr
	Fcurrent_idx Ti64
}

type sbe_query_knn_data = Tsbe_query_knn_data

func Xsbe_query_knn_data_clear(tls *libc.TLS, knn_data uintptr) {
	if !(knn_data != 0) {
		return
	}
	if (*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Frowids != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Frowids)
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Frowids = libc.UintptrFromInt32(0)
	}
	if (*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances)
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances = libc.UintptrFromInt32(0)
	}
}

type Tvec_static_blob_entries_cursor = struct {
	Fbase       Tsqlite3_vtab_cursor
	FiRowid     Tsqlite3_int64
	Fquery_plan Tvec_sbe_query_plan
	Fknn_data   uintptr
}

type vec_static_blob_entries_cursor = Tvec_static_blob_entries_cursor

func _vec_static_blob_entriesConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var blob_data, pNew uintptr
	var i, idx, rc int32
	_, _, _, _, _ = blob_data, i, idx, pNew, rc
	_ = argc
	_ = argv
	_ = pzErr
	blob_data = pAux
	idx = -int32(1)
	i = 0
	for {
		if !(i < int32(m_MAX_STATIC_BLOBS)) {
			break
		}
		if !((*(*Tstatic_blob)(unsafe.Pointer(blob_data + uintptr(i)*40))).Fname != 0) {
			goto _1
		}
		if libc.Xstrncmp(tls, (*(*Tstatic_blob)(unsafe.Pointer(blob_data + uintptr(i)*40))).Fname, *(*uintptr)(unsafe.Pointer(argv + 3*8)), libc.Xstrlen(tls, (*(*Tstatic_blob)(unsafe.Pointer(blob_data + uintptr(i)*40))).Fname)) == 0 {
			idx = i
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if idx < 0 {
		libc.Xabort(tls)
	}
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+15221)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(32))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint64(32))
		(*Tvec_static_blob_entries_vtab)(unsafe.Pointer(pNew)).Fblob = blob_data + uintptr(idx)*40
	}
	return rc
}

func _vec_static_blob_entriesCreate(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	return _vec_static_blob_entriesConnect(tls, db, pAux, argc, argv, ppVtab, pzErr)
}

func _vec_static_blob_entriesDisconnect(tls *libc.TLS, pVtab uintptr) (r int32) {
	var p uintptr
	_ = p
	p = pVtab
	libsqlite3.Xsqlite3_free(tls, p)
	return m_SQLITE_OK
}

func _vec_static_blob_entriesOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(32))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint64(32))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_static_blob_entriesClose(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	libsqlite3.Xsqlite3_free(tls, (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)
	libsqlite3.Xsqlite3_free(tls, pCur)
	return m_SQLITE_OK
}

func _vec_static_blob_entriesBestIndex(tls *libc.TLS, pVTab uintptr, pIdxInfo uintptr) (r int32) {
	var i, iColumn, iKTerm, iLimitTerm, iMatchTerm, op int32
	var p uintptr
	_, _, _, _, _, _, _ = i, iColumn, iKTerm, iLimitTerm, iMatchTerm, op, p
	p = pVTab
	iMatchTerm = -int32(1)
	iLimitTerm = -int32(1)
	// int iRowidTerm = -1; // https://github.com/asg017/sqlite-vec/issues/47
	iKTerm = -int32(1)
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		if !((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fusable != 0) {
			goto _1
		}
		iColumn = (*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).FiColumn
		op = libc.Int32FromUint8((*(*Tsqlite3_index_constraint)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fop)
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_MATCH) && iColumn == m_VEC_STATIC_BLOB_ENTRIES_VECTOR {
			if iMatchTerm > -int32(1) {
				// https://github.com/asg017/sqlite-vec/issues/51
				return int32(m_SQLITE_ERROR)
			}
			iMatchTerm = i
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_LIMIT) {
			iLimitTerm = i
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_EQ) && iColumn == int32(m_VEC_STATIC_BLOB_ENTRIES_K) {
			iKTerm = i
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if iMatchTerm >= 0 {
		if iLimitTerm < 0 && iKTerm < 0 {
			// https://github.com/asg017/sqlite-vec/issues/51
			return int32(m_SQLITE_ERROR)
		}
		if iLimitTerm >= 0 && iKTerm >= 0 {
			return int32(m_SQLITE_ERROR) // limit or k, not both
		}
		if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy < int32(1) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+15271, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy > int32(1) {
			// https://github.com/asg017/sqlite-vec/issues/51
			Xvtab_set_error(tls, pVTab, __ccgo_ts+15298, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		if (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).FiColumn != int32(m_VEC_STATIC_BLOB_ENTRIES_DISTANCE) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+15335, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		if (*(*Tsqlite3_index_orderby)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).Fdesc != 0 {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+8794, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(_VEC_SBE__QUERYPLAN_KNN)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(10)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = int32(1)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iMatchTerm)*8))).FargvIndex = int32(1)
		(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iMatchTerm)*8))).Fomit = uint8(1)
		if iLimitTerm >= 0 {
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iLimitTerm)*8))).FargvIndex = int32(2)
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iLimitTerm)*8))).Fomit = uint8(1)
		} else {
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iKTerm)*8))).FargvIndex = int32(2)
			(*(*Tsqlite3_index_constraint_usage)(unsafe.Pointer((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iKTerm)*8))).Fomit = uint8(1)
		}
	} else {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(_VEC_SBE__QUERYPLAN_FULLSCAN)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = libc.Int64FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
	}
	return m_SQLITE_OK
}

func _vec_static_blob_entriesFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bsize, i, i1 Tsize_t
	var candidates, distances, knn_data, p, pCur, taken, topk_rowids, v uintptr
	var k Ti64
	var rc int32
	var v1 int64
	var _ /* cleanup at bp+24 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+16 */ _VectorElementType
	var _ /* err at bp+32 */ uintptr
	var _ /* k_used at bp+40 */ Ti32
	var _ /* queryVector at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bsize, candidates, distances, i, i1, k, knn_data, p, pCur, rc, taken, topk_rowids, v, v1
	_ = idxStr
	pCur = pVtabCursor
	p = (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	if idxNum == int32(_VEC_SBE__QUERYPLAN_KNN) {
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC_SBE__QUERYPLAN_KNN)
		knn_data = libsqlite3.Xsqlite3_malloc(tls, int32(40))
		if !(knn_data != 0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, knn_data, 0, uint64(40))
		rc = Xvector_from_value(tls, *(*uintptr)(unsafe.Pointer(argv)), bp, bp+8, bp+16, bp+24, bp+32)
		if rc != m_SQLITE_OK {
			return int32(m_SQLITE_ERROR)
		}
		if *(*_VectorElementType)(unsafe.Pointer(bp + 16)) != (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Felement_type {
			return int32(m_SQLITE_ERROR)
		}
		if *(*Tsize_t)(unsafe.Pointer(bp + 8)) != (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions {
			return int32(m_SQLITE_ERROR)
		}
		if libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) <= libc.Int64FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors) {
			v1 = libsqlite3.Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		} else {
			v1 = libc.Int64FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
		}
		k = v1
		if k < 0 {
			// HANDLE https://github.com/asg017/sqlite-vec/issues/55
			return int32(m_SQLITE_ERROR)
		}
		if k == 0 {
			(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fk = 0
			(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data = knn_data
			return m_SQLITE_OK
		}
		bsize = ((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors + uint64(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7))
		topk_rowids = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(libc.Uint64FromInt64(k)*uint64(4)))
		if !(topk_rowids != 0) {
			// HANDLE https://github.com/asg017/sqlite-vec/issues/55
			return int32(m_SQLITE_ERROR)
		}
		distances = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(bsize*uint64(4)))
		if !(distances != 0) {
			// HANDLE https://github.com/asg017/sqlite-vec/issues/55
			return int32(m_SQLITE_ERROR)
		}
		i = uint64(0)
		for {
			if !(i < (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors) {
				break
			}
			// https://github.com/asg017/sqlite-vec/issues/52
			v = (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fp + uintptr(i*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions)*4
			*(*Tf32)(unsafe.Pointer(distances + uintptr(i)*4)) = _distance_l2_sqr_float(tls, v, *(*uintptr)(unsafe.Pointer(bp)), (*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob+16)
			goto _2
		_2:
			;
			i = i + 1
		}
		candidates = Xbitmap_new(tls, libc.Int32FromUint64(bsize))
		taken = Xbitmap_new(tls, libc.Int32FromUint64(bsize))
		Xbitmap_fill(tls, candidates, libc.Int32FromUint64(bsize))
		i1 = bsize
		for {
			if !(i1 >= (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors) {
				break
			}
			Xbitmap_set(tls, candidates, libc.Int32FromUint64(i1), 0)
			goto _3
		_3:
			;
			i1 = i1 - 1
		}
		*(*Ti32)(unsafe.Pointer(bp + 40)) = 0
		Xmin_idx(tls, distances, libc.Int32FromUint64(bsize), candidates, topk_rowids, int32(k), taken, bp+40)
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fcurrent_idx = 0
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances = distances
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fk = k
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Frowids = topk_rowids
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data = knn_data
	} else {
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC_SBE__QUERYPLAN_FULLSCAN)
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	}
	return m_SQLITE_OK
}

func _vec_static_blob_entriesRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) (r int32) {
	var pCur uintptr
	var rowid Ti32
	_, _ = pCur, rowid
	pCur = cur
	switch (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC_SBE__QUERYPLAN_FULLSCAN):
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid
		return m_SQLITE_OK
	case int32(_VEC_SBE__QUERYPLAN_KNN):
		rowid = *(*Ti32)(unsafe.Pointer((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*4))
		*(*Tsqlite_int64)(unsafe.Pointer(pRowid)) = int64(rowid)
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_static_blob_entriesNext(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	switch (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC_SBE__QUERYPLAN_FULLSCAN):
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
		return m_SQLITE_OK
	case int32(_VEC_SBE__QUERYPLAN_KNN):
		(*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx = (*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx + 1
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_static_blob_entriesEof(tls *libc.TLS, cur uintptr) (r int32) {
	var p, pCur uintptr
	_, _ = p, pCur
	pCur = cur
	p = (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	switch (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC_SBE__QUERYPLAN_FULLSCAN):
		return libc.BoolInt32(libc.Uint64FromInt64((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid) >= (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
	case int32(_VEC_SBE__QUERYPLAN_KNN):
		return libc.BoolInt32((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx >= (*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fk)
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_static_blob_entriesColumn(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var p, pCur uintptr
	var rowid Ti32
	_, _, _ = p, pCur, rowid
	pCur = cur
	p = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	switch (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC_SBE__QUERYPLAN_FULLSCAN):
		switch i {
		case m_VEC_STATIC_BLOB_ENTRIES_VECTOR:
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fp+uintptr(libc.Uint64FromInt64((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid)*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*libc.Uint64FromInt64(4)), libc.Int32FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Felement_type))
			break
		}
		return m_SQLITE_OK
	case int32(_VEC_SBE__QUERYPLAN_KNN):
		switch i {
		case m_VEC_STATIC_BLOB_ENTRIES_VECTOR:
			rowid = *(*Ti32)(unsafe.Pointer((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*4))
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fp+uintptr(libc.Uint64FromInt32(rowid)*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*libc.Uint64FromInt64(4)), libc.Int32FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Felement_type))
			break
		}
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

var _vec_static_blob_entriesModule = Tsqlite3_module{
	FiVersion: int32(3),
}

func init() {
	p := unsafe.Pointer(&_vec_static_blob_entriesModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec_static_blob_entriesCreate)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_static_blob_entriesConnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_static_blob_entriesBestIndex)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_static_blob_entriesDisconnect)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec_static_blob_entriesDisconnect)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_static_blob_entriesOpen)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec_static_blob_entriesClose)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_vec_static_blob_entriesFilter)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_vec_static_blob_entriesNext)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_vec_static_blob_entriesEof)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_vec_static_blob_entriesColumn)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_vec_static_blob_entriesRowid)
}

func Xsqlite3_vec_init(tls *libc.TLS, db uintptr, pzErrMsg uintptr, pApi uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1 uint64
	var rc int32
	_, _, _ = i, i1, rc
	rc = m_SQLITE_OK
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+15375, 0, libc.Int32FromInt32(m_SQLITE_UTF8)|libc.Int32FromInt32(m_SQLITE_INNOCUOUS)|libc.Int32FromInt32(m_SQLITE_DETERMINISTIC), __ccgo_ts+6873, __ccgo_fp(__static_text_func), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+15387, 0, libc.Int32FromInt32(m_SQLITE_UTF8)|libc.Int32FromInt32(m_SQLITE_INNOCUOUS)|libc.Int32FromInt32(m_SQLITE_DETERMINISTIC), __ccgo_ts+15397, __ccgo_fp(__static_text_func), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	i = uint64(0)
	for {
		if !(i < libc.Uint64FromInt64(384)/libc.Uint64FromInt64(24) && rc == m_SQLITE_OK) {
			break
		}
		rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, _aFunc[i].FzFName, _aFunc[i].FnArg, _aFunc[i].Fflags, libc.UintptrFromInt32(0), _aFunc[i].FxFunc, libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pzErrMsg)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+15691, libc.VaList(bp+8, _aFunc[i].FzFName, libsqlite3.Xsqlite3_errmsg(tls, db)))
			return rc
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	i1 = uint64(0)
	for {
		if !(i1 < libc.Uint64FromInt64(64)/libc.Uint64FromInt64(32) && rc == m_SQLITE_OK) {
			break
		}
		rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, _aMod[i1].Fname, _aMod[i1].Fmodule, libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pzErrMsg)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+15722, libc.VaList(bp+8, _aMod[i1].Fname, libsqlite3.Xsqlite3_errmsg(tls, db)))
			return rc
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	return m_SQLITE_OK
}

var _aFunc = [16]struct {
	FzFName uintptr
	FxFunc  uintptr
	FnArg   int32
	Fflags  int32
}{
	0: {
		FzFName: __ccgo_ts + 15469,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE),
	},
	1: {
		FzFName: __ccgo_ts + 15485,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE),
	},
	2: {
		FzFName: __ccgo_ts + 15501,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE),
	},
	3: {
		FzFName: __ccgo_ts + 15522,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE),
	},
	4: {
		FzFName: __ccgo_ts + 15542,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE),
	},
	5: {
		FzFName: __ccgo_ts + 15553,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC),
	},
	6: {
		FzFName: __ccgo_ts + 15562,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	7: {
		FzFName: __ccgo_ts + 15574,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	8: {
		FzFName: __ccgo_ts + 15582,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	9: {
		FzFName: __ccgo_ts + 15590,
		FnArg:   int32(3),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	10: {
		FzFName: __ccgo_ts + 15600,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	11: {
		FzFName: __ccgo_ts + 15614,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	12: {
		FzFName: __ccgo_ts + 15622,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	13: {
		FzFName: __ccgo_ts + 15630,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	14: {
		FzFName: __ccgo_ts + 15639,
		FnArg:   int32(2),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
	15: {
		FzFName: __ccgo_ts + 15657,
		FnArg:   int32(1),
		Fflags:  libc.Int32FromInt32(m_SQLITE_UTF8) | libc.Int32FromInt32(m_SQLITE_INNOCUOUS) | libc.Int32FromInt32(m_SQLITE_DETERMINISTIC) | libc.Int32FromInt32(m_SQLITE_SUBTYPE) | libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE),
	},
}

func init() {
	p := unsafe.Pointer(&_aFunc)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec_distance_l2)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_distance_l1)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec_distance_hamming)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_vec_distance_cosine)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(_vec_length)
	*(*uintptr)(unsafe.Add(p, 128)) = __ccgo_fp(_vec_type)
	*(*uintptr)(unsafe.Add(p, 152)) = __ccgo_fp(_vec_to_json)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_vec_add)
	*(*uintptr)(unsafe.Add(p, 200)) = __ccgo_fp(_vec_sub)
	*(*uintptr)(unsafe.Add(p, 224)) = __ccgo_fp(_vec_slice)
	*(*uintptr)(unsafe.Add(p, 248)) = __ccgo_fp(_vec_normalize)
	*(*uintptr)(unsafe.Add(p, 272)) = __ccgo_fp(_vec_f32)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_vec_bit)
	*(*uintptr)(unsafe.Add(p, 320)) = __ccgo_fp(_vec_int8)
	*(*uintptr)(unsafe.Add(p, 344)) = __ccgo_fp(_vec_quantize_int8)
	*(*uintptr)(unsafe.Add(p, 368)) = __ccgo_fp(_vec_quantize_binary)
}

var _aMod = [2]struct {
	Fname     uintptr
	Fmodule   uintptr
	Fp        uintptr
	FxDestroy uintptr
}{
	0: {
		Fname:   __ccgo_ts + 15677,
		Fmodule: uintptr(unsafe.Pointer(&_vec0Module)),
	},
	1: {
		Fname:   __ccgo_ts + 15682,
		Fmodule: uintptr(unsafe.Pointer(&_vec_eachModule)),
	},
}

func Xsqlite3_vec_numpy_init(tls *libc.TLS, db uintptr, pzErrMsg uintptr, pApi uintptr) (r int32) {
	var rc int32
	_ = rc
	_ = pzErrMsg
	rc = m_SQLITE_OK
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+15751, int32(1), int32(m_SQLITE_RESULT_SUBTYPE), libc.UintptrFromInt32(0), __ccgo_fp(_vec_npy_file), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, __ccgo_ts+15764, uintptr(unsafe.Pointer(&_vec_npy_eachModule)), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	return rc
}

func Xsqlite3_vec_static_blobs_init(tls *libc.TLS, db uintptr, pzErrMsg uintptr, pApi uintptr) (r int32) {
	var rc int32
	var static_blob_data uintptr
	_, _ = rc, static_blob_data
	_ = pzErrMsg
	rc = m_SQLITE_OK
	static_blob_data = libsqlite3.Xsqlite3_malloc(tls, int32(640))
	if !(static_blob_data != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, static_blob_data, 0, uint64(640))
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+15777, int32(4), libc.Int32FromInt32(m_SQLITE_UTF8)|libc.Int32FromInt32(m_SQLITE_INNOCUOUS)|libc.Int32FromInt32(m_SQLITE_DETERMINISTIC)|libc.Int32FromInt32(m_SQLITE_SUBTYPE)|libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE), libc.UintptrFromInt32(0), __ccgo_fp(_vec_static_blob_from_raw), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, __ccgo_ts+15802, uintptr(unsafe.Pointer(&_vec_static_blobsModule)), static_blob_data, __ccgo_fp(libsqlite3.Xsqlite3_free))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, __ccgo_ts+15819, uintptr(unsafe.Pointer(&_vec_static_blob_entriesModule)), static_blob_data, libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	return rc
}

type Tsqlite3_index_constraint = struct {
	FiColumn     int32
	Fop          uint8
	Fusable      uint8
	FiTermOffset int32
}

type sqlite3_index_constraint = Tsqlite3_index_constraint

type Tsqlite3_index_constraint_usage = struct {
	FargvIndex int32
	Fomit      uint8
}

type sqlite3_index_constraint_usage = Tsqlite3_index_constraint_usage

type Tsqlite3_index_orderby = struct {
	FiColumn int32
	Fdesc    uint8
}

type sqlite3_index_orderby = Tsqlite3_index_orderby

func __ccgo_fp(f interface{}) uintptr {
	type iface [2]uintptr
	return (*iface)(unsafe.Pointer(&f))[1]
}

var __ccgo_ts = (*reflect.StringHeader)(unsafe.Pointer(&__ccgo_ts1)).Data

var __ccgo_ts1 = "float32\x00int8\x00bit\x00\x00INTEGER\x00BLOB\x00TEXT\x00FLOAT\x00NULL\x00zero-length vectors are not supported.\x00invalid float32 vector BLOB length. Must be divisible by %d, found %d\x00JSON array parsing error: Input does not start with '['\x00JSON parsing error\x00Input must have type BLOB (compact format) or TEXT (JSON), found %s\x00Unknown type for bitvector.\x00JSON parsing error: value out of range for int8\x00Unknown type for int8 vector.\x00Unknown subtype: %d\x00Error reading 1st vector: %s\x00Error reading 2nd vector: %s\x00Vector type mistmatch. First vector has type %s, while the second has type %s.\x00Vector dimension mistmatch. First vector has %ld dimensions, while the second has %ld dimensions.\x00vec0-npy-file\x00Cannot calculate cosine distance between two bitvectors.\x00Cannot calculate L2 distance between two bitvectors.\x00Cannot calculate L1 distance between two bitvectors.\x00Cannot calculate hamming distance between two float32 vectors.\x00Cannot calculate hamming distance between two int8 vectors.\x00Zero length vectors are not supported.\x00Binary quantization requires vectors with a length divisible by 8\x00Can only binary quantize float or int8 vectors\x00unit\x002nd argument to vec_quantize_int8() must be 'unit'.\x00Cannot add two bitvectors together.\x00Cannot subtract two bitvectors together.\x00slice 'start' index must be a postive number.\x00slice 'end' index must be a postive number.\x00slice 'start' index is greater than the number of dimensions\x00slice 'end' index is greater than the number of dimensions\x00slice 'start' index is greater than 'end' index\x00slice 'start' index is equal to the 'end' index, vectors must have non-zero length\x00start index must be divisible by 8.\x00end index must be divisible by 8.\x00[\x00,\x00null\x00%f\x00%d\x00]\x00only float32 vectors are supported when normalizing\x00text\x00int\x00integer\x00partition\x00key\x00float\x00double\x00blob\x00boolean\x00bool\x00int64\x00integer64\x00float64\x00f64\x00primary\x00f32\x00i8\x00distance_metric\x00l2\x00l1\x00cosine\x00%.*s\x00CREATE TABLE x(value, vector hidden)\x00False\x00Error parsing numpy array: numpy header did not start with '{'\x00Error parsing numpy array: expected key in numpy header\x00Error parsing numpy array: expected a string as key in numpy header\x00Error parsing numpy array: expected a ':' after key in numpy header\x00'descr'\x00Error parsing numpy array: expected a string value after 'descr' key\x00'<f4'\x00Error parsing numpy array: Only '<f4' values are supported in sqlite-vec numpy functions\x00'fortran_order'\x00Error parsing numpy array: Only fortran_order = False is supported in sqlite-vec numpy functions\x00'shape'\x00Error parsing numpy array: Expected left parenthesis '(' after shape key\x00Error parsing numpy array: Expected an initial number in shape value\x00Error parsing numpy array: Expected comma after first shape value\x00Error parsing numpy array: unexpected header EOF while parsing shape\x00Error parsing numpy array: expected right parenthesis after shape value\x00Error parsing numpy array: unknown type in shape value\x00Error parsing numpy array: unknown key in numpy header\x00Error parsing numpy array: unknown extra token after value\x00numpy array file too short\x00numpy array file does not contain the 'magic' header\x00numpy array file header length is invalid\x00numpy array file error: Expected a data size of %d, found %d\x00numpy array too short\x00numpy array does not contain the 'magic' header\x00numpy array header length is invalid\x00numpy array error: Expected a data size of %d, found %d\x00CREATE TABLE x(vector, input hidden)\x00input argument is required\x00r\x00Could not open numpy file\x00vec_npy_each only supports float32 vectors\x00SELECT id, chunk_id, chunk_offset FROM \"%w\".\"%w_rowids\" WHERE rowid = ?\x00Internal sqlite-vec error: could not initialize 'rowids get chunk position' statement\x00SELECT rowid FROM \"%w\".\"%w_rowids\" WHERE id = ?\x00Could not find a row with rowid %lld\x00vectors\x00Could not fetch vector data for %lld, opening blob failed\x00Could not fetch vector data for %lld, reading from blob failed\x00Internal sqlite-vec error: unknown error, could not close vector blob, please file an issue\x00SELECT partition%02d FROM \"%w\".\"%w_chunks\" WHERE chunk_id = ?\x00SELECT value%02d FROM \"%w\".\"%w_auxiliary\" WHERE rowid = ?\x00data\x00SELECT data FROM \"%w\".\"%w_metadatatext%02d\" WHERE rowid = ?\x00SELECT max(rowid) FROM \"%w\".\"%w_chunks\" WHERE \x00 AND \x00 partition%02d = ? \x00SELECT max(rowid) FROM \"%w\".\"%w_chunks\"\x00Internal sqlite-vec error: could not initialize 'latest chunk' statement\x00Internal sqlite-vec error: Could not find latest chunk\x00Internal sqlite-vec error: unknown result code when closing out stmtLatestChunk. Please file an issue: https://github.com/asg017/sqlite-vec/issues/new\x00INSERT INTO \"%w\".\"%w_rowids\"(rowid)VALUES (?);\x00Internal sqlite-vec error: could not initialize 'insert rowids' statement\x00UNIQUE constraint failed on %s primary key\x00Error inserting rowid into rowids shadow table: %s\x00INSERT INTO \"%w\".\"%w_rowids\"(id)VALUES (?);\x00Internal sqlite-vec error: could not initialize 'insert rowids id' statement\x00Error inserting id into rowids shadow table: %s\x00 UPDATE \"%w\".\"%w_rowids\" SET chunk_id = ?, chunk_offset = ? WHERE rowid = ?\x00Internal sqlite-vec error: could not initialize 'update rowids position' statement\x00Internal sqlite-vec error: could not update rowids position for rowid=%lld, chunk_rowid=%lld, chunk_offset=%lld\x00INSERT INTO \"%w\".\"%w_chunks\"\x00(size, validity, rowids\x00, partition%02d\x00) VALUES (?, ?, ?\x00, ?\x00)\x00INSERT INTO \"%w\".\"%w_chunks\"(size, validity, rowids) VALUES (?, ?, ?);\x00INSERT INTO \"%w\".\"%w_vector_chunks%02d\"(rowid, vectors)VALUES (?, ?)\x00INSERT INTO \"%w\".\"%w_metadatachunks%02d\"(rowid, data)VALUES (?, ?)\x00vec0 constructor error: could not parse vector column '%s'\x00vec0 constructor error: Too many provided vector columns, maximum %d\x00vec0 constructor error: Dimension on vector column too large, provided %lld, maximum %lld\x00vec0 constructor error: More than %d partition key columns were provided\x00vec0 constructor error: More than one primary key definition was provided, vec0 only suports a single primary key column\x00vec0 constructor error: More than %d auxiliary columns were provided\x00vec0 constructor error: More than %d metadata columns were provided\x00vec0 constructor error: could not parse table option '%s'\x00chunk_size\x00vec0 constructor error: chunk_size must be a non-zero positive integer\x00vec0 constructor error: chunk_size must be divisible by 8\x00vec0 constructor error: chunk_size too large\x00vec0 constructor error: Unknown table option: %.*s\x00vec0 constructor error: Could not parse '%s'\x00vec0 constructor error: At least one vector column is required\x00CREATE TABLE x(\x00\"%.*w\" primary key, \x00rowid, \x00\"%.*w\", \x00 distance hidden, k hidden) \x00without rowid \x00vec0 constructor error: could not declare virtual table, '%s'\x00%s\x00%s_rowids\x00%s_chunks\x00%s_vector_chunks%02d\x00%s_metadatachunks%02d\x00CREATE TABLE \"%w\".\"%w_info\" (key text primary key, value any)\x00Could not create '_info' shadow table: %s\x00INSERT INTO \"%w\".\"%w_info\"(key, value) VALUES (?1, ?2), (?3, ?4), (?5, ?6), (?7, ?8) \x00Could not seed '_info' shadow table: %s\x00CREATE_VERSION\x00v0.1.6\x00CREATE_VERSION_MAJOR\x00CREATE_VERSION_MINOR\x00CREATE_VERSION_PATCH\x00CREATE TABLE \"%w\".\"%w_chunks\"(\x00chunk_id INTEGER PRIMARY KEY AUTOINCREMENT,size INTEGER NOT NULL,\x00sequence_id integer,\x00partition%02d,\x00validity BLOB NOT NULL, rowids BLOB NOT NULL);\x00CREATE TABLE \"%w\".\"%w_chunks\"(chunk_id INTEGER PRIMARY KEY AUTOINCREMENT,size INTEGER NOT NULL,validity BLOB NOT NULL,rowids BLOB NOT NULL);\x00Could not create '_chunks' shadow table: %s\x00CREATE TABLE \"%w\".\"%w_rowids\"(rowid INTEGER PRIMARY KEY AUTOINCREMENT,id TEXT UNIQUE NOT NULL,chunk_id INTEGER,chunk_offset INTEGER);\x00CREATE TABLE \"%w\".\"%w_rowids\"(rowid INTEGER PRIMARY KEY AUTOINCREMENT,id,chunk_id INTEGER,chunk_offset INTEGER);\x00Could not create '_rowids' shadow table: %s\x00CREATE TABLE \"%w\".\"%w_vector_chunks%02d\"(rowid PRIMARY KEY,vectors BLOB NOT NULL);\x00Could not create '_vector_chunks%02d' shadow table: %s\x00CREATE TABLE \"%w\".\"%w_metadatachunks%02d\"(rowid PRIMARY KEY, data BLOB NOT NULL);\x00Could not create '_metata_chunks%02d' shadow table: %s\x00CREATE TABLE \"%w\".\"%w_metadatatext%02d\"(rowid PRIMARY KEY, data TEXT);\x00Could not create '_metadatatext%02d' shadow table: %s\x00CREATE TABLE \"%w\".\"%w_auxiliary\"( rowid integer PRIMARY KEY \x00, value%02d\x00Could not create auxiliary shadow table: %s\x00DROP TABLE \"%w\".\"%w_chunks\"\x00could not drop chunks shadow table\x00DROP TABLE \"%w\".\"%w_info\"\x00could not drop info shadow table\x00DROP TABLE \"%w\".\"%w_rowids\"\x00DROP TABLE \"%w\".\"%w\"\x00DROP TABLE \"%w\".\"%w_auxiliary\"\x00DROP TABLE \"%w\".\"%w_metadatachunks%02d\"\x00DROP TABLE \"%w\".\"%w_metadatatext%02d\"\x00only 1 MATCH operator is allowed in a single vec0 query\x00only 1 'rowid in (..)' operator is allowed in a single vec0 query\x00A LIMIT or 'k = ?' constraint is required on vec0 knn queries.\x00Only LIMIT or 'k =?' can be provided, not both\x00Only a single 'ORDER BY distance' clause is allowed on vec0 KNN queries\x00Only a single 'ORDER BY distance' clause is allowed on vec0 KNN queries, not on other columns\x00Only ascending in ORDER BY distance clause is supported, DESC is not supported yet.\x00An illegal WHERE constraint was provided on a vec0 auxiliary column in a KNN query.\x00'xxx in (...)' is only available on INTEGER or TEXT metadata columns.\x00An illegal WHERE constraint was provided on a vec0 metadata column in a KNN query. Only one of EQUALS, GREATER_THAN, LESS_THAN_OR_EQUAL, LESS_THAN, GREATER_THAN_OR_EQUAL, NOT_EQUALS is allowed.\x00ONLY EQUALS (=) or NOT_EQUALS (!=) operators are allowed on boolean metadata columns.\x00select data from \"%w\".\"%w_metadatatext%02d\" where rowid = ?\x00select chunk_id, validity, rowids  from \"%w\".\"%w_chunks\"\x00 WHERE \x00 partition%02d > ? \x00 partition%02d <= ? \x00 partition%02d < ? \x00 partition%02d >= ? \x00 partition%02d != ? \x00rowids\x00chunks iter error\x00chunk validity size doesn't match - expected %lld, found %lld\x00rowids size doesn't match\x00chunk rowids size doesn't match - expected %lld, found %lld\x00could not open vectors blob for chunk %lld\x00vectors blob size doesn't match - expected %lld, found %lld\x00vectors blob read error for %lld\x00Could not open metadata blob\x00Could not filter metadata fields\x00Query vector on the \"%.*s\" column is invalid: %z\x00Query vector for the \"%.*s\" column is expected to be of type %s, but a %s vector was provided.\x00Dimension mismatch for query vector for the \"%.*s\" column. Expected %d dimensions but received %d.\x00k value in knn queries must be greater than or equal to 0.\x00k value in knn query too large, provided %lld and the limit is %lld\x00error processing rowid in (...) array\x00Error fetching next value in `x in (...)` integer expression\x00Error fetching next value in `x in (...)` text expression\x00Internal sqlite-vec error\x00Error preparing stmtChunk: %s\x00 SELECT rowid  FROM \"%w\".\"%w_rowids\" ORDER by chunk_id, chunk_offset \x00Error preparing rowid scan: %s\x00unknown idxStr '%s'\x00Internal sqlite-vec error: expected point query plan in vec0Rowid, found %d\x00Internal sqlite-vec error: fullscan_data is NULL.\x00Could not extract metadata value for column %.*s at rowid %lld\x00Internal sqlite-vec error: point_data is NULL.\x00Internal sqlite-vec error: knn_data is NULL.\x00The %s virtual table was declared with a TEXT primary key, but a non-TEXT value was provided in an INSERT.\x00Only integers are allows for primary key values on %s\x00validity\x00Internal sqlite-vec error: could not open validity blob on %s.%s.%lld\x00Internal sqlite-vec error: validity blob size mismatch on %s.%s.%lld, expected %lld but received %lld.\x00Internal sqlite-vec error: Could not allocate memory for validity bitmap\x00Internal sqlite-vec error: Could not read validity bitmap for %s.%s.%lld\x00Internal sqlite-vec error: Could not insert a new vector chunk\x00Internal sqlite-vec error: unknown error, blobChunksValidity could not be closed, please file an issue.\x00Internal sqlite-vec error: Could not open validity blob for newly created chunk %s.%s.%lld\x00Internal sqlite-vec error: validity blob size mismatch for newly created chunk %s.%s.%lld. Exepcted %lld, got %lld\x00Internal sqlite-vec error: could not read validity blob newly created chunk %s.%s.%lld\x00Internal sqlite-vec error: could not mark validity bit \x00Error opening vector blob at %s.%s.%lld\x00Internal sqlite-vec error: vector blob size mismatch on %s.%s.%lld. Expected %lld, actual %lld\x00Internal sqlite-vec error: could not write vector blob on %s.%s.%lld\x00Internal sqlite-vec error: could not close vector blob on %s.%s.%lld\x00Internal sqlite-vec error: could not open rowids blob on %s.%s.%lld\x00Internal sqlite-vec error: rowids blob size mismatch on %s.%s.%lld. Expected %lld, actual %lld\x00Internal sqlite-vec error: could not write rowids blob on %s.%s.%lld\x00Internal sqlite-vec error: could not close rowids blob on %s.%s.%lld\x00Expected 0 or 1 for BOOLEAN metadata column %.*s\x00Expected integer for INTEGER metadata column %.*s, received %s\x00Expected float for FLOAT metadata column %.*s, received %s\x00Expected text for TEXT metadata column %.*s, received %s\x00UPDATE \"%w\".\"%w_metadatatext%02d\" SET data = ?2 WHERE rowid = ?1\x00INSERT INTO \"%w\".\"%w_metadatatext%02d\" (rowid, data) VALUES (?1, ?2)\x00DELETE FROM \"%w\".\"%w_metadatatext%02d\" WHERE rowid = ?\x00Parition key type mismatch: The partition key column %.*s has type %s, but %s was provided.\x00Inserted vector for the \"%.*s\" column is invalid: %z\x00Inserted vector for the \"%.*s\" column is expected to be of type %s, but a %s vector was provided.\x00Dimension mismatch for inserted vector for the \"%.*s\" column. Expected %d dimensions but received %d.\x00A value was provided for the hidden \"distance\" column.\x00A value was provided for the hidden \"k\" column.\x00INSERT INTO \"%w\".\"%w_auxiliary\"(rowid \x00) VALUES (? \x00Auxiliary column type mismatch: The auxiliary column %.*s has type %s, but %s was provided.\x00Internal sqlite-vec error: unknown error, blobChunksValidity could not be closed, please file an issue\x00could not open validity blob for %s.%s.%lld\x00could not read validity blob for %s.%s.%lld at %d\x00vec0 deletion error: validity bit is not set for %s.%s.%lld at %d\x00could not write to validity blob for %s.%s.%lld at %d\x00vec0 deletion error: Error commiting validity blob transaction on %s.%s.%lld at %d\x00DELETE FROM \"%w\".\"%w_rowids\" WHERE rowid = ?\x00DELETE FROM \"%w\".\"%w_auxiliary\" WHERE rowid = ?\x00UPDATE \"%w\".\"%w_auxiliary\" SET value%02d = ? WHERE rowid = ?\x00Updated vector for the \"%.*s\" column is invalid: %z\x00Updated vector for the \"%.*s\" column is expected to be of type %s, but a %s vector was provided.\x00Dimension mismatch for new updated vector for the \"%.*s\" column. Expected %d dimensions but received %d.\x00Could not open vectors blob for %s.%s.%lld\x00Could not write to vectors blob for %s.%s.%lld\x00Could not commit blob transaction for vectors blob for %s.%s.%lld\x00UPDATEs on vec0 primary key values are not allowed.\x00UPDATE on partition key columns are not supported yet. \x00Unrecognized xUpdate operation provided for vec0.\x00chunks\x00auxiliary\x00info\x00metadatachunks00\x00metadatachunks01\x00metadatachunks02\x00metadatachunks03\x00metadatachunks04\x00metadatachunks05\x00metadatachunks06\x00metadatachunks07\x00metadatachunks08\x00metadatachunks09\x00metadatachunks10\x00metadatachunks11\x00metadatachunks12\x00metadatachunks13\x00metadatachunks14\x00metadatachunks15\x00metadatatext00\x00metadatatext01\x00metadatatext02\x00metadatatext03\x00metadatatext04\x00metadatatext05\x00metadatatext06\x00metadatatext07\x00metadatatext08\x00metadatatext09\x00metadatatext10\x00metadatatext11\x00metadatatext12\x00metadatatext13\x00metadatatext14\x00metadatatext15\x00vec0-static_blob_def\x00CREATE TABLE x(name, data, dimensions hidden, count hidden)\x00CREATE TABLE x(vector, distance hidden, k hidden)\x00ORDER BY distance required\x00more than 1 ORDER BY clause provided\x00ORDER BY must be on the distance column\x00vec_version\x00vec_debug\x00Version: v0.1.6\nDate: 2024-11-20T17:34:19Z+0100\nCommit: \nBuild flags:  \x00vec_distance_l2\x00vec_distance_l1\x00vec_distance_hamming\x00vec_distance_cosine\x00vec_length\x00vec_type\x00vec_to_json\x00vec_add\x00vec_sub\x00vec_slice\x00vec_normalize\x00vec_f32\x00vec_bit\x00vec_int8\x00vec_quantize_int8\x00vec_quantize_binary\x00vec0\x00vec_each\x00Error creating function %s: %s\x00Error creating module %s: %s\x00vec_npy_file\x00vec_npy_each\x00vec_static_blob_from_raw\x00vec_static_blobs\x00vec_static_blob_entries\x00"
