Expand description
sqlite-vec extension registration.
sqlite-vec provides a vec0 virtual table for approximate nearest-neighbor
search. The crate (sqlite-vec) ships a static C library that must be
registered with SQLite on each connection that wants vec0 tables.
§Per-connection registration
We call sqlite3_vec_init(db, NULL, NULL) directly on the connection’s
underlying raw *mut sqlite3 handle. This avoids sqlite3_auto_extension,
which internally calls sqlite3_initialize() and conflicts with libsql’s
own initialization (libsql asserts that sqlite3_config(SERIALIZED) returns
SQLITE_OK, which fails if sqlite was already initialized).
Because libsql::Connection does not expose the raw handle through its
public API, we obtain it by opening a lightweight raw FFI connection to the
same database file. A VecConnection wraps this raw handle and provides
helper methods for vec-specific operations.
§Safety
sqlite3_vec_init is declared by the sqlite-vec crate as fn() (zero
arguments) but the actual C function has the standard SQLite extension entry
point signature (sqlite3*, char**, const sqlite3_api_routines*) -> int.
We re-declare it with the correct signature and call it directly. Because
the library is compiled with SQLITE_CORE, the pApi parameter is ignored
(the extension calls SQLite functions directly rather than through the API
struct).
Structs§
- VecConnection
- A raw SQLite connection with sqlite-vec registered.
- VecStmt
- A prepared statement on a
VecConnection.
Functions§
- open_
vec_ connection - Register the sqlite-vec extension on a
libsql::Connectionby opening a raw FFI handle to the same database and registering there. - vec_
available - Check whether the sqlite-vec extension is available on a connection by
trying to call
vec_version(). Returnstrueif the extension is loaded.