@prisma-next/extension-pgvector 0.3.0-dev.12 → 0.3.0-dev.123

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +35 -18
  3. package/dist/codec-types-BcHC4dXB.d.mts +41 -0
  4. package/dist/codec-types-BcHC4dXB.d.mts.map +1 -0
  5. package/dist/codec-types.d.mts +2 -0
  6. package/dist/codec-types.mjs +1 -0
  7. package/dist/column-types.d.mts +33 -0
  8. package/dist/column-types.d.mts.map +1 -0
  9. package/dist/column-types.mjs +36 -0
  10. package/dist/column-types.mjs.map +1 -0
  11. package/dist/constants-BmZpaev5.mjs +13 -0
  12. package/dist/constants-BmZpaev5.mjs.map +1 -0
  13. package/dist/control.d.mts +7 -0
  14. package/dist/control.d.mts.map +1 -0
  15. package/dist/control.mjs +61 -0
  16. package/dist/control.mjs.map +1 -0
  17. package/dist/descriptor-meta-IXkObAr0.mjs +117 -0
  18. package/dist/descriptor-meta-IXkObAr0.mjs.map +1 -0
  19. package/dist/operation-types.d.mts +78 -0
  20. package/dist/operation-types.d.mts.map +1 -0
  21. package/dist/operation-types.mjs +1 -0
  22. package/dist/pack.d.mts +10 -0
  23. package/dist/pack.d.mts.map +1 -0
  24. package/dist/pack.mjs +9 -0
  25. package/dist/pack.mjs.map +1 -0
  26. package/dist/runtime.d.mts +7 -0
  27. package/dist/runtime.d.mts.map +1 -0
  28. package/dist/runtime.mjs +76 -0
  29. package/dist/runtime.mjs.map +1 -0
  30. package/package.json +34 -46
  31. package/src/core/codecs.ts +2 -1
  32. package/src/core/constants.ts +9 -0
  33. package/src/core/descriptor-meta.ts +68 -19
  34. package/src/exports/codec-types.ts +1 -1
  35. package/src/exports/column-types.ts +34 -1
  36. package/src/exports/control.ts +32 -26
  37. package/src/exports/operation-types.ts +1 -1
  38. package/src/exports/pack.ts +5 -1
  39. package/src/exports/runtime.ts +42 -27
  40. package/src/types/codec-types.ts +23 -1
  41. package/src/types/operation-types.ts +36 -0
  42. package/dist/chunk-SHWLERB3.js +0 -60
  43. package/dist/chunk-SHWLERB3.js.map +0 -1
  44. package/dist/core/codecs.d.ts +0 -23
  45. package/dist/core/codecs.d.ts.map +0 -1
  46. package/dist/core/descriptor-meta.d.ts +0 -53
  47. package/dist/core/descriptor-meta.d.ts.map +0 -1
  48. package/dist/exports/codec-types.d.ts +0 -7
  49. package/dist/exports/codec-types.d.ts.map +0 -1
  50. package/dist/exports/codec-types.js +0 -1
  51. package/dist/exports/codec-types.js.map +0 -1
  52. package/dist/exports/column-types.d.ts +0 -11
  53. package/dist/exports/column-types.d.ts.map +0 -1
  54. package/dist/exports/column-types.js +0 -9
  55. package/dist/exports/column-types.js.map +0 -1
  56. package/dist/exports/control.d.ts +0 -9
  57. package/dist/exports/control.d.ts.map +0 -1
  58. package/dist/exports/control.js +0 -67
  59. package/dist/exports/control.js.map +0 -1
  60. package/dist/exports/operation-types.d.ts +0 -7
  61. package/dist/exports/operation-types.d.ts.map +0 -1
  62. package/dist/exports/operation-types.js +0 -1
  63. package/dist/exports/operation-types.js.map +0 -1
  64. package/dist/exports/pack.d.ts +0 -52
  65. package/dist/exports/pack.d.ts.map +0 -1
  66. package/dist/exports/pack.js +0 -11
  67. package/dist/exports/pack.js.map +0 -1
  68. package/dist/exports/runtime.d.ts +0 -8
  69. package/dist/exports/runtime.d.ts.map +0 -1
  70. package/dist/exports/runtime.js +0 -86
  71. package/dist/exports/runtime.js.map +0 -1
  72. package/dist/types/codec-types.d.ts +0 -10
  73. package/dist/types/codec-types.d.ts.map +0 -1
  74. package/dist/types/operation-types.d.ts +0 -31
  75. package/dist/types/operation-types.d.ts.map +0 -1
@@ -0,0 +1,117 @@
1
+ //#region src/core/descriptor-meta.ts
2
+ const pgvectorTypeId = "pg/vector@1";
3
+ const cosineDistanceLowering = {
4
+ targetFamily: "sql",
5
+ strategy: "function",
6
+ template: "{{self}} <=> {{arg0}}"
7
+ };
8
+ const cosineSimilarityLowering = {
9
+ targetFamily: "sql",
10
+ strategy: "function",
11
+ template: "1 - ({{self}} <=> {{arg0}})"
12
+ };
13
+ const cosineDistanceOperation = Object.freeze({
14
+ method: "cosineDistance",
15
+ args: [{ kind: "param" }],
16
+ returns: {
17
+ kind: "builtin",
18
+ type: "number"
19
+ },
20
+ lowering: cosineDistanceLowering
21
+ });
22
+ const cosineSimilarityOperation = Object.freeze({
23
+ method: "cosineSimilarity",
24
+ args: [{ kind: "param" }],
25
+ returns: {
26
+ kind: "builtin",
27
+ type: "number"
28
+ },
29
+ lowering: cosineSimilarityLowering
30
+ });
31
+ const pgvectorOperationSignatures = [{
32
+ forTypeId: pgvectorTypeId,
33
+ ...cosineDistanceOperation
34
+ }, {
35
+ forTypeId: pgvectorTypeId,
36
+ ...cosineSimilarityOperation
37
+ }];
38
+ const pgvectorQueryOperations = [{
39
+ method: "cosineDistance",
40
+ args: [{
41
+ codecId: pgvectorTypeId,
42
+ nullable: false
43
+ }, {
44
+ codecId: pgvectorTypeId,
45
+ nullable: false
46
+ }],
47
+ returns: {
48
+ codecId: "pg/float8@1",
49
+ nullable: false
50
+ },
51
+ lowering: {
52
+ targetFamily: "sql",
53
+ strategy: "function",
54
+ template: "{{self}} <=> {{arg0}}"
55
+ }
56
+ }, {
57
+ method: "cosineSimilarity",
58
+ args: [{
59
+ codecId: pgvectorTypeId,
60
+ nullable: false
61
+ }, {
62
+ codecId: pgvectorTypeId,
63
+ nullable: false
64
+ }],
65
+ returns: {
66
+ codecId: "pg/float8@1",
67
+ nullable: false
68
+ },
69
+ lowering: {
70
+ targetFamily: "sql",
71
+ strategy: "function",
72
+ template: "1 - ({{self}} <=> {{arg0}})"
73
+ }
74
+ }];
75
+ const pgvectorPackMeta = {
76
+ kind: "extension",
77
+ id: "pgvector",
78
+ familyId: "sql",
79
+ targetId: "postgres",
80
+ version: "0.0.1",
81
+ capabilities: { postgres: { "pgvector/cosine": true } },
82
+ types: {
83
+ codecTypes: {
84
+ import: {
85
+ package: "@prisma-next/extension-pgvector/codec-types",
86
+ named: "CodecTypes",
87
+ alias: "PgVectorTypes"
88
+ },
89
+ typeImports: [{
90
+ package: "@prisma-next/extension-pgvector/codec-types",
91
+ named: "Vector",
92
+ alias: "Vector"
93
+ }],
94
+ parameterized: { [pgvectorTypeId]: "Vector<{{length}}>" }
95
+ },
96
+ operationTypes: { import: {
97
+ package: "@prisma-next/extension-pgvector/operation-types",
98
+ named: "OperationTypes",
99
+ alias: "PgVectorOperationTypes"
100
+ } },
101
+ queryOperationTypes: { import: {
102
+ package: "@prisma-next/extension-pgvector/operation-types",
103
+ named: "QueryOperationTypes",
104
+ alias: "PgVectorQueryOperationTypes"
105
+ } },
106
+ storage: [{
107
+ typeId: pgvectorTypeId,
108
+ familyId: "sql",
109
+ targetId: "postgres",
110
+ nativeType: "vector"
111
+ }]
112
+ }
113
+ };
114
+
115
+ //#endregion
116
+ export { pgvectorPackMeta as n, pgvectorQueryOperations as r, pgvectorOperationSignatures as t };
117
+ //# sourceMappingURL=descriptor-meta-IXkObAr0.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-IXkObAr0.mjs","names":["pgvectorOperationSignatures: readonly SqlOperationSignature[]","pgvectorQueryOperations: readonly QueryOperationDescriptor[]"],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":["import type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { QueryOperationDescriptor } from '@prisma-next/sql-relational-core/query-operations';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\nconst cosineDistanceLowering = {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n} as const;\n\nconst cosineSimilarityLowering = {\n targetFamily: 'sql',\n strategy: 'function',\n template: '1 - ({{self}} <=> {{arg0}})',\n} as const;\n\nconst cosineDistanceOperation = Object.freeze({\n method: 'cosineDistance',\n args: [{ kind: 'param' }],\n returns: { kind: 'builtin', type: 'number' },\n lowering: cosineDistanceLowering,\n} as const);\n\nconst cosineSimilarityOperation = Object.freeze({\n method: 'cosineSimilarity',\n args: [{ kind: 'param' }],\n returns: { kind: 'builtin', type: 'number' },\n lowering: cosineSimilarityLowering,\n} as const);\n\nexport const pgvectorOperationSignatures: readonly SqlOperationSignature[] = [\n { forTypeId: pgvectorTypeId, ...cosineDistanceOperation },\n { forTypeId: pgvectorTypeId, ...cosineSimilarityOperation },\n];\n\nexport const pgvectorQueryOperations: readonly QueryOperationDescriptor[] = [\n {\n method: 'cosineDistance',\n args: [\n { codecId: pgvectorTypeId, nullable: false },\n { codecId: pgvectorTypeId, nullable: false },\n ],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n },\n {\n method: 'cosineSimilarity',\n args: [\n { codecId: pgvectorTypeId, nullable: false },\n { codecId: pgvectorTypeId, nullable: false },\n ],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '1 - ({{self}} <=> {{arg0}})',\n },\n },\n];\n\nexport const pgvectorPackMeta = {\n kind: 'extension',\n id: 'pgvector',\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'pgvector/cosine': true,\n },\n },\n types: {\n codecTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'CodecTypes',\n alias: 'PgVectorTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'Vector',\n alias: 'Vector',\n },\n ],\n parameterized: {\n [pgvectorTypeId]: 'Vector<{{length}}>',\n },\n },\n operationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'OperationTypes',\n alias: 'PgVectorOperationTypes',\n },\n },\n queryOperationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PgVectorQueryOperationTypes',\n },\n },\n storage: [\n { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },\n ],\n },\n} as const;\n"],"mappings":";AAGA,MAAM,iBAAiB;AAEvB,MAAM,yBAAyB;CAC7B,cAAc;CACd,UAAU;CACV,UAAU;CACX;AAED,MAAM,2BAA2B;CAC/B,cAAc;CACd,UAAU;CACV,UAAU;CACX;AAED,MAAM,0BAA0B,OAAO,OAAO;CAC5C,QAAQ;CACR,MAAM,CAAC,EAAE,MAAM,SAAS,CAAC;CACzB,SAAS;EAAE,MAAM;EAAW,MAAM;EAAU;CAC5C,UAAU;CACX,CAAU;AAEX,MAAM,4BAA4B,OAAO,OAAO;CAC9C,QAAQ;CACR,MAAM,CAAC,EAAE,MAAM,SAAS,CAAC;CACzB,SAAS;EAAE,MAAM;EAAW,MAAM;EAAU;CAC5C,UAAU;CACX,CAAU;AAEX,MAAaA,8BAAgE,CAC3E;CAAE,WAAW;CAAgB,GAAG;CAAyB,EACzD;CAAE,WAAW;CAAgB,GAAG;CAA2B,CAC5D;AAED,MAAaC,0BAA+D,CAC1E;CACE,QAAQ;CACR,MAAM,CACJ;EAAE,SAAS;EAAgB,UAAU;EAAO,EAC5C;EAAE,SAAS;EAAgB,UAAU;EAAO,CAC7C;CACD,SAAS;EAAE,SAAS;EAAe,UAAU;EAAO;CACpD,UAAU;EACR,cAAc;EACd,UAAU;EACV,UAAU;EACX;CACF,EACD;CACE,QAAQ;CACR,MAAM,CACJ;EAAE,SAAS;EAAgB,UAAU;EAAO,EAC5C;EAAE,SAAS;EAAgB,UAAU;EAAO,CAC7C;CACD,SAAS;EAAE,SAAS;EAAe,UAAU;EAAO;CACpD,UAAU;EACR,cAAc;EACd,UAAU;EACV,UAAU;EACX;CACF,CACF;AAED,MAAa,mBAAmB;CAC9B,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,cAAc,EACZ,UAAU,EACR,mBAAmB,MACpB,EACF;CACD,OAAO;EACL,YAAY;GACV,QAAQ;IACN,SAAS;IACT,OAAO;IACP,OAAO;IACR;GACD,aAAa,CACX;IACE,SAAS;IACT,OAAO;IACP,OAAO;IACR,CACF;GACD,eAAe,GACZ,iBAAiB,sBACnB;GACF;EACD,gBAAgB,EACd,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;GACR,EACF;EACD,qBAAqB,EACnB,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;GACR,EACF;EACD,SAAS,CACP;GAAE,QAAQ;GAAgB,UAAU;GAAO,UAAU;GAAY,YAAY;GAAU,CACxF;EACF;CACF"}
@@ -0,0 +1,78 @@
1
+ import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
2
+
3
+ //#region src/types/operation-types.d.ts
4
+
5
+ /**
6
+ * Operation type definitions for pgvector extension.
7
+ *
8
+ * This file exports type-only definitions for operation method signatures.
9
+ * These types are imported by contract.d.ts files for compile-time type inference.
10
+ */
11
+ /**
12
+ * Operation types for pgvector extension.
13
+ * Maps typeId to operation methods.
14
+ */
15
+ type OperationTypes = {
16
+ readonly 'pg/vector@1': {
17
+ readonly cosineDistance: {
18
+ readonly args: readonly [{
19
+ readonly kind: 'param';
20
+ }];
21
+ readonly returns: {
22
+ readonly kind: 'builtin';
23
+ readonly type: 'number';
24
+ };
25
+ readonly lowering: {
26
+ readonly targetFamily: 'sql';
27
+ readonly strategy: 'function';
28
+ readonly template: string;
29
+ };
30
+ };
31
+ readonly cosineSimilarity: {
32
+ readonly args: readonly [{
33
+ readonly kind: 'param';
34
+ }];
35
+ readonly returns: {
36
+ readonly kind: 'builtin';
37
+ readonly type: 'number';
38
+ };
39
+ readonly lowering: {
40
+ readonly targetFamily: 'sql';
41
+ readonly strategy: 'function';
42
+ readonly template: string;
43
+ };
44
+ };
45
+ };
46
+ };
47
+ /** Flat operation signatures for the query builder. */
48
+ type QueryOperationTypes = SqlQueryOperationTypes<{
49
+ readonly cosineDistance: {
50
+ readonly args: readonly [{
51
+ readonly codecId: 'pg/vector@1';
52
+ readonly nullable: boolean;
53
+ }, {
54
+ readonly codecId: 'pg/vector@1';
55
+ readonly nullable: boolean;
56
+ }];
57
+ readonly returns: {
58
+ readonly codecId: 'pg/float8@1';
59
+ readonly nullable: false;
60
+ };
61
+ };
62
+ readonly cosineSimilarity: {
63
+ readonly args: readonly [{
64
+ readonly codecId: 'pg/vector@1';
65
+ readonly nullable: boolean;
66
+ }, {
67
+ readonly codecId: 'pg/vector@1';
68
+ readonly nullable: boolean;
69
+ }];
70
+ readonly returns: {
71
+ readonly codecId: 'pg/float8@1';
72
+ readonly nullable: false;
73
+ };
74
+ };
75
+ }>;
76
+ //#endregion
77
+ export { type OperationTypes, type QueryOperationTypes };
78
+ //# sourceMappingURL=operation-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;AAsCA;;;;;;;KAtCY,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCA,mBAAA,GAAsB"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,10 @@
1
+ import { t as CodecTypes } from "./codec-types-BcHC4dXB.mjs";
2
+ import { ExtensionPackRef } from "@prisma-next/contract/framework-components";
3
+
4
+ //#region src/exports/pack.d.ts
5
+ declare const _default: ExtensionPackRef<"sql", "postgres"> & {
6
+ readonly __codecTypes?: CodecTypes;
7
+ };
8
+ //#endregion
9
+ export { _default as default };
10
+ //# sourceMappingURL=pack.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.mts","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":[],"mappings":";;;;cAEuD,UAIxB;0BACL;AAL6B,CAAA"}
package/dist/pack.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import { n as pgvectorPackMeta } from "./descriptor-meta-IXkObAr0.mjs";
2
+
3
+ //#region src/exports/pack.ts
4
+ const pgvectorPack = pgvectorPackMeta;
5
+ var pack_default = pgvectorPack;
6
+
7
+ //#endregion
8
+ export { pack_default as default };
9
+ //# sourceMappingURL=pack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.mjs","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":["import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';\nimport { pgvectorPackMeta } from '../core/descriptor-meta';\nimport type { CodecTypes } from '../types/codec-types';\n\nconst pgvectorPack = pgvectorPackMeta;\n\nexport default pgvectorPack as ExtensionPackRef<'sql', 'postgres'> & {\n readonly __codecTypes?: CodecTypes;\n};\n"],"mappings":";;;AAIA,MAAM,eAAe;AAErB,mBAAe"}
@@ -0,0 +1,7 @@
1
+ import { SqlRuntimeExtensionDescriptor } from "@prisma-next/sql-runtime";
2
+
3
+ //#region src/exports/runtime.d.ts
4
+ declare const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
5
+ //#endregion
6
+ export { pgvectorRuntimeDescriptor as default };
7
+ //# sourceMappingURL=runtime.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;cA4CM,2BAA2B"}
@@ -0,0 +1,76 @@
1
+ import { n as pgvectorPackMeta, r as pgvectorQueryOperations, t as pgvectorOperationSignatures } from "./descriptor-meta-IXkObAr0.mjs";
2
+ import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-BmZpaev5.mjs";
3
+ import { codec, createCodecRegistry, defineCodecs } from "@prisma-next/sql-relational-core/ast";
4
+ import { type } from "arktype";
5
+
6
+ //#region src/core/codecs.ts
7
+ /**
8
+ * Vector codec implementation for pgvector extension.
9
+ *
10
+ * Provides encoding/decoding for the `vector` PostgreSQL type.
11
+ * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
12
+ */
13
+ const pgVectorCodec = codec({
14
+ typeId: "pg/vector@1",
15
+ targetTypes: ["vector"],
16
+ traits: ["equality"],
17
+ encode: (value) => {
18
+ if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
19
+ if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
20
+ return `[${value.join(",")}]`;
21
+ },
22
+ decode: (wire) => {
23
+ if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
24
+ if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
25
+ const content = wire.slice(1, -1).trim();
26
+ if (content === "") return [];
27
+ return content.split(",").map((v) => {
28
+ const num = Number.parseFloat(v.trim());
29
+ if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
30
+ return num;
31
+ });
32
+ },
33
+ meta: { db: { sql: { postgres: { nativeType: "vector" } } } }
34
+ });
35
+ const codecs = defineCodecs().add("vector", pgVectorCodec);
36
+ const codecDefinitions = codecs.codecDefinitions;
37
+ const dataTypes = codecs.dataTypes;
38
+
39
+ //#endregion
40
+ //#region src/exports/runtime.ts
41
+ const parameterizedCodecDescriptors = [{
42
+ codecId: VECTOR_CODEC_ID,
43
+ paramsSchema: type({ length: "number" }).narrow((params, ctx) => {
44
+ const { length } = params;
45
+ if (!Number.isInteger(length)) return ctx.mustBe("an integer");
46
+ if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
47
+ return true;
48
+ })
49
+ }];
50
+ function createPgvectorCodecRegistry() {
51
+ const registry = createCodecRegistry();
52
+ for (const def of Object.values(codecDefinitions)) registry.register(def.codec);
53
+ return registry;
54
+ }
55
+ const pgvectorRuntimeDescriptor = {
56
+ kind: "extension",
57
+ id: pgvectorPackMeta.id,
58
+ version: pgvectorPackMeta.version,
59
+ familyId: "sql",
60
+ targetId: "postgres",
61
+ codecs: createPgvectorCodecRegistry,
62
+ operationSignatures: () => pgvectorOperationSignatures,
63
+ queryOperations: () => pgvectorQueryOperations,
64
+ parameterizedCodecs: () => parameterizedCodecDescriptors,
65
+ create() {
66
+ return {
67
+ familyId: "sql",
68
+ targetId: "postgres"
69
+ };
70
+ }
71
+ };
72
+ var runtime_default = pgvectorRuntimeDescriptor;
73
+
74
+ //#endregion
75
+ export { runtime_default as default };
76
+ //# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.mjs","names":["arktype","pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>"],"sources":["../src/core/codecs.ts","../src/exports/runtime.ts"],"sourcesContent":["/**\n * Vector codec implementation for pgvector extension.\n *\n * Provides encoding/decoding for the `vector` PostgreSQL type.\n * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).\n */\n\nimport { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';\n\nconst pgVectorCodec = codec({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\n traits: ['equality'],\n encode: (value: number[]): string => {\n // Validate that value is an array of numbers\n if (!Array.isArray(value)) {\n throw new Error('Vector value must be an array of numbers');\n }\n if (!value.every((v) => typeof v === 'number')) {\n throw new Error('Vector value must contain only numbers');\n }\n // Format as PostgreSQL vector text format: [1,2,3]\n // PostgreSQL's pg library requires the vector format string\n return `[${value.join(',')}]`;\n },\n decode: (wire: string): number[] => {\n // Handle string format from PostgreSQL: [1,2,3]\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n // Parse PostgreSQL vector format: [1,2,3]\n if (!wire.startsWith('[') || !wire.endsWith(']')) {\n throw new Error(`Invalid vector format: expected \"[...]\", got \"${wire}\"`);\n }\n const content = wire.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n const values = content.split(',').map((v) => {\n const num = Number.parseFloat(v.trim());\n if (Number.isNaN(num)) {\n throw new Error(`Invalid vector value: \"${v}\" is not a number`);\n }\n return num;\n });\n return values;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'vector',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs().add('vector', pgVectorCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\n// Export types derived from codecs builder\nexport type CodecTypes = typeof codecs.CodecTypes;\n","import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeExtensionDescriptor,\n} from '@prisma-next/sql-runtime';\nimport { type as arktype } from 'arktype';\nimport { codecDefinitions } from '../core/codecs';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';\nimport {\n pgvectorOperationSignatures,\n pgvectorPackMeta,\n pgvectorQueryOperations,\n} from '../core/descriptor-meta';\n\nconst vectorParamsSchema = arktype({\n length: 'number',\n}).narrow((params, ctx) => {\n const { length } = params;\n if (!Number.isInteger(length)) {\n return ctx.mustBe('an integer');\n }\n if (length < 1 || length > VECTOR_MAX_DIM) {\n return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);\n }\n return true;\n});\n\nconst parameterizedCodecDescriptors = [\n {\n codecId: VECTOR_CODEC_ID,\n paramsSchema: vectorParamsSchema,\n },\n] as const satisfies ReadonlyArray<\n RuntimeParameterizedCodecDescriptor<{ readonly length: number }>\n>;\n\nfunction createPgvectorCodecRegistry() {\n const registry = createCodecRegistry();\n for (const def of Object.values(codecDefinitions)) {\n registry.register(def.codec);\n }\n return registry;\n}\n\nconst pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: pgvectorPackMeta.id,\n version: pgvectorPackMeta.version,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n codecs: createPgvectorCodecRegistry,\n operationSignatures: () => pgvectorOperationSignatures,\n queryOperations: () => pgvectorQueryOperations,\n parameterizedCodecs: () => parameterizedCodecDescriptors,\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n\nexport default pgvectorRuntimeDescriptor;\n"],"mappings":";;;;;;;;;;;;AASA,MAAM,gBAAgB,MAAM;CAC1B,QAAQ;CACR,aAAa,CAAC,SAAS;CACvB,QAAQ,CAAC,WAAW;CACpB,SAAS,UAA4B;AAEnC,MAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,OAAM,IAAI,MAAM,2CAA2C;AAE7D,MAAI,CAAC,MAAM,OAAO,MAAM,OAAO,MAAM,SAAS,CAC5C,OAAM,IAAI,MAAM,yCAAyC;AAI3D,SAAO,IAAI,MAAM,KAAK,IAAI,CAAC;;CAE7B,SAAS,SAA2B;AAElC,MAAI,OAAO,SAAS,SAClB,OAAM,IAAI,MAAM,qCAAqC;AAGvD,MAAI,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAC9C,OAAM,IAAI,MAAM,iDAAiD,KAAK,GAAG;EAE3E,MAAM,UAAU,KAAK,MAAM,GAAG,GAAG,CAAC,MAAM;AACxC,MAAI,YAAY,GACd,QAAO,EAAE;AASX,SAPe,QAAQ,MAAM,IAAI,CAAC,KAAK,MAAM;GAC3C,MAAM,MAAM,OAAO,WAAW,EAAE,MAAM,CAAC;AACvC,OAAI,OAAO,MAAM,IAAI,CACnB,OAAM,IAAI,MAAM,0BAA0B,EAAE,mBAAmB;AAEjE,UAAO;IACP;;CAGJ,MAAM,EACJ,IAAI,EACF,KAAK,EACH,UAAU,EACR,YAAY,UACb,EACF,EACF,EACF;CACF,CAAC;AAGF,MAAM,SAAS,cAAc,CAAC,IAAI,UAAU,cAAc;AAG1D,MAAa,mBAAmB,OAAO;AACvC,MAAa,YAAY,OAAO;;;;ACpChC,MAAM,gCAAgC,CACpC;CACE,SAAS;CACT,cAhBuBA,KAAQ,EACjC,QAAQ,UACT,CAAC,CAAC,QAAQ,QAAQ,QAAQ;EACzB,MAAM,EAAE,WAAW;AACnB,MAAI,CAAC,OAAO,UAAU,OAAO,CAC3B,QAAO,IAAI,OAAO,aAAa;AAEjC,MAAI,SAAS,KAAK,SAAS,eACzB,QAAO,IAAI,OAAO,oBAAoB,eAAe,GAAG;AAE1D,SAAO;GACP;CAMC,CACF;AAID,SAAS,8BAA8B;CACrC,MAAM,WAAW,qBAAqB;AACtC,MAAK,MAAM,OAAO,OAAO,OAAO,iBAAiB,CAC/C,UAAS,SAAS,IAAI,MAAM;AAE9B,QAAO;;AAGT,MAAMC,4BAAuE;CAC3E,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,UAAU;CACV,UAAU;CACV,QAAQ;CACR,2BAA2B;CAC3B,uBAAuB;CACvB,2BAA2B;CAC3B,SAAS;AACP,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ;AAED,sBAAe"}
package/package.json CHANGED
@@ -1,71 +1,59 @@
1
1
  {
2
2
  "name": "@prisma-next/extension-pgvector",
3
- "version": "0.3.0-dev.12",
3
+ "version": "0.3.0-dev.123",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
7
7
  "arktype": "^2.0.0",
8
- "@prisma-next/cli": "0.3.0-dev.12",
9
- "@prisma-next/contract": "0.3.0-dev.12",
10
- "@prisma-next/contract-authoring": "0.3.0-dev.12",
11
- "@prisma-next/core-control-plane": "0.3.0-dev.12",
12
- "@prisma-next/family-sql": "0.3.0-dev.12",
13
- "@prisma-next/sql-operations": "0.3.0-dev.12",
14
- "@prisma-next/sql-relational-core": "0.3.0-dev.12",
15
- "@prisma-next/sql-runtime": "0.3.0-dev.12",
16
- "@prisma-next/sql-schema-ir": "0.3.0-dev.12"
8
+ "@prisma-next/cli": "0.3.0-dev.123",
9
+ "@prisma-next/contract-authoring": "0.3.0-dev.123",
10
+ "@prisma-next/contract": "0.3.0-dev.123",
11
+ "@prisma-next/family-sql": "0.3.0-dev.123",
12
+ "@prisma-next/sql-operations": "0.3.0-dev.123",
13
+ "@prisma-next/core-control-plane": "0.3.0-dev.123",
14
+ "@prisma-next/sql-relational-core": "0.3.0-dev.123",
15
+ "@prisma-next/sql-runtime": "0.3.0-dev.123",
16
+ "@prisma-next/sql-schema-ir": "0.3.0-dev.123"
17
17
  },
18
18
  "devDependencies": {
19
- "@vitest/coverage-v8": "4.0.16",
20
- "tsup": "8.5.1",
19
+ "tsdown": "0.18.4",
21
20
  "typescript": "5.9.3",
22
- "vitest": "4.0.16",
23
- "@prisma-next/adapter-postgres": "0.3.0-dev.12",
24
- "@prisma-next/operations": "0.3.0-dev.12",
25
- "@prisma-next/sql-contract": "0.3.0-dev.12",
26
- "@prisma-next/sql-contract-ts": "0.3.0-dev.12",
27
- "@prisma-next/sql-lane": "0.3.0-dev.12",
28
- "@prisma-next/test-utils": "0.0.1"
21
+ "vitest": "4.0.17",
22
+ "@prisma-next/adapter-postgres": "0.3.0-dev.123",
23
+ "@prisma-next/operations": "0.3.0-dev.123",
24
+ "@prisma-next/sql-contract": "0.3.0-dev.123",
25
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.123",
26
+ "@prisma-next/sql-lane": "0.3.0-dev.123",
27
+ "@prisma-next/tsconfig": "0.0.0",
28
+ "@prisma-next/test-utils": "0.0.1",
29
+ "@prisma-next/tsdown": "0.0.0"
29
30
  },
30
31
  "files": [
31
32
  "dist",
32
33
  "src"
33
34
  ],
34
35
  "exports": {
35
- "./package.json": "./package.json",
36
- "./control": {
37
- "types": "./dist/exports/control.d.ts",
38
- "import": "./dist/exports/control.js"
39
- },
40
- "./runtime": {
41
- "types": "./dist/exports/runtime.d.ts",
42
- "import": "./dist/exports/runtime.js"
43
- },
44
- "./pack": {
45
- "types": "./dist/exports/pack.d.ts",
46
- "import": "./dist/exports/pack.js"
47
- },
48
- "./codec-types": {
49
- "types": "./dist/exports/codec-types.d.ts",
50
- "import": "./dist/exports/codec-types.js"
51
- },
52
- "./column-types": {
53
- "types": "./dist/exports/column-types.d.ts",
54
- "import": "./dist/exports/column-types.js"
55
- },
56
- "./operation-types": {
57
- "types": "./dist/exports/operation-types.d.ts",
58
- "import": "./dist/exports/operation-types.js"
59
- }
36
+ "./codec-types": "./dist/codec-types.mjs",
37
+ "./column-types": "./dist/column-types.mjs",
38
+ "./control": "./dist/control.mjs",
39
+ "./operation-types": "./dist/operation-types.mjs",
40
+ "./pack": "./dist/pack.mjs",
41
+ "./runtime": "./dist/runtime.mjs",
42
+ "./package.json": "./package.json"
43
+ },
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/prisma/prisma-next.git",
47
+ "directory": "packages/3-extensions/pgvector"
60
48
  },
61
49
  "scripts": {
62
- "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
50
+ "build": "tsdown",
63
51
  "test": "vitest run",
64
52
  "test:coverage": "vitest run --coverage",
65
53
  "typecheck": "tsc --project tsconfig.json --noEmit",
66
54
  "lint": "biome check . --error-on-warnings",
67
55
  "lint:fix": "biome check --write .",
68
56
  "lint:fix:unsafe": "biome check --write --unsafe .",
69
- "clean": "node ../../../scripts/clean.mjs"
57
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
70
58
  }
71
59
  }
@@ -7,9 +7,10 @@
7
7
 
8
8
  import { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';
9
9
 
10
- const pgVectorCodec = codec<'pg/vector@1', string, number[]>({
10
+ const pgVectorCodec = codec({
11
11
  typeId: 'pg/vector@1',
12
12
  targetTypes: ['vector'],
13
+ traits: ['equality'],
13
14
  encode: (value: number[]): string => {
14
15
  // Validate that value is an array of numbers
15
16
  if (!Array.isArray(value)) {
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Codec ID for pgvector's vector type.
3
+ */
4
+ export const VECTOR_CODEC_ID = 'pg/vector@1' as const;
5
+
6
+ /**
7
+ * Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).
8
+ */
9
+ export const VECTOR_MAX_DIM = 16000;
@@ -1,25 +1,68 @@
1
- import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';
2
1
  import type { SqlOperationSignature } from '@prisma-next/sql-operations';
2
+ import type { QueryOperationDescriptor } from '@prisma-next/sql-relational-core/query-operations';
3
3
 
4
4
  const pgvectorTypeId = 'pg/vector@1' as const;
5
5
 
6
- const cosineLowering = {
6
+ const cosineDistanceLowering = {
7
+ targetFamily: 'sql',
8
+ strategy: 'function',
9
+ template: '{{self}} <=> {{arg0}}',
10
+ } as const;
11
+
12
+ const cosineSimilarityLowering = {
7
13
  targetFamily: 'sql',
8
14
  strategy: 'function',
9
15
  template: '1 - ({{self}} <=> {{arg0}})',
10
16
  } as const;
11
17
 
12
- /**
13
- * Shared operation definition used by both pack metadata and runtime descriptor.
14
- * Frozen to prevent accidental mutation.
15
- */
16
18
  const cosineDistanceOperation = Object.freeze({
17
19
  method: 'cosineDistance',
18
20
  args: [{ kind: 'param' }],
19
21
  returns: { kind: 'builtin', type: 'number' },
20
- lowering: cosineLowering,
22
+ lowering: cosineDistanceLowering,
23
+ } as const);
24
+
25
+ const cosineSimilarityOperation = Object.freeze({
26
+ method: 'cosineSimilarity',
27
+ args: [{ kind: 'param' }],
28
+ returns: { kind: 'builtin', type: 'number' },
29
+ lowering: cosineSimilarityLowering,
21
30
  } as const);
22
31
 
32
+ export const pgvectorOperationSignatures: readonly SqlOperationSignature[] = [
33
+ { forTypeId: pgvectorTypeId, ...cosineDistanceOperation },
34
+ { forTypeId: pgvectorTypeId, ...cosineSimilarityOperation },
35
+ ];
36
+
37
+ export const pgvectorQueryOperations: readonly QueryOperationDescriptor[] = [
38
+ {
39
+ method: 'cosineDistance',
40
+ args: [
41
+ { codecId: pgvectorTypeId, nullable: false },
42
+ { codecId: pgvectorTypeId, nullable: false },
43
+ ],
44
+ returns: { codecId: 'pg/float8@1', nullable: false },
45
+ lowering: {
46
+ targetFamily: 'sql',
47
+ strategy: 'function',
48
+ template: '{{self}} <=> {{arg0}}',
49
+ },
50
+ },
51
+ {
52
+ method: 'cosineSimilarity',
53
+ args: [
54
+ { codecId: pgvectorTypeId, nullable: false },
55
+ { codecId: pgvectorTypeId, nullable: false },
56
+ ],
57
+ returns: { codecId: 'pg/float8@1', nullable: false },
58
+ lowering: {
59
+ targetFamily: 'sql',
60
+ strategy: 'function',
61
+ template: '1 - ({{self}} <=> {{arg0}})',
62
+ },
63
+ },
64
+ ];
65
+
23
66
  export const pgvectorPackMeta = {
24
67
  kind: 'extension',
25
68
  id: 'pgvector',
@@ -38,6 +81,16 @@ export const pgvectorPackMeta = {
38
81
  named: 'CodecTypes',
39
82
  alias: 'PgVectorTypes',
40
83
  },
84
+ typeImports: [
85
+ {
86
+ package: '@prisma-next/extension-pgvector/codec-types',
87
+ named: 'Vector',
88
+ alias: 'Vector',
89
+ },
90
+ ],
91
+ parameterized: {
92
+ [pgvectorTypeId]: 'Vector<{{length}}>',
93
+ },
41
94
  },
42
95
  operationTypes: {
43
96
  import: {
@@ -46,19 +99,15 @@ export const pgvectorPackMeta = {
46
99
  alias: 'PgVectorOperationTypes',
47
100
  },
48
101
  },
102
+ queryOperationTypes: {
103
+ import: {
104
+ package: '@prisma-next/extension-pgvector/operation-types',
105
+ named: 'QueryOperationTypes',
106
+ alias: 'PgVectorQueryOperationTypes',
107
+ },
108
+ },
49
109
  storage: [
50
110
  { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },
51
111
  ],
52
112
  },
53
- operations: [
54
- {
55
- for: pgvectorTypeId,
56
- ...cosineDistanceOperation,
57
- },
58
- ],
59
- } as const satisfies ExtensionPackRef<'sql', 'postgres'>;
60
-
61
- export const pgvectorRuntimeOperation: SqlOperationSignature = {
62
- forTypeId: pgvectorTypeId,
63
- ...cosineDistanceOperation,
64
- };
113
+ } as const;
@@ -4,4 +4,4 @@
4
4
  * Re-export from types module for public API.
5
5
  */
6
6
 
7
- export type { CodecTypes } from '../types/codec-types';
7
+ export type { CodecTypes, Vector } from '../types/codec-types';
@@ -6,8 +6,41 @@
6
6
  */
7
7
 
8
8
  import type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';
9
+ import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
9
10
 
11
+ /**
12
+ * Static vector column descriptor without dimension.
13
+ * Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
14
+ */
10
15
  export const vectorColumn = {
11
- codecId: 'pg/vector@1',
16
+ codecId: VECTOR_CODEC_ID,
12
17
  nativeType: 'vector',
13
18
  } as const satisfies ColumnTypeDescriptor;
19
+
20
+ /**
21
+ * Factory for creating dimensioned vector column descriptors.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * .column('embedding', { type: vector(1536), nullable: false })
26
+ * // Produces: nativeType: 'vector', typeParams: { length: 1536 }
27
+ * ```
28
+ *
29
+ * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
30
+ * @returns A column type descriptor with `typeParams.length` set
31
+ * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
32
+ */
33
+ export function vector<N extends number>(
34
+ length: N,
35
+ ): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {
36
+ if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {
37
+ throw new RangeError(
38
+ `pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`,
39
+ );
40
+ }
41
+ return {
42
+ codecId: VECTOR_CODEC_ID,
43
+ nativeType: 'vector',
44
+ typeParams: { length },
45
+ } as const;
46
+ }