diff --git a/pkgs/development/python-modules/sqlite-vec/default.nix b/pkgs/development/python-modules/sqlite-vec/default.nix new file mode 100644 index 000000000000..09fcf06304af --- /dev/null +++ b/pkgs/development/python-modules/sqlite-vec/default.nix @@ -0,0 +1,85 @@ +{ + lib, + buildPythonPackage, + fetchpatch, + + # build-system + setuptools, + setuptools-scm, + + # dependencies + sqlite-vec-c, # alias for pkgs.sqlite-vec + + # optional dependencies + numpy, + + # check inputs + openai, + pytestCheckHook, +}: + +buildPythonPackage rec { + inherit (sqlite-vec-c) pname version src; + pyproject = true; + + # The actual source root is bindings/python but the patches + # apply to the bindings directory. + # This is a known issue, see https://discourse.nixos.org/t/how-to-apply-patches-with-sourceroot/59727 + sourceRoot = "${src.name}/bindings"; + + patches = [ + (fetchpatch { + # https://github.com/asg017/sqlite-vec/pull/233 + name = "add-python-build-files.patch"; + url = "https://github.com/asg017/sqlite-vec/commit/c1917deb11aa79dcac32440679345b93e13b1b86.patch"; + hash = "sha256-4/9QLKuM/1AbD8AQHwJ14rhWVYVc+MILvK6+tWwWQlw="; + stripLen = 1; + }) + (fetchpatch { + # https://github.com/asg017/sqlite-vec/pull/233 + name = "add-python-test.patch"; + url = "https://github.com/asg017/sqlite-vec/commit/608972c9dcbfc7f4583e99fd8de6e5e16da11081.patch"; + hash = "sha256-8dfw7zs7z2FYh8DoAxurMYCDMOheg8Zl1XGcPw1A1BM="; + stripLen = 1; + }) + ]; + + # Change into the proper directory for building, move `extra_init.py` into its proper location, + # and supply the path to the library. + postPatch = '' + cd python + mv extra_init.py sqlite_vec/ + substituteInPlace sqlite_vec/__init__.py \ + --replace-fail "@libpath@" "${lib.getLib sqlite-vec-c}/lib/" + ''; + + build-system = [ + setuptools + setuptools-scm + ]; + + dependencies = [ + sqlite-vec-c + ]; + + optional-dependencies = { + numpy = [ + numpy + ]; + }; + + nativeCheckInputs = [ + numpy + openai + pytestCheckHook + sqlite-vec-c + ]; + + pythonImportsCheck = [ "sqlite_vec" ]; + + meta = sqlite-vec-c.meta // { + description = "Python bindings for sqlite-vec"; + maintainers = [ lib.maintainers.sarahec ]; + badPlatforms = [ "x86_64-darwin" ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 263a5fcd1ab3..c3b0a3daf68e 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -17009,6 +17009,10 @@ self: super: with self; { sqlite-utils = callPackage ../development/python-modules/sqlite-utils { }; + sqlite-vec = callPackage ../development/python-modules/sqlite-vec { + sqlite-vec-c = pkgs.sqlite-vec; + }; + sqlitedict = callPackage ../development/python-modules/sqlitedict { }; sqliteschema = callPackage ../development/python-modules/sqliteschema { };