SDIR}/sqlite-vec.h ${WRKSRC}/sqlite-vec.h + +pre-build: + @cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${GMAKE} loadable \ + VERSION=${DISTVERSION} \ + CFLAGS="${CFLAGS} -I${LOCALBASE}/include -include sys/types.h" + @${CP} ${WRKSRC}/dist/vec0.so ${WRKSRC}/sqlite_vec/vec0.so + +# tests as of 0.1.9: 2 failed, 2 passed, 4 warnings, 74 errors in 4.30s: failures are due to sqlite3 missing enable_load_extension which needs to be fixed in the port + +.include diff --git a/databases/py-sqlite-vec/distinfo b/databases/py-sqlite-vec/distinfo new file mode 100644 index 000000000000..12083675ebf0 --- /dev/null +++ b/databases/py-sqlite-vec/distinfo @@ -0,0 +1,3 @@ +TIMESTAMP = 1777862627 +SHA256 (asg017-sqlite-vec-v0.1.9_GH0.tar.gz) = 9823e737d9934dcbe85dff75d3fca81018a9beee803d70fa77b16faab5d61dc9 +SIZE (asg017-sqlite-vec-v0.1.9_GH0.tar.gz) = 617543 diff --git a/databases/py-sqlite-vec/files/__init__.py b/databases/py-sqlite-vec/files/__init__.py new file mode 100644 index 000000000000..e57188c623bb --- /dev/null +++ b/databases/py-sqlite-vec/files/__init__.py @@ -0,0 +1,61 @@ +from os import path +import sqlite3 + +__version__ = "0.1.9" +__version_info__ = tuple(__version__.split(".")) + + +def loadable_path(): + """Returns the full path to the sqlite-vec loadable SQLite extension bundled with this package""" + lp = path.join(path.dirname(__file__), "vec0") + return path.normpath(lp) + + +def load(conn: sqlite3.Connection) -> None: + """Load the sqlite-vec SQLite extension into the given database connection.""" + conn.load_extension(loadable_path()) + + +from typing import List +from struct import pack +from sqlite3 import Connection + + +def serialize_float32(vector: List[float]) -> bytes: + """Serializes a list of floats into the raw bytes format sqlite-vec expects""" + return pack("%sf" % len(vector), *vector) + + +def serialize_int8(vector: List[int]) -> bytes: + """Serializes a list of integers into the raw bytes format sqlite-vec expects""" + return pack("%sb" % len(vector), *vector) + + +try: + import numpy.typing as npt + + def register_numpy(db: Connection, name: str, array: npt.NDArray): + ptr = array.__array_interface__["data"][0] + nvectors, dimensions = array.__array_interface__["shape"] + element_type = array.__array_interface__["typestr"] + + assert element_type == "=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "sqlite-vec" +version = "0.1.9" +description = "A vector search SQLite extension" +license = {text = "MIT OR Apache-2.0"} +requires-python = ">=3.8" + +[tool.setuptools.packages.find] +include = ["sqlite_vec*"] + +[tool.setuptools.package-data] +sqlite_vec = ["vec0.so", "vec0.dylib", "vec0.dll"] diff --git a/databases/py-sqlite-vec/files/sqlite-vec.h b/databases/py-sqlite-vec/files/sqlite-vec.h new file mode 100644 index 000000000000..40d5405f0163 --- /dev/null +++ b/databases/py-sqlite-vec/files/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 "v0.1.9" +// TODO rm +#define SQLITE_VEC_DATE "2025-01-01T00:00:00Z+0000" +#define SQLITE_VEC_SOURCE "v0.1.9" + + +#define SQLITE_VEC_VERSION_MAJOR 0 +#define SQLITE_VEC_VERSION_MINOR 1 +#define SQLITE_VEC_VERSION_PATCH 9 + +#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 */ diff --git a/databases/py-sqlite-vec/pkg-descr b/databases/py-sqlite-vec/pkg-descr new file mode 100644 index 000000000000..c8ab31cd1476 --- /dev/null +++ b/databases/py-sqlite-vec/pkg-descr @@ -0,0 +1,5 @@ +sqlite-vec is a vector search SQLite extension with Python bindings. +It provides fast nearest-neighbor vector search using SQLite virtual tables. + +The Python package bundles the compiled vec0.so SQLite loadable extension +and provides helper functions for loading it and serializing vectors.