@prisma-next/extension-pgvector 0.3.0-dev.6 → 0.3.0-dev.64

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 (70) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +18 -11
  3. package/dist/codec-types.d.mts +41 -0
  4. package/dist/codec-types.d.mts.map +1 -0
  5. package/dist/codec-types.mjs +1 -0
  6. package/dist/column-types.d.mts +33 -0
  7. package/dist/column-types.d.mts.map +1 -0
  8. package/dist/column-types.mjs +36 -0
  9. package/dist/column-types.mjs.map +1 -0
  10. package/dist/constants-BmZpaev5.mjs +13 -0
  11. package/dist/constants-BmZpaev5.mjs.map +1 -0
  12. package/dist/control.d.mts +7 -0
  13. package/dist/control.d.mts.map +1 -0
  14. package/dist/control.mjs +49 -0
  15. package/dist/control.mjs.map +1 -0
  16. package/dist/descriptor-meta-BADTQp0u.mjs +57 -0
  17. package/dist/descriptor-meta-BADTQp0u.mjs.map +1 -0
  18. package/dist/operation-types.d.mts +32 -0
  19. package/dist/operation-types.d.mts.map +1 -0
  20. package/dist/operation-types.mjs +1 -0
  21. package/dist/pack.d.mts +46 -0
  22. package/dist/pack.d.mts.map +1 -0
  23. package/dist/pack.mjs +9 -0
  24. package/dist/pack.mjs.map +1 -0
  25. package/dist/runtime.d.mts +7 -0
  26. package/dist/runtime.d.mts.map +1 -0
  27. package/dist/runtime.mjs +74 -0
  28. package/dist/runtime.mjs.map +1 -0
  29. package/package.json +37 -49
  30. package/src/core/constants.ts +9 -0
  31. package/src/core/descriptor-meta.ts +16 -17
  32. package/src/exports/codec-types.ts +1 -1
  33. package/src/exports/column-types.ts +34 -1
  34. package/src/exports/control.ts +2 -13
  35. package/src/exports/runtime.ts +37 -27
  36. package/src/types/codec-types.ts +23 -1
  37. package/dist/chunk-SHWLERB3.js +0 -60
  38. package/dist/chunk-SHWLERB3.js.map +0 -1
  39. package/dist/core/codecs.d.ts +0 -23
  40. package/dist/core/codecs.d.ts.map +0 -1
  41. package/dist/core/descriptor-meta.d.ts +0 -53
  42. package/dist/core/descriptor-meta.d.ts.map +0 -1
  43. package/dist/exports/codec-types.d.ts +0 -7
  44. package/dist/exports/codec-types.d.ts.map +0 -1
  45. package/dist/exports/codec-types.js +0 -1
  46. package/dist/exports/codec-types.js.map +0 -1
  47. package/dist/exports/column-types.d.ts +0 -11
  48. package/dist/exports/column-types.d.ts.map +0 -1
  49. package/dist/exports/column-types.js +0 -9
  50. package/dist/exports/column-types.js.map +0 -1
  51. package/dist/exports/control.d.ts +0 -9
  52. package/dist/exports/control.d.ts.map +0 -1
  53. package/dist/exports/control.js +0 -67
  54. package/dist/exports/control.js.map +0 -1
  55. package/dist/exports/operation-types.d.ts +0 -7
  56. package/dist/exports/operation-types.d.ts.map +0 -1
  57. package/dist/exports/operation-types.js +0 -1
  58. package/dist/exports/operation-types.js.map +0 -1
  59. package/dist/exports/pack.d.ts +0 -52
  60. package/dist/exports/pack.d.ts.map +0 -1
  61. package/dist/exports/pack.js +0 -11
  62. package/dist/exports/pack.js.map +0 -1
  63. package/dist/exports/runtime.d.ts +0 -8
  64. package/dist/exports/runtime.d.ts.map +0 -1
  65. package/dist/exports/runtime.js +0 -86
  66. package/dist/exports/runtime.js.map +0 -1
  67. package/dist/types/codec-types.d.ts +0 -10
  68. package/dist/types/codec-types.d.ts.map +0 -1
  69. package/dist/types/operation-types.d.ts +0 -31
  70. package/dist/types/operation-types.d.ts.map +0 -1
@@ -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":";;;cAwCM,2BAA2B"}
@@ -0,0 +1,74 @@
1
+ import { n as pgvectorPackMeta, t as pgvectorOperationSignature } from "./descriptor-meta-BADTQp0u.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
+ encode: (value) => {
17
+ if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
18
+ if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
19
+ return `[${value.join(",")}]`;
20
+ },
21
+ decode: (wire) => {
22
+ if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
23
+ if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
24
+ const content = wire.slice(1, -1).trim();
25
+ if (content === "") return [];
26
+ return content.split(",").map((v) => {
27
+ const num = Number.parseFloat(v.trim());
28
+ if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
29
+ return num;
30
+ });
31
+ },
32
+ meta: { db: { sql: { postgres: { nativeType: "vector" } } } }
33
+ });
34
+ const codecs = defineCodecs().add("vector", pgVectorCodec);
35
+ const codecDefinitions = codecs.codecDefinitions;
36
+ const dataTypes = codecs.dataTypes;
37
+
38
+ //#endregion
39
+ //#region src/exports/runtime.ts
40
+ const parameterizedCodecDescriptors = [{
41
+ codecId: VECTOR_CODEC_ID,
42
+ paramsSchema: type({ length: "number" }).narrow((params, ctx) => {
43
+ const { length } = params;
44
+ if (!Number.isInteger(length)) return ctx.mustBe("an integer");
45
+ if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
46
+ return true;
47
+ })
48
+ }];
49
+ function createPgvectorCodecRegistry() {
50
+ const registry = createCodecRegistry();
51
+ for (const def of Object.values(codecDefinitions)) registry.register(def.codec);
52
+ return registry;
53
+ }
54
+ const pgvectorRuntimeDescriptor = {
55
+ kind: "extension",
56
+ id: pgvectorPackMeta.id,
57
+ version: pgvectorPackMeta.version,
58
+ familyId: "sql",
59
+ targetId: "postgres",
60
+ codecs: createPgvectorCodecRegistry,
61
+ operationSignatures: () => [pgvectorOperationSignature],
62
+ parameterizedCodecs: () => parameterizedCodecDescriptors,
63
+ create() {
64
+ return {
65
+ familyId: "sql",
66
+ targetId: "postgres"
67
+ };
68
+ }
69
+ };
70
+ var runtime_default = pgvectorRuntimeDescriptor;
71
+
72
+ //#endregion
73
+ export { runtime_default as default };
74
+ //# 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<'pg/vector@1', string, number[]>({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\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 { pgvectorOperationSignature, pgvectorPackMeta } 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: () => [pgvectorOperationSignature],\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,MAAuC;CAC3D,QAAQ;CACR,aAAa,CAAC,SAAS;CACvB,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;;;;ACvChC,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,CAAC,2BAA2B;CACvD,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.6",
3
+ "version": "0.3.0-dev.64",
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.6",
9
- "@prisma-next/contract": "0.3.0-dev.6",
10
- "@prisma-next/contract-authoring": "0.3.0-dev.6",
11
- "@prisma-next/core-control-plane": "0.3.0-dev.6",
12
- "@prisma-next/family-sql": "0.3.0-dev.6",
13
- "@prisma-next/sql-operations": "0.3.0-dev.6",
14
- "@prisma-next/sql-relational-core": "0.3.0-dev.6",
15
- "@prisma-next/sql-runtime": "0.3.0-dev.6",
16
- "@prisma-next/sql-schema-ir": "0.3.0-dev.6"
8
+ "@prisma-next/cli": "0.3.0-dev.64",
9
+ "@prisma-next/core-control-plane": "0.3.0-dev.64",
10
+ "@prisma-next/contract": "0.3.0-dev.64",
11
+ "@prisma-next/sql-relational-core": "0.3.0-dev.64",
12
+ "@prisma-next/family-sql": "0.3.0-dev.64",
13
+ "@prisma-next/sql-runtime": "0.3.0-dev.64",
14
+ "@prisma-next/sql-schema-ir": "0.3.0-dev.64",
15
+ "@prisma-next/contract-authoring": "0.3.0-dev.64",
16
+ "@prisma-next/sql-operations": "0.3.0-dev.64"
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.6",
24
- "@prisma-next/operations": "0.3.0-dev.6",
25
- "@prisma-next/sql-contract-ts": "0.3.0-dev.6",
26
- "@prisma-next/sql-lane": "0.3.0-dev.6",
27
- "@prisma-next/sql-contract": "0.3.0-dev.6",
28
- "@prisma-next/test-utils": "0.0.1"
21
+ "vitest": "4.0.17",
22
+ "@prisma-next/adapter-postgres": "0.3.0-dev.64",
23
+ "@prisma-next/operations": "0.3.0-dev.64",
24
+ "@prisma-next/sql-contract": "0.3.0-dev.64",
25
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.64",
26
+ "@prisma-next/sql-lane": "0.3.0-dev.64",
27
+ "@prisma-next/test-utils": "0.0.1",
28
+ "@prisma-next/tsconfig": "0.0.0",
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
- "lint": "biome check . --config-path ../../../biome.json --error-on-warnings",
67
- "lint:fix": "biome check --write . --config-path ../../../biome.json",
68
- "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../biome.json",
69
- "clean": "node ../../../scripts/clean.mjs"
54
+ "lint": "biome check . --error-on-warnings",
55
+ "lint:fix": "biome check --write .",
56
+ "lint:fix:unsafe": "biome check --write --unsafe .",
57
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
70
58
  }
71
59
  }
@@ -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,4 +1,3 @@
1
- import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';
2
1
  import type { SqlOperationSignature } from '@prisma-next/sql-operations';
3
2
 
4
3
  const pgvectorTypeId = 'pg/vector@1' as const;
@@ -9,10 +8,6 @@ const cosineLowering = {
9
8
  template: '1 - ({{self}} <=> {{arg0}})',
10
9
  } as const;
11
10
 
12
- /**
13
- * Shared operation definition used by both pack metadata and runtime descriptor.
14
- * Frozen to prevent accidental mutation.
15
- */
16
11
  const cosineDistanceOperation = Object.freeze({
17
12
  method: 'cosineDistance',
18
13
  args: [{ kind: 'param' }],
@@ -20,6 +15,11 @@ const cosineDistanceOperation = Object.freeze({
20
15
  lowering: cosineLowering,
21
16
  } as const);
22
17
 
18
+ export const pgvectorOperationSignature: SqlOperationSignature = {
19
+ forTypeId: pgvectorTypeId,
20
+ ...cosineDistanceOperation,
21
+ };
22
+
23
23
  export const pgvectorPackMeta = {
24
24
  kind: 'extension',
25
25
  id: 'pgvector',
@@ -38,6 +38,16 @@ export const pgvectorPackMeta = {
38
38
  named: 'CodecTypes',
39
39
  alias: 'PgVectorTypes',
40
40
  },
41
+ typeImports: [
42
+ {
43
+ package: '@prisma-next/extension-pgvector/codec-types',
44
+ named: 'Vector',
45
+ alias: 'Vector',
46
+ },
47
+ ],
48
+ parameterized: {
49
+ [pgvectorTypeId]: 'Vector<{{length}}>',
50
+ },
41
51
  },
42
52
  operationTypes: {
43
53
  import: {
@@ -50,15 +60,4 @@ export const pgvectorPackMeta = {
50
60
  { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },
51
61
  ],
52
62
  },
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
- };
63
+ } 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(1536)', 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(${length})`,
44
+ typeParams: { length },
45
+ } as const;
46
+ }
@@ -4,12 +4,8 @@ import type {
4
4
  SqlControlExtensionDescriptor,
5
5
  } from '@prisma-next/family-sql/control';
6
6
  import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
7
- import { pgvectorPackMeta } from '../core/descriptor-meta';
7
+ import { pgvectorOperationSignature, pgvectorPackMeta } from '../core/descriptor-meta';
8
8
 
9
- /**
10
- * Pure verification hook: checks whether the 'vector' extension is installed
11
- * based on the in-memory schema IR (no DB I/O).
12
- */
13
9
  function verifyVectorExtensionInstalled(schema: SqlSchemaIR): readonly SchemaIssue[] {
14
10
  if (!schema.extensions.includes('vector')) {
15
11
  return [
@@ -23,10 +19,6 @@ function verifyVectorExtensionInstalled(schema: SqlSchemaIR): readonly SchemaIss
23
19
  return [];
24
20
  }
25
21
 
26
- /**
27
- * Database dependencies for the pgvector extension.
28
- * Declares the 'vector' Postgres extension as a required dependency.
29
- */
30
22
  const pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {
31
23
  init: [
32
24
  {
@@ -64,12 +56,9 @@ const pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {
64
56
  ],
65
57
  };
66
58
 
67
- /**
68
- * pgvector extension descriptor for CLI config.
69
- * Declares database dependencies for the 'vector' Postgres extension.
70
- */
71
59
  const pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {
72
60
  ...pgvectorPackMeta,
61
+ operationSignatures: () => [pgvectorOperationSignature],
73
62
  databaseDependencies: pgvectorDatabaseDependencies,
74
63
  create: () => ({
75
64
  familyId: 'sql' as const,
@@ -1,47 +1,57 @@
1
- import type { SqlOperationSignature } from '@prisma-next/sql-operations';
2
- import type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
1
  import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
4
2
  import type {
3
+ RuntimeParameterizedCodecDescriptor,
5
4
  SqlRuntimeExtensionDescriptor,
6
- SqlRuntimeExtensionInstance,
7
5
  } from '@prisma-next/sql-runtime';
6
+ import { type as arktype } from 'arktype';
8
7
  import { codecDefinitions } from '../core/codecs';
9
- import { pgvectorPackMeta, pgvectorRuntimeOperation } from '../core/descriptor-meta';
8
+ import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
9
+ import { pgvectorOperationSignature, pgvectorPackMeta } from '../core/descriptor-meta';
10
10
 
11
- /**
12
- * pgvector SQL runtime extension instance.
13
- * Provides codecs and operations for vector data type and similarity operations.
14
- */
15
- class PgVectorRuntimeExtensionInstance implements SqlRuntimeExtensionInstance<'postgres'> {
16
- readonly familyId = 'sql' as const;
17
- readonly targetId = 'postgres' as const;
18
-
19
- codecs(): CodecRegistry {
20
- const registry = createCodecRegistry();
21
- // Register all codecs from codecDefinitions
22
- for (const def of Object.values(codecDefinitions)) {
23
- registry.register(def.codec);
24
- }
25
- return registry;
11
+ const vectorParamsSchema = arktype({
12
+ length: 'number',
13
+ }).narrow((params, ctx) => {
14
+ const { length } = params;
15
+ if (!Number.isInteger(length)) {
16
+ return ctx.mustBe('an integer');
17
+ }
18
+ if (length < 1 || length > VECTOR_MAX_DIM) {
19
+ return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
26
20
  }
21
+ return true;
22
+ });
23
+
24
+ const parameterizedCodecDescriptors = [
25
+ {
26
+ codecId: VECTOR_CODEC_ID,
27
+ paramsSchema: vectorParamsSchema,
28
+ },
29
+ ] as const satisfies ReadonlyArray<
30
+ RuntimeParameterizedCodecDescriptor<{ readonly length: number }>
31
+ >;
27
32
 
28
- operations(): ReadonlyArray<SqlOperationSignature> {
29
- return [pgvectorRuntimeOperation];
33
+ function createPgvectorCodecRegistry() {
34
+ const registry = createCodecRegistry();
35
+ for (const def of Object.values(codecDefinitions)) {
36
+ registry.register(def.codec);
30
37
  }
38
+ return registry;
31
39
  }
32
40
 
33
- /**
34
- * pgvector SQL runtime extension descriptor.
35
- * Provides metadata and factory for creating runtime extension instances.
36
- */
37
41
  const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
38
42
  kind: 'extension' as const,
39
43
  id: pgvectorPackMeta.id,
40
44
  version: pgvectorPackMeta.version,
41
45
  familyId: 'sql' as const,
42
46
  targetId: 'postgres' as const,
43
- create(): SqlRuntimeExtensionInstance<'postgres'> {
44
- return new PgVectorRuntimeExtensionInstance();
47
+ codecs: createPgvectorCodecRegistry,
48
+ operationSignatures: () => [pgvectorOperationSignature],
49
+ parameterizedCodecs: () => parameterizedCodecDescriptors,
50
+ create() {
51
+ return {
52
+ familyId: 'sql' as const,
53
+ targetId: 'postgres' as const,
54
+ };
45
55
  },
46
56
  };
47
57
 
@@ -7,4 +7,26 @@
7
7
  * Runtime codec implementations are provided by the extension's codec registry.
8
8
  */
9
9
 
10
- export type { CodecTypes } from '../core/codecs';
10
+ import type { CodecTypes as CoreCodecTypes } from '../core/codecs';
11
+
12
+ /**
13
+ * Type-level branded vector.
14
+ *
15
+ * The runtime values are plain number arrays, but parameterized column typing can
16
+ * carry the dimension at the type level (e.g. Vector<1536>).
17
+ */
18
+ export type Vector<N extends number = number> = number[] & { readonly __vectorLength?: N };
19
+
20
+ /**
21
+ * Codec types for pgvector.
22
+ *
23
+ * - Scalar output remains `number[]` (runtime representation).
24
+ * - `parameterizedOutput` enables lane typing to compute `Vector<N>` from column `typeParams`.
25
+ */
26
+ export type CodecTypes = CoreCodecTypes & {
27
+ readonly 'pg/vector@1': CoreCodecTypes['pg/vector@1'] & {
28
+ readonly parameterizedOutput: <P extends { readonly length: number }>(
29
+ params: P,
30
+ ) => P extends { readonly length: infer N extends number } ? Vector<N> : Vector<number>;
31
+ };
32
+ };
@@ -1,60 +0,0 @@
1
- // src/core/descriptor-meta.ts
2
- var pgvectorTypeId = "pg/vector@1";
3
- var cosineLowering = {
4
- targetFamily: "sql",
5
- strategy: "function",
6
- template: "1 - ({{self}} <=> {{arg0}})"
7
- };
8
- var cosineDistanceOperation = Object.freeze({
9
- method: "cosineDistance",
10
- args: [{ kind: "param" }],
11
- returns: { kind: "builtin", type: "number" },
12
- lowering: cosineLowering
13
- });
14
- var pgvectorPackMeta = {
15
- kind: "extension",
16
- id: "pgvector",
17
- familyId: "sql",
18
- targetId: "postgres",
19
- version: "0.0.1",
20
- capabilities: {
21
- postgres: {
22
- "pgvector/cosine": true
23
- }
24
- },
25
- types: {
26
- codecTypes: {
27
- import: {
28
- package: "@prisma-next/extension-pgvector/codec-types",
29
- named: "CodecTypes",
30
- alias: "PgVectorTypes"
31
- }
32
- },
33
- operationTypes: {
34
- import: {
35
- package: "@prisma-next/extension-pgvector/operation-types",
36
- named: "OperationTypes",
37
- alias: "PgVectorOperationTypes"
38
- }
39
- },
40
- storage: [
41
- { typeId: pgvectorTypeId, familyId: "sql", targetId: "postgres", nativeType: "vector" }
42
- ]
43
- },
44
- operations: [
45
- {
46
- for: pgvectorTypeId,
47
- ...cosineDistanceOperation
48
- }
49
- ]
50
- };
51
- var pgvectorRuntimeOperation = {
52
- forTypeId: pgvectorTypeId,
53
- ...cosineDistanceOperation
54
- };
55
-
56
- export {
57
- pgvectorPackMeta,
58
- pgvectorRuntimeOperation
59
- };
60
- //# sourceMappingURL=chunk-SHWLERB3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":["import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';\nimport type { SqlOperationSignature } from '@prisma-next/sql-operations';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\nconst cosineLowering = {\n targetFamily: 'sql',\n strategy: 'function',\n template: '1 - ({{self}} <=> {{arg0}})',\n} as const;\n\n/**\n * Shared operation definition used by both pack metadata and runtime descriptor.\n * Frozen to prevent accidental mutation.\n */\nconst cosineDistanceOperation = Object.freeze({\n method: 'cosineDistance',\n args: [{ kind: 'param' }],\n returns: { kind: 'builtin', type: 'number' },\n lowering: cosineLowering,\n} as const);\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 },\n operationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'OperationTypes',\n alias: 'PgVectorOperationTypes',\n },\n },\n storage: [\n { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },\n ],\n },\n operations: [\n {\n for: pgvectorTypeId,\n ...cosineDistanceOperation,\n },\n ],\n} as const satisfies ExtensionPackRef<'sql', 'postgres'>;\n\nexport const pgvectorRuntimeOperation: SqlOperationSignature = {\n forTypeId: pgvectorTypeId,\n ...cosineDistanceOperation,\n};\n"],"mappings":";AAGA,IAAM,iBAAiB;AAEvB,IAAM,iBAAiB;AAAA,EACrB,cAAc;AAAA,EACd,UAAU;AAAA,EACV,UAAU;AACZ;AAMA,IAAM,0BAA0B,OAAO,OAAO;AAAA,EAC5C,QAAQ;AAAA,EACR,MAAM,CAAC,EAAE,MAAM,QAAQ,CAAC;AAAA,EACxB,SAAS,EAAE,MAAM,WAAW,MAAM,SAAS;AAAA,EAC3C,UAAU;AACZ,CAAU;AAEH,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAS;AAAA,EACT,cAAc;AAAA,IACZ,UAAU;AAAA,MACR,mBAAmB;AAAA,IACrB;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,YAAY;AAAA,MACV,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,gBAAgB;AAAA,MACd,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,EAAE,QAAQ,gBAAgB,UAAU,OAAO,UAAU,YAAY,YAAY,SAAS;AAAA,IACxF;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV;AAAA,MACE,KAAK;AAAA,MACL,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,IAAM,2BAAkD;AAAA,EAC7D,WAAW;AAAA,EACX,GAAG;AACL;","names":[]}
@@ -1,23 +0,0 @@
1
- /**
2
- * Vector codec implementation for pgvector extension.
3
- *
4
- * Provides encoding/decoding for the `vector` PostgreSQL type.
5
- * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
6
- */
7
- declare const codecs: import("@prisma-next/sql-relational-core/ast").CodecDefBuilder<{} & Record<"vector", import("@prisma-next/sql-relational-core/ast").Codec<"pg/vector@1", string, number[]>>>;
8
- export declare const codecDefinitions: {
9
- readonly vector: {
10
- readonly typeId: "pg/vector@1";
11
- readonly scalar: "vector";
12
- readonly codec: import("@prisma-next/sql-relational-core/ast").Codec<"pg/vector@1", string, number[]>;
13
- readonly input: number[];
14
- readonly output: number[];
15
- readonly jsType: number[];
16
- };
17
- };
18
- export declare const dataTypes: {
19
- readonly vector: "pg/vector@1";
20
- };
21
- export type CodecTypes = typeof codecs.CodecTypes;
22
- export {};
23
- //# sourceMappingURL=codecs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../src/core/codecs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqDH,QAAA,MAAM,MAAM,8KAA8C,CAAC;AAG3D,eAAO,MAAM,gBAAgB;;;;;;;;;CAA0B,CAAC;AACxD,eAAO,MAAM,SAAS;;CAAmB,CAAC;AAG1C,MAAM,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,UAAU,CAAC"}
@@ -1,53 +0,0 @@
1
- import type { SqlOperationSignature } from '@prisma-next/sql-operations';
2
- export declare const pgvectorPackMeta: {
3
- readonly kind: "extension";
4
- readonly id: "pgvector";
5
- readonly familyId: "sql";
6
- readonly targetId: "postgres";
7
- readonly version: "0.0.1";
8
- readonly capabilities: {
9
- readonly postgres: {
10
- readonly 'pgvector/cosine': true;
11
- };
12
- };
13
- readonly types: {
14
- readonly codecTypes: {
15
- readonly import: {
16
- readonly package: "@prisma-next/extension-pgvector/codec-types";
17
- readonly named: "CodecTypes";
18
- readonly alias: "PgVectorTypes";
19
- };
20
- };
21
- readonly operationTypes: {
22
- readonly import: {
23
- readonly package: "@prisma-next/extension-pgvector/operation-types";
24
- readonly named: "OperationTypes";
25
- readonly alias: "PgVectorOperationTypes";
26
- };
27
- };
28
- readonly storage: readonly [{
29
- readonly typeId: "pg/vector@1";
30
- readonly familyId: "sql";
31
- readonly targetId: "postgres";
32
- readonly nativeType: "vector";
33
- }];
34
- };
35
- readonly operations: readonly [{
36
- readonly method: "cosineDistance";
37
- readonly args: readonly [{
38
- readonly kind: "param";
39
- }];
40
- readonly returns: {
41
- readonly kind: "builtin";
42
- readonly type: "number";
43
- };
44
- readonly lowering: {
45
- readonly targetFamily: "sql";
46
- readonly strategy: "function";
47
- readonly template: "1 - ({{self}} <=> {{arg0}})";
48
- };
49
- readonly for: "pg/vector@1";
50
- }];
51
- };
52
- export declare const pgvectorRuntimeOperation: SqlOperationSignature;
53
- //# sourceMappingURL=descriptor-meta.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor-meta.d.ts","sourceRoot":"","sources":["../../src/core/descriptor-meta.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAqBzE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoC2B,CAAC;AAEzD,eAAO,MAAM,wBAAwB,EAAE,qBAGtC,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Codec type definitions for pgvector extension.
3
- *
4
- * Re-export from types module for public API.
5
- */
6
- export type { CodecTypes } from '../types/codec-types';
7
- //# sourceMappingURL=codec-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codec-types.d.ts","sourceRoot":"","sources":["../../src/exports/codec-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=codec-types.js.map