Add sqlite-vec static extension for vector search in ProxySQL

This commit integrates sqlite-vec (https://github.com/asg017/sqlite-vec)
as a statically linked extension, enabling vector search capabilities
in all ProxySQL SQLite databases (admin, stats, config, monitor).

Changes:
1. Added sqlite-vec source files to deps/sqlite3/sqlite-vec-source/
   - sqlite-vec.c: main extension source
   - sqlite-vec.h: header for static linking
   - sqlite-vec.h.tmpl: template header

2. Modified deps/Makefile:
   - Added target sqlite3/sqlite3/vec.o that copies sources and compiles
     with flags -DSQLITE_CORE -DSQLITE_VEC_STATIC
   - Made sqlite3 target depend on vec.o

3. Modified lib/Makefile:
   - Added $(SQLITE3_LDIR)/vec.o to libproxysql.a prerequisites
   - Included vec.o in the static library archive

4. Modified lib/Admin_Bootstrap.cpp:
   - Added extern "C" declaration for sqlite3_vec_init
   - Enabled load extension support for all databases:
     - admindb, statsdb, configdb, monitordb, statsdb_disk
   - Registered sqlite3_vec_init as auto-extension at database open
     (replacing commented sqlite3_json_init)

5. Updated top-level Makefile:
   - Made GIT_VERSION fallback to git describe --always when tags missing

Result:
- Vector search functions (vec0 virtual tables, vector operations) are
  available in all ProxySQL SQLite databases without runtime dependencies
- No separate shared library required; fully embedded in proxysql binary
- Extension automatically loaded at database initialization
pull/5310/head
Rene Cannao 4 months ago
parent faa64a570d
commit fbd0d9732b

@ -9,7 +9,7 @@
### export GIT_VERSION=3.x.y-dev
### ```
GIT_VERSION ?= $(shell git describe --long --abbrev=7)
GIT_VERSION ?= $(shell git describe --long --abbrev=7 2>/dev/null || git describe --long --abbrev=7 --always)
ifndef GIT_VERSION
$(error GIT_VERSION is not set)
endif

6
deps/Makefile vendored

@ -246,7 +246,11 @@ sqlite3/sqlite3/sqlite3.o:
cd sqlite3/sqlite3 && ${CC} ${MYCFLAGS} -fPIC -c -o sqlite3.o sqlite3.c -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_JSON1 -DSQLITE_DLL=1
cd sqlite3/sqlite3 && ${CC} -shared -o libsqlite3.so sqlite3.o
sqlite3: sqlite3/sqlite3/sqlite3.o
sqlite3/sqlite3/vec.o: sqlite3/sqlite3/sqlite3.o
cd sqlite3/sqlite3 && cp ../sqlite-vec-source/sqlite-vec.c . && cp ../sqlite-vec-source/sqlite-vec.h .
cd sqlite3/sqlite3 && ${CC} ${MYCFLAGS} -fPIC -c -o vec.o sqlite-vec.c -DSQLITE_CORE -DSQLITE_VEC_STATIC -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_JSON1 -DSQLITE_DLL=1
sqlite3: sqlite3/sqlite3/sqlite3.o sqlite3/sqlite3/vec.o
libconfig/libconfig/out/libconfig++.a:

File diff suppressed because it is too large Load Diff

@ -0,0 +1,39 @@
#ifndef SQLITE_VEC_H
#define SQLITE_VEC_H
#ifndef SQLITE_CORE
#include "sqlite3ext.h"
#else
#include "sqlite3.h"
#endif
#ifdef SQLITE_VEC_STATIC
#define SQLITE_VEC_API
#else
#ifdef _WIN32
#define SQLITE_VEC_API __declspec(dllexport)
#else
#define SQLITE_VEC_API
#endif
#endif
#define SQLITE_VEC_VERSION "v0.1.0"
#define SQLITE_VEC_DATE "2025-12-22"
#define SQLITE_VEC_SOURCE "sqlite-vec.c"
#define SQLITE_VEC_VERSION_MAJOR 0
#define SQLITE_VEC_VERSION_MINOR 1
#define SQLITE_VEC_VERSION_PATCH 0
#ifdef __cplusplus
extern "C" {
#endif
SQLITE_VEC_API int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg,
const sqlite3_api_routines *pApi);
#ifdef __cplusplus
} /* end of the 'extern "C"' block */
#endif
#endif /* ifndef SQLITE_VEC_H */

@ -0,0 +1,41 @@
#ifndef SQLITE_VEC_H
#define SQLITE_VEC_H
#ifndef SQLITE_CORE
#include "sqlite3ext.h"
#else
#include "sqlite3.h"
#endif
#ifdef SQLITE_VEC_STATIC
#define SQLITE_VEC_API
#else
#ifdef _WIN32
#define SQLITE_VEC_API __declspec(dllexport)
#else
#define SQLITE_VEC_API
#endif
#endif
#define SQLITE_VEC_VERSION "v${VERSION}"
// TODO rm
#define SQLITE_VEC_DATE "${DATE}"
#define SQLITE_VEC_SOURCE "${SOURCE}"
#define SQLITE_VEC_VERSION_MAJOR ${VERSION_MAJOR}
#define SQLITE_VEC_VERSION_MINOR ${VERSION_MINOR}
#define SQLITE_VEC_VERSION_PATCH ${VERSION_PATCH}
#ifdef __cplusplus
extern "C" {
#endif
SQLITE_VEC_API int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg,
const sqlite3_api_routines *pApi);
#ifdef __cplusplus
} /* end of the 'extern "C"' block */
#endif
#endif /* ifndef SQLITE_VEC_H */

@ -67,6 +67,7 @@ using json = nlohmann::json;
#include <sys/utsname.h>
#include "platform.h"
extern "C" int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
#include "microhttpd.h"
#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || defined(__mips__)) && defined(__linux)
@ -511,10 +512,11 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) {
admindb=new SQLite3DB();
admindb->open((char *)"file:mem_admindb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
admindb->execute("PRAGMA cache_size = -50000");
//sqlite3_enable_load_extension(admindb->get_db(),1);
//sqlite3_auto_extension( (void(*)(void))sqlite3_json_init);
sqlite3_enable_load_extension(admindb->get_db(),1);
sqlite3_auto_extension( (void(*)(void))sqlite3_vec_init);
statsdb=new SQLite3DB();
statsdb->open((char *)"file:mem_statsdb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
sqlite3_enable_load_extension(statsdb->get_db(),1);
// check if file exists , see #617
bool admindb_file_exists=Proxy_file_exists(GloVars.admindb);
@ -527,15 +529,18 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) {
}
}
configdb->open((char *)GloVars.admindb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
sqlite3_enable_load_extension(configdb->get_db(),1);
// Fully synchronous is not required. See to #1055
// https://sqlite.org/pragma.html#pragma_synchronous
configdb->execute("PRAGMA synchronous=0");
monitordb = new SQLite3DB();
monitordb->open((char *)"file:mem_monitordb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
sqlite3_enable_load_extension(monitordb->get_db(),1);
statsdb_disk = new SQLite3DB();
statsdb_disk->open((char *)GloVars.statsdb_disk, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
sqlite3_enable_load_extension(statsdb_disk->get_db(),1);
// char *dbname = (char *)malloc(strlen(GloVars.statsdb_disk)+50);
// sprintf(dbname,"%s?mode=memory&cache=shared",GloVars.statsdb_disk);
// statsdb_disk->open(dbname, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_FULLMUTEX);

@ -89,8 +89,8 @@ HEADERS := ../include/*.h ../include/*.hpp
$(ODIR)/%.oo: %.cpp $(HEADERS)
$(CXX) -fPIC -c -o $@ $< $(MYCXXFLAGS) $(CXXFLAGS)
libproxysql.a: $(ODIR) $(OBJ) $(OBJ_CXX) $(SQLITE3_LDIR)/sqlite3.o
ar rcs $@ $(OBJ) $(OBJ_CXX) $(SQLITE3_LDIR)/sqlite3.o
libproxysql.a: $(ODIR) $(OBJ) $(OBJ_CXX) $(SQLITE3_LDIR)/sqlite3.o $(SQLITE3_LDIR)/vec.o
ar rcs $@ $(OBJ) $(OBJ_CXX) $(SQLITE3_LDIR)/sqlite3.o $(SQLITE3_LDIR)/vec.o
$(ODIR):
mkdir $(ODIR)

Loading…
Cancel
Save