Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 buildPgrxExtension,
3 cargo-pgrx_0_12_6,
4 postgresql,
5 fetchFromGitHub,
6 lib,
7 postgresqlTestExtension,
8}:
9
10buildPgrxExtension (finalAttrs: {
11 pname = "pgvectorscale";
12 version = "0.7.0";
13
14 src = fetchFromGitHub {
15 owner = "timescale";
16 repo = "pgvectorscale";
17 tag = finalAttrs.version;
18 hash = "sha256-dy481k2SvyYXwwcsyLZSl3XlhSk9C5+4LfEfciB1DK4=";
19 };
20
21 doCheck = false;
22
23 cargoHash = "sha256-CeRyDn9VhxfjWFJ1/Z/XvOUQOSnDoHHZAqgfYTeKU0o=";
24 cargoPatches = [
25 ./add-Cargo.lock.patch
26 ];
27
28 cargoPgrxFlags = [
29 "-p"
30 "vectorscale"
31 ];
32
33 inherit postgresql;
34 cargo-pgrx = cargo-pgrx_0_12_6;
35
36 passthru.tests.extension = postgresqlTestExtension {
37 inherit (finalAttrs) finalPackage;
38 withPackages = [ "pgvector" ];
39 sql = ''
40 CREATE EXTENSION vectorscale CASCADE;
41 CREATE TABLE document_embedding (
42 id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
43 embedding VECTOR(3)
44 );
45
46 INSERT INTO document_embedding (id, embedding) VALUES
47 (10, '[1,2,4]'),
48 (20, '[1,2,5]');
49
50 CREATE INDEX document_embedding_idx ON document_embedding
51 USING diskann (embedding vector_cosine_ops);
52 '';
53 asserts = [
54 {
55 query = "SELECT id FROM document_embedding WHERE embedding <-> '[1,2,3]' = 1";
56 expected = "10";
57 description = "Expected vector of row with ID=10 to have an euclidean distance from [1,2,3] of 1.";
58 }
59 {
60 query = "SELECT id FROM document_embedding WHERE embedding <-> '[1,2,3]' = 2";
61 expected = "20";
62 description = "Expected vector of row with ID=20 to have an euclidean distance from [1,2,3] of 2.";
63 }
64 ];
65 };
66
67 meta = {
68 homepage = "https://github.com/timescale/pgvectorscale";
69 teams = [ lib.teams.flyingcircus ];
70 description = "Complement to pgvector for high performance, cost efficient vector search on large workloads";
71 license = lib.licenses.postgresql;
72 platforms = postgresql.meta.platforms;
73 changelog = "https://github.com/timescale/pgvectorscale/releases/tag/${finalAttrs.version}";
74 };
75})