Skip to content

Commit

Permalink
Merge pull request #281192 from diogotcorreia/pgvecto.rs
Browse files Browse the repository at this point in the history
postgresqlPackages.pgvecto-rs: init at 0.2.1
  • Loading branch information
Atemu authored Mar 11, 2024
2 parents b9c6210 + 6b97ba6 commit ce8ddcd
Show file tree
Hide file tree
Showing 7 changed files with 3,844 additions and 2 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ in {
pgbouncer = handleTest ./pgbouncer.nix {};
pgjwt = handleTest ./pgjwt.nix {};
pgmanage = handleTest ./pgmanage.nix {};
pgvecto-rs = handleTest ./pgvecto-rs.nix {};
phosh = handleTest ./phosh.nix {};
photoprism = handleTest ./photoprism.nix {};
php = handleTest ./php {};
Expand Down
76 changes: 76 additions & 0 deletions nixos/tests/pgvecto-rs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# mostly copied from ./timescaledb.nix which was copied from ./postgresql.nix
# as it seemed unapproriate to test additional extensions for postgresql there.

{ system ? builtins.currentSystem
, config ? { }
, pkgs ? import ../.. { inherit system config; }
}:

with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let
postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs;
# Test cases from https://docs.pgvecto.rs/use-cases/hybrid-search.html
test-sql = pkgs.writeText "postgresql-test" ''
CREATE EXTENSION vectors;
CREATE TABLE items (
id bigserial PRIMARY KEY,
content text NOT NULL,
embedding vectors.vector(3) NOT NULL -- 3 dimensions
);
INSERT INTO items (content, embedding) VALUES
('a fat cat sat on a mat and ate a fat rat', '[1, 2, 3]'),
('a fat dog sat on a mat and ate a fat rat', '[4, 5, 6]'),
('a thin cat sat on a mat and ate a thin rat', '[7, 8, 9]'),
('a thin dog sat on a mat and ate a thin rat', '[10, 11, 12]');
'';
make-postgresql-test = postgresql-name: postgresql-package: makeTest {
name = postgresql-name;
meta = with pkgs.lib.maintainers; {
maintainers = [ diogotcorreia ];
};

nodes.machine = { ... }:
{
services.postgresql = {
enable = true;
package = postgresql-package;
extraPlugins = ps: with ps; [
pgvecto-rs
];
settings.shared_preload_libraries = "vectors";
};
};

testScript = ''
def check_count(statement, lines):
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
statement, lines
)
machine.start()
machine.wait_for_unit("postgresql")
with subtest("Postgresql with extension vectors is available just after unit start"):
machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'vectors' AND default_version = '${postgresql-package.pkgs.pgvecto-rs.version}';", 1))
machine.succeed("sudo -u postgres psql -f ${test-sql}")
machine.succeed(check_count("SELECT content, embedding FROM items WHERE to_tsvector('english', content) @@ 'cat & rat'::tsquery;", 2))
machine.shutdown()
'';

};
applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "12") postgresql-versions;
in
mapAttrs'
(name: package: {
inherit name;
value = make-postgresql-test name package;
})
applicablePostgresqlVersions
4 changes: 2 additions & 2 deletions pkgs/development/compilers/rust/make-rust-platform.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, buildPackages, callPackage, cargo-auditable, stdenv, runCommand }@prev:
{ lib, buildPackages, callPackage, callPackages, cargo-auditable, stdenv, runCommand }@prev:

{ rustc
, cargo
Expand Down Expand Up @@ -34,7 +34,7 @@ rec {
};

# Hooks
inherit (callPackage ../../../build-support/rust/hooks {
inherit (callPackages ../../../build-support/rust/hooks {
inherit stdenv cargo rustc;
}) cargoBuildHook cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook maturinBuildHook bindgenHook;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/crates/c/build.rs b/crates/c/build.rs
index 8d822e5..8b7e371 100644
--- a/crates/c/build.rs
+++ b/crates/c/build.rs
@@ -1,9 +1,13 @@
fn main() {
println!("cargo:rerun-if-changed=src/c.h");
println!("cargo:rerun-if-changed=src/c.c");
+ println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
cc::Build::new()
- .compiler("clang-16")
+ .compiler("@clang@")
.file("./src/c.c")
+ // read env var set by rustPlatform.bindgenHook
+ .try_flags_from_environment("BINDGEN_EXTRA_CLANG_ARGS")
+ .expect("the BINDGEN_EXTRA_CLANG_ARGS environment variable must be specified and UTF-8")
.opt_level(3)
.debug(true)
.compile("pgvectorsc");
Loading

0 comments on commit ce8ddcd

Please sign in to comment.