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