@prisma-next/extension-pgvector 0.5.0-dev.60 → 0.5.0-dev.62

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.
@@ -0,0 +1,64 @@
1
+ import { AnyCodecDescriptor, CodecCallContext, CodecDescriptorImpl, CodecImpl, CodecInstanceContext } from "@prisma-next/framework-components/codec";
2
+ import { JsonValue } from "@prisma-next/contract/types";
3
+ import { ExtractCodecTypes } from "@prisma-next/sql-relational-core/ast";
4
+ import { StandardSchemaV1 } from "@standard-schema/spec";
5
+
6
+ //#region src/core/constants.d.ts
7
+ /**
8
+ * Codec ID for pgvector's vector type.
9
+ */
10
+ declare const VECTOR_CODEC_ID: "pg/vector@1";
11
+ //#endregion
12
+ //#region src/core/codecs.d.ts
13
+
14
+ type VectorParams = {
15
+ readonly length: number;
16
+ };
17
+ declare class PgVectorCodec extends CodecImpl<typeof VECTOR_CODEC_ID, readonly ['equality'], string, number[]> {
18
+ readonly length: number | undefined;
19
+ constructor(descriptor: AnyCodecDescriptor, length: number | undefined);
20
+ assertVector(value: unknown): asserts value is number[];
21
+ encode(value: number[], _ctx: CodecCallContext): Promise<string>;
22
+ decode(wire: string, _ctx: CodecCallContext): Promise<number[]>;
23
+ encodeJson(value: number[]): JsonValue;
24
+ decodeJson(json: JsonValue): number[];
25
+ }
26
+ declare class PgVectorDescriptor extends CodecDescriptorImpl<VectorParams> {
27
+ readonly codecId: "pg/vector@1";
28
+ readonly traits: readonly ["equality"];
29
+ readonly targetTypes: readonly ["vector"];
30
+ readonly meta: {
31
+ readonly db: {
32
+ readonly sql: {
33
+ readonly postgres: {
34
+ readonly nativeType: "vector";
35
+ };
36
+ };
37
+ };
38
+ };
39
+ readonly paramsSchema: StandardSchemaV1<VectorParams>;
40
+ renderOutputType(params: VectorParams): string;
41
+ /**
42
+ * The runtime calls `factory(undefined)(ctx)` to materialize a representative codec for parameterized descriptors that ship a no-params column variant (here, `vectorColumn` vs `vector(N)`). The runtime cast widens `params` to `unknown`, so guarding with an optional read keeps the typed call site (`factory({ length })`) strict while still producing a length-agnostic codec for representative use. Encode/decode for an undimensioned column run through this representative; the wire format `[v1,v2,...]` is dimension-independent.
43
+ */
44
+ factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec;
45
+ }
46
+ declare const codecDescriptorMap: {
47
+ readonly vector: PgVectorDescriptor;
48
+ };
49
+ type CodecTypes$1 = ExtractCodecTypes<typeof codecDescriptorMap>;
50
+ //#endregion
51
+ //#region src/types/codec-types.d.ts
52
+ /**
53
+ * Type-level branded vector.
54
+ *
55
+ * The runtime values are plain number arrays, but parameterized column typing can
56
+ * carry the dimension at the type level (e.g. Vector<1536>).
57
+ */
58
+ type Vector<N extends number = number> = number[] & {
59
+ readonly __vectorLength?: N;
60
+ };
61
+ type CodecTypes = CodecTypes$1;
62
+ //#endregion
63
+ export { Vector as n, CodecTypes as t };
64
+ //# sourceMappingURL=codec-types-BFZqW_TL.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec-types-BFZqW_TL.d.mts","names":[],"sources":["../src/core/constants.ts","../src/core/codecs.ts","../src/types/codec-types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cAGa;;;;KCyBR,YAAA,GA+C8B;EAAmB,SAAA,MAAA,EAAA,MAAA;CAsBvB;AAKZ,cAzDN,aAAA,SAAsB,SAyDhB,CAAA,OAxDV,eAwDU,EAAA,SAAA,CAAA,UAAA,CAAA,EAAA,MAAA,EAAA,MAAA,EAAA,CAAA,CAAA;EAzDgB,SAAA,MAAA,EAAA,MAAA,GAAA,SAAA;EAAS,WAAA,CAAA,UAAA,EAQlB,kBARkB,EAAA,MAAA,EAAA,MAAA,GAAA,SAAA;EA+D/B,YAAA,CAAA,KAAA,EAAA,OAAmB,CAAA,EAAA,QAAA,KAAA,IAAA,MAAA,EAAA;EAA4B,MAAA,CAAA,KAAA,EAAA,MAAA,EAAA,EAAA,IAAA,EAtCtB,gBAsCsB,CAAA,EAtCH,OAsCG,CAAA,MAAA,CAAA;EAKT,MAAA,CAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAtChB,gBAsCgB,CAAA,EAtCG,OAsCH,CAAA,MAAA,EAAA,CAAA;EAAjB,UAAA,CAAA,KAAA,EAAA,MAAA,EAAA,CAAA,EAhBH,SAgBG;EACE,UAAA,CAAA,IAAA,EAZjB,SAYiB,CAAA,EAAA,MAAA,EAAA;;AAMY,cAZnC,kBAAA,SAA2B,mBAYQ,CAZY,YAYZ,CAAA,CAAA;EAAyB,SAAA,OAAA,EAAA,aAAA;EAZjC,SAAA,MAAA,EAAA,SAAA,CAAA,UAAA,CAAA;EAAmB,SAAA,WAAA,EAAA,SAAA,CAAA,QAAA,CAAA;EA8BrD,SAAA,IAAA,EAAA;IAIM,SAAA,EAAU,EAAA;;;;QC7HJ,CAAA;MAEN,CAAA;;;yBD8FsB,iBAAiB;2BACf;;;;kBAMT,qBAAqB,yBAAyB;;cAkBnE;mBAEI;;KAEE,YAAA,GAAa,yBAAyB;;;;AApHY;AAmB9D;;;;AAyByD,KCrD7C,MDqD6C,CAAA,UAAA,MAAA,GAAA,MAAA,CAAA,GAAA,MAAA,EAAA,GAAA;EAKtB,SAAA,cAAA,CAAA,EC1DoD,CD0DpD;CAAmB;AAsBvB,KC9EnB,UAAA,GAAa,YD8EM"}
@@ -1,2 +1,2 @@
1
- import { n as Vector, t as CodecTypes } from "./codec-types-BifaP625.mjs";
1
+ import { n as Vector, t as CodecTypes } from "./codec-types-BFZqW_TL.mjs";
2
2
  export { type CodecTypes, type Vector };
@@ -1,10 +1,9 @@
1
- import { ColumnTypeDescriptor } from "@prisma-next/contract-authoring";
1
+ import { ColumnTypeDescriptor } from "@prisma-next/framework-components/codec";
2
2
 
3
3
  //#region src/exports/column-types.d.ts
4
4
 
5
5
  /**
6
- * Static vector column descriptor without dimension.
7
- * Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
6
+ * Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
8
7
  */
9
8
  declare const vectorColumn: {
10
9
  readonly codecId: "pg/vector@1";
@@ -18,7 +17,6 @@ declare const vectorColumn: {
18
17
  * .column('embedding', { type: vector(1536), nullable: false })
19
18
  * // Produces: nativeType: 'vector', typeParams: { length: 1536 }
20
19
  * ```
21
- *
22
20
  * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
23
21
  * @returns A column type descriptor with `typeParams.length` set
24
22
  * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
@@ -1 +1 @@
1
- {"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAca;;;;;;;;;;;;;;;;;iBAkBG,iCACN,IACP;;qBAAiE"}
1
+ {"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":[],"mappings":";;;;;;;cAYa;;;;;;;;;;;;;;;;iBAiBG,iCACN,IACP;;qBAAiE"}
@@ -2,8 +2,7 @@ import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-Co5golCK.
2
2
 
3
3
  //#region src/exports/column-types.ts
4
4
  /**
5
- * Static vector column descriptor without dimension.
6
- * Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
5
+ * Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
7
6
  */
8
7
  const vectorColumn = {
9
8
  codecId: VECTOR_CODEC_ID,
@@ -17,7 +16,6 @@ const vectorColumn = {
17
16
  * .column('embedding', { type: vector(1536), nullable: false })
18
17
  * // Produces: nativeType: 'vector', typeParams: { length: 1536 }
19
18
  * ```
20
- *
21
19
  * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
22
20
  * @returns A column type descriptor with `typeParams.length` set
23
21
  * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
@@ -1 +1 @@
1
- {"version":3,"file":"column-types.mjs","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for pgvector extension.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring.\n * They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';\n\n/**\n * Static vector column descriptor without dimension.\n * Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.\n */\nexport const vectorColumn = {\n codecId: VECTOR_CODEC_ID,\n nativeType: 'vector',\n} as const satisfies ColumnTypeDescriptor;\n\n/**\n * Factory for creating dimensioned vector column descriptors.\n *\n * @example\n * ```typescript\n * .column('embedding', { type: vector(1536), nullable: false })\n * // Produces: nativeType: 'vector', typeParams: { length: 1536 }\n * ```\n *\n * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)\n * @returns A column type descriptor with `typeParams.length` set\n * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]\n */\nexport function vector<N extends number>(\n length: N,\n): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {\n if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {\n throw new RangeError(\n `pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`,\n );\n }\n return {\n codecId: VECTOR_CODEC_ID,\n nativeType: 'vector',\n typeParams: { length },\n } as const;\n}\n"],"mappings":";;;;;;;AAcA,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;CACb;;;;;;;;;;;;;;AAeD,SAAgB,OACd,QACwE;AACxE,KAAI,CAAC,OAAO,UAAU,OAAO,IAAI,SAAS,KAAK,SAAS,eACtD,OAAM,IAAI,WACR,iDAAiD,eAAe,SAAS,SAC1E;AAEH,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB"}
1
+ {"version":3,"file":"column-types.mjs","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for pgvector extension.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring. They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';\n\n/**\n * Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.\n */\nexport const vectorColumn = {\n codecId: VECTOR_CODEC_ID,\n nativeType: 'vector',\n} as const satisfies ColumnTypeDescriptor;\n\n/**\n * Factory for creating dimensioned vector column descriptors.\n *\n * @example\n * ```typescript\n * .column('embedding', { type: vector(1536), nullable: false })\n * // Produces: nativeType: 'vector', typeParams: { length: 1536 }\n * ```\n * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)\n * @returns A column type descriptor with `typeParams.length` set\n * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]\n */\nexport function vector<N extends number>(\n length: N,\n): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {\n if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {\n throw new RangeError(\n `pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`,\n );\n }\n return {\n codecId: VECTOR_CODEC_ID,\n nativeType: 'vector',\n typeParams: { length },\n } as const;\n}\n"],"mappings":";;;;;;AAYA,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;CACb;;;;;;;;;;;;;AAcD,SAAgB,OACd,QACwE;AACxE,KAAI,CAAC,OAAO,UAAU,OAAO,IAAI,SAAS,KAAK,SAAS,eACtD,OAAM,IAAI,WACR,iDAAiD,eAAe,SAAS,SAC1E;AAEH,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB"}
package/dist/control.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-DTopW_37.mjs";
1
+ import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-BaV3A8tJ.mjs";
2
2
 
3
3
  //#region src/exports/control.ts
4
4
  const PGVECTOR_CODEC_ID = "pg/vector@1";
@@ -0,0 +1,189 @@
1
+ import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-Co5golCK.mjs";
2
+ import { buildOperation, refsOf, toExpr } from "@prisma-next/sql-relational-core/expression";
3
+ import { buildCodecDescriptorRegistry } from "@prisma-next/sql-relational-core/codec-descriptor-registry";
4
+ import { CodecDescriptorImpl, CodecImpl } from "@prisma-next/framework-components/codec";
5
+ import { type } from "arktype";
6
+
7
+ //#region src/core/authoring.ts
8
+ const pgvectorAuthoringTypes = { pgvector: { Vector: {
9
+ kind: "typeConstructor",
10
+ args: [{
11
+ kind: "number",
12
+ name: "length",
13
+ integer: true,
14
+ minimum: 1,
15
+ maximum: VECTOR_MAX_DIM
16
+ }],
17
+ output: {
18
+ codecId: "pg/vector@1",
19
+ nativeType: "vector",
20
+ typeParams: { length: {
21
+ kind: "arg",
22
+ index: 0
23
+ } }
24
+ }
25
+ } } };
26
+
27
+ //#endregion
28
+ //#region src/core/codecs.ts
29
+ const vectorParamsSchema = type({ length: "number" }).narrow((params, ctx) => {
30
+ const { length } = params;
31
+ if (!Number.isInteger(length)) return ctx.mustBe("an integer");
32
+ if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
33
+ return true;
34
+ });
35
+ const PG_VECTOR_META = { db: { sql: { postgres: { nativeType: "vector" } } } };
36
+ var PgVectorCodec = class extends CodecImpl {
37
+ length;
38
+ constructor(descriptor, length) {
39
+ super(descriptor);
40
+ this.length = length;
41
+ }
42
+ assertVector(value) {
43
+ if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
44
+ if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
45
+ if (this.length !== void 0 && value.length !== this.length) throw new Error(`Vector length mismatch: expected ${this.length}, got ${value.length}`);
46
+ }
47
+ async encode(value, _ctx) {
48
+ this.assertVector(value);
49
+ return `[${value.join(",")}]`;
50
+ }
51
+ async decode(wire, _ctx) {
52
+ if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
53
+ if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
54
+ const content = wire.slice(1, -1).trim();
55
+ const parsed = content === "" ? [] : content.split(",").map((v) => {
56
+ const num = Number.parseFloat(v.trim());
57
+ if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
58
+ return num;
59
+ });
60
+ this.assertVector(parsed);
61
+ return parsed;
62
+ }
63
+ encodeJson(value) {
64
+ this.assertVector(value);
65
+ return value;
66
+ }
67
+ decodeJson(json) {
68
+ this.assertVector(json);
69
+ return json;
70
+ }
71
+ };
72
+ var PgVectorDescriptor = class extends CodecDescriptorImpl {
73
+ codecId = VECTOR_CODEC_ID;
74
+ traits = ["equality"];
75
+ targetTypes = ["vector"];
76
+ meta = PG_VECTOR_META;
77
+ paramsSchema = vectorParamsSchema;
78
+ renderOutputType(params) {
79
+ return `Vector<${params.length}>`;
80
+ }
81
+ /**
82
+ * The runtime calls `factory(undefined)(ctx)` to materialize a representative codec for parameterized descriptors that ship a no-params column variant (here, `vectorColumn` vs `vector(N)`). The runtime cast widens `params` to `unknown`, so guarding with an optional read keeps the typed call site (`factory({ length })`) strict while still producing a length-agnostic codec for representative use. Encode/decode for an undimensioned column run through this representative; the wire format `[v1,v2,...]` is dimension-independent.
83
+ */
84
+ factory(params) {
85
+ return () => new PgVectorCodec(this, params?.length);
86
+ }
87
+ };
88
+ const pgVectorDescriptor = new PgVectorDescriptor();
89
+ const codecDescriptorMap = { vector: pgVectorDescriptor };
90
+ const codecDescriptors = Object.values(codecDescriptorMap);
91
+
92
+ //#endregion
93
+ //#region src/core/registry.ts
94
+ /**
95
+ * Registry of every codec descriptor shipped by `@prisma-next/extension-pgvector`.
96
+ *
97
+ * Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.
98
+ */
99
+ const pgvectorCodecRegistry = buildCodecDescriptorRegistry(codecDescriptors);
100
+
101
+ //#endregion
102
+ //#region src/core/descriptor-meta.ts
103
+ const pgvectorTypeId = "pg/vector@1";
104
+ function pgvectorQueryOperations() {
105
+ return [{
106
+ method: "cosineDistance",
107
+ self: { codecId: pgvectorTypeId },
108
+ impl: (self, other) => {
109
+ const selfRefs = refsOf(self);
110
+ return buildOperation({
111
+ method: "cosineDistance",
112
+ args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],
113
+ returns: {
114
+ codecId: "pg/float8@1",
115
+ nullable: false
116
+ },
117
+ lowering: {
118
+ targetFamily: "sql",
119
+ strategy: "function",
120
+ template: "{{self}} <=> {{arg0}}"
121
+ }
122
+ });
123
+ }
124
+ }, {
125
+ method: "cosineSimilarity",
126
+ self: { codecId: pgvectorTypeId },
127
+ impl: (self, other) => {
128
+ const selfRefs = refsOf(self);
129
+ return buildOperation({
130
+ method: "cosineSimilarity",
131
+ args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],
132
+ returns: {
133
+ codecId: "pg/float8@1",
134
+ nullable: false
135
+ },
136
+ lowering: {
137
+ targetFamily: "sql",
138
+ strategy: "function",
139
+ template: "1 - ({{self}} <=> {{arg0}})"
140
+ }
141
+ });
142
+ }
143
+ }];
144
+ }
145
+ const pgvectorPackMetaBase = {
146
+ kind: "extension",
147
+ id: "pgvector",
148
+ familyId: "sql",
149
+ targetId: "postgres",
150
+ version: "0.0.1",
151
+ capabilities: { postgres: { "pgvector.cosine": true } },
152
+ authoring: { type: pgvectorAuthoringTypes },
153
+ types: {
154
+ codecTypes: {
155
+ codecDescriptors: Array.from(pgvectorCodecRegistry.values()),
156
+ import: {
157
+ package: "@prisma-next/extension-pgvector/codec-types",
158
+ named: "CodecTypes",
159
+ alias: "PgVectorTypes"
160
+ },
161
+ typeImports: [{
162
+ package: "@prisma-next/extension-pgvector/codec-types",
163
+ named: "Vector",
164
+ alias: "Vector"
165
+ }]
166
+ },
167
+ operationTypes: { import: {
168
+ package: "@prisma-next/extension-pgvector/operation-types",
169
+ named: "OperationTypes",
170
+ alias: "PgVectorOperationTypes"
171
+ } },
172
+ queryOperationTypes: { import: {
173
+ package: "@prisma-next/extension-pgvector/operation-types",
174
+ named: "QueryOperationTypes",
175
+ alias: "PgVectorQueryOperationTypes"
176
+ } },
177
+ storage: [{
178
+ typeId: pgvectorTypeId,
179
+ familyId: "sql",
180
+ targetId: "postgres",
181
+ nativeType: "vector"
182
+ }]
183
+ }
184
+ };
185
+ const pgvectorPackMeta = pgvectorPackMetaBase;
186
+
187
+ //#endregion
188
+ export { pgvectorQueryOperations as n, pgvectorCodecRegistry as r, pgvectorPackMeta as t };
189
+ //# sourceMappingURL=descriptor-meta-BaV3A8tJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-BaV3A8tJ.mjs","names":["arktype","codecDescriptors: readonly AnyCodecDescriptor[]","pgvectorCodecRegistry: CodecDescriptorRegistry","pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n}"],"sources":["../src/core/authoring.ts","../src/core/codecs.ts","../src/core/registry.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport { VECTOR_MAX_DIM } from './constants';\n\nexport const pgvectorAuthoringTypes = {\n pgvector: {\n Vector: {\n kind: 'typeConstructor',\n args: [\n { kind: 'number', name: 'length', integer: true, minimum: 1, maximum: VECTOR_MAX_DIM },\n ],\n output: {\n codecId: 'pg/vector@1',\n nativeType: 'vector',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\n * pgvector extension codec.\n *\n * Mirrors the patterns in `postgres/codecs-class.ts` and `sqlite/codecs-class.ts` for the single `pg/vector@1` codec. Three artifacts:\n *\n * 1. `PgVectorCodec` extends {@link CodecImpl} with the runtime encode/decode/encodeJson/decodeJson conversions inline. Conversions are simple enough (PostgreSQL `[1,2,3]` text format) that no shared helper module is warranted; the class body is the source of truth.\n * 2. `PgVectorDescriptor` extends {@link CodecDescriptorImpl} with the codec id, traits, target types, params schema (`{ length: number }`, validated against {@link VECTOR_MAX_DIM}), `meta` (postgres `nativeType: 'vector'`), and the emit-path `renderOutputType` producing `Vector<${length}>`.\n * 3. `pgVectorColumn(length)` per-codec column helper invoking `descriptor.factory({ length })` directly + passing the bare `nativeType: 'vector'`. The family-layer {@link expandNativeType} hook renders the parameterized form (`vector(1536)`) at emit/verify time from `nativeType` + `typeParams`.\n *\n * `length` threads into the runtime codec via the constructor so encode/decode/encodeJson/decodeJson enforce the declared dimension at every ingress path. Without this, `vector(3)` and `vector(1536)` would produce codecs with identical behaviour and a dimension-mismatched value would round-trip undetected.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport {\n type AnyCodecDescriptor,\n type CodecCallContext,\n CodecDescriptorImpl,\n CodecImpl,\n type CodecInstanceContext,\n type ColumnHelperFor,\n type ColumnHelperForStrict,\n column,\n} from '@prisma-next/framework-components/codec';\nimport type { ExtractCodecTypes } from '@prisma-next/sql-relational-core/ast';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { type as arktype } from 'arktype';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from './constants';\n\ntype VectorParams = { readonly length: number };\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}) satisfies StandardSchemaV1<VectorParams>;\n\nconst PG_VECTOR_META = { db: { sql: { postgres: { nativeType: 'vector' } } } } as const;\n\nexport class PgVectorCodec extends CodecImpl<\n typeof VECTOR_CODEC_ID,\n readonly ['equality'],\n string,\n number[]\n> {\n readonly length: number | undefined;\n\n constructor(descriptor: AnyCodecDescriptor, length: number | undefined) {\n super(descriptor);\n this.length = length;\n }\n\n assertVector(value: unknown): asserts value is number[] {\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 if (this.length !== undefined && value.length !== this.length) {\n throw new Error(`Vector length mismatch: expected ${this.length}, got ${value.length}`);\n }\n }\n\n async encode(value: number[], _ctx: CodecCallContext): Promise<string> {\n this.assertVector(value);\n return `[${value.join(',')}]`;\n }\n\n async decode(wire: string, _ctx: CodecCallContext): Promise<number[]> {\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\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 const parsed =\n content === ''\n ? []\n : 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 this.assertVector(parsed);\n return parsed;\n }\n\n encodeJson(value: number[]): JsonValue {\n this.assertVector(value);\n return value;\n }\n\n decodeJson(json: JsonValue): number[] {\n this.assertVector(json);\n return json;\n }\n}\n\nexport class PgVectorDescriptor extends CodecDescriptorImpl<VectorParams> {\n override readonly codecId = VECTOR_CODEC_ID;\n override readonly traits = ['equality'] as const;\n override readonly targetTypes = ['vector'] as const;\n override readonly meta = PG_VECTOR_META;\n override readonly paramsSchema: StandardSchemaV1<VectorParams> = vectorParamsSchema;\n override renderOutputType(params: VectorParams): string {\n return `Vector<${params.length}>`;\n }\n /**\n * The runtime calls `factory(undefined)(ctx)` to materialize a representative codec for parameterized descriptors that ship a no-params column variant (here, `vectorColumn` vs `vector(N)`). The runtime cast widens `params` to `unknown`, so guarding with an optional read keeps the typed call site (`factory({ length })`) strict while still producing a length-agnostic codec for representative use. Encode/decode for an undimensioned column run through this representative; the wire format `[v1,v2,...]` is dimension-independent.\n */\n override factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec {\n return () => new PgVectorCodec(this, (params as VectorParams | undefined)?.length);\n }\n}\n\nexport const pgVectorDescriptor = new PgVectorDescriptor();\n\n/**\n * Per-codec column helper for `pg/vector@1`. Generic over `N extends number` so the column site preserves the dimension literal in `typeParams` (e.g. `pgVectorColumn(1536)` packs `typeParams: { length: 1536 }`).\n *\n * Passes the bare `nativeType: 'vector'`; the family-layer `expandNativeType` hook renders the parameterized form (`vector(1536)`) at emit/verify time from `nativeType` + `typeParams`.\n */\nexport const pgVectorColumn = <N extends number>(length: N) =>\n column(pgVectorDescriptor.factory({ length }), pgVectorDescriptor.codecId, { length }, 'vector');\n\npgVectorColumn satisfies ColumnHelperFor<PgVectorDescriptor>;\npgVectorColumn satisfies ColumnHelperForStrict<PgVectorDescriptor>;\n\nconst codecDescriptorMap = {\n vector: pgVectorDescriptor,\n} as const;\n\nexport type CodecTypes = ExtractCodecTypes<typeof codecDescriptorMap>;\n\nexport const codecDescriptors: readonly AnyCodecDescriptor[] = Object.values(codecDescriptorMap);\n","import { buildCodecDescriptorRegistry } from '@prisma-next/sql-relational-core/codec-descriptor-registry';\nimport type { CodecDescriptorRegistry } from '@prisma-next/sql-relational-core/query-lane-context';\nimport { codecDescriptors } from './codecs';\n\n/**\n * Registry of every codec descriptor shipped by `@prisma-next/extension-pgvector`.\n *\n * Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.\n */\nexport const pgvectorCodecRegistry: CodecDescriptorRegistry =\n buildCodecDescriptorRegistry(codecDescriptors);\n","import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport {\n buildOperation,\n type CodecExpression,\n type Expression,\n refsOf,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport { pgvectorAuthoringTypes } from './authoring';\nimport { pgvectorCodecRegistry } from './registry';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\nexport function pgvectorQueryOperations<\n CT extends CodecTypesBase,\n>(): readonly SqlOperationDescriptor[] {\n return [\n {\n method: 'cosineDistance',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> => {\n const selfRefs = refsOf(self);\n return buildOperation({\n method: 'cosineDistance',\n args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n });\n },\n },\n {\n method: 'cosineSimilarity',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> => {\n const selfRefs = refsOf(self);\n return buildOperation({\n method: 'cosineSimilarity',\n args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],\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 },\n ];\n}\n\nconst pgvectorPackMetaBase = {\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 authoring: {\n type: pgvectorAuthoringTypes,\n },\n types: {\n codecTypes: {\n codecDescriptors: Array.from(pgvectorCodecRegistry.values()),\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 },\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\nexport const pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = pgvectorPackMetaBase;\n"],"mappings":"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"}
package/dist/pack.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { t as CodecTypes } from "./codec-types-BifaP625.mjs";
2
- import * as _prisma_next_sql_relational_core_ast0 from "@prisma-next/sql-relational-core/ast";
1
+ import { t as CodecTypes } from "./codec-types-BFZqW_TL.mjs";
2
+ import * as _prisma_next_framework_components_codec0 from "@prisma-next/framework-components/codec";
3
3
 
4
4
  //#region src/core/descriptor-meta.d.ts
5
5
 
@@ -42,7 +42,7 @@ declare const pgvectorPackMetaBase: {
42
42
  };
43
43
  readonly types: {
44
44
  readonly codecTypes: {
45
- readonly codecInstances: _prisma_next_sql_relational_core_ast0.Codec<"pg/vector@1", readonly ["equality"], string, number[], Record<string, unknown>, unknown>[];
45
+ readonly codecDescriptors: _prisma_next_framework_components_codec0.CodecDescriptor<unknown>[];
46
46
  readonly import: {
47
47
  readonly package: "@prisma-next/extension-pgvector/codec-types";
48
48
  readonly named: "CodecTypes";
@@ -1 +1 @@
1
- {"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":";;;;;cA0DM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAgDI,qCAAA,CAAA,8DAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEG,yBAAyB;0BACZ"}
1
+ {"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":";;;;;cA+DM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAgDI,wCAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEG,yBAAyB;0BACZ"}
package/dist/pack.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as pgvectorPackMeta } from "./descriptor-meta-DTopW_37.mjs";
1
+ import { t as pgvectorPackMeta } from "./descriptor-meta-BaV3A8tJ.mjs";
2
2
 
3
3
  export { pgvectorPackMeta as default };
@@ -1,7 +1,17 @@
1
1
  import { SqlRuntimeExtensionDescriptor } from "@prisma-next/sql-runtime";
2
+ import { CodecDescriptorRegistry } from "@prisma-next/sql-relational-core/query-lane-context";
2
3
 
4
+ //#region src/core/registry.d.ts
5
+
6
+ /**
7
+ * Registry of every codec descriptor shipped by `@prisma-next/extension-pgvector`.
8
+ *
9
+ * Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.
10
+ */
11
+ declare const pgvectorCodecRegistry: CodecDescriptorRegistry;
12
+ //#endregion
3
13
  //#region src/exports/runtime.d.ts
4
14
  declare const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
5
15
  //#endregion
6
- export { pgvectorRuntimeDescriptor as default };
16
+ export { pgvectorRuntimeDescriptor as default, pgvectorCodecRegistry };
7
17
  //# sourceMappingURL=runtime.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;cA6DM,2BAA2B"}
1
+ {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/registry.ts","../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;;AASA;;cAAa,uBAAuB;;;cCL9B,2BAA2B"}
package/dist/runtime.mjs CHANGED
@@ -1,40 +1,15 @@
1
- import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-Co5golCK.mjs";
2
- import { n as pgvectorQueryOperations, r as codecDefinitions, t as pgvectorPackMeta } from "./descriptor-meta-DTopW_37.mjs";
3
- import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
4
- import { type } from "arktype";
1
+ import { n as pgvectorQueryOperations, r as pgvectorCodecRegistry, t as pgvectorPackMeta } from "./descriptor-meta-BaV3A8tJ.mjs";
5
2
 
6
3
  //#region src/exports/runtime.ts
7
- const vectorParamsSchema = type({ length: "number" }).narrow((params, ctx) => {
8
- const { length } = params;
9
- if (!Number.isInteger(length)) return ctx.mustBe("an integer");
10
- if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
11
- return true;
12
- });
13
- const sharedVectorCodec = codecDefinitions.vector.codec;
14
- const vectorFactory = (_params) => (_ctx) => sharedVectorCodec;
15
- const parameterizedCodecDescriptors = [{
16
- codecId: VECTOR_CODEC_ID,
17
- traits: ["equality"],
18
- targetTypes: ["vector"],
19
- paramsSchema: vectorParamsSchema,
20
- renderOutputType: (params) => `Vector<${params.length}>`,
21
- factory: vectorFactory
22
- }];
23
- function createPgvectorCodecRegistry() {
24
- const registry = createCodecRegistry();
25
- for (const def of Object.values(codecDefinitions)) registry.register(def.codec);
26
- return registry;
27
- }
28
4
  const pgvectorRuntimeDescriptor = {
29
5
  kind: "extension",
30
6
  id: pgvectorPackMeta.id,
31
7
  version: pgvectorPackMeta.version,
32
8
  familyId: "sql",
33
9
  targetId: "postgres",
34
- types: { codecTypes: { codecInstances: Object.values(codecDefinitions).map((def) => def.codec) } },
35
- codecs: createPgvectorCodecRegistry,
10
+ types: { codecTypes: { codecDescriptors: Array.from(pgvectorCodecRegistry.values()) } },
11
+ codecs: () => Array.from(pgvectorCodecRegistry.values()),
36
12
  queryOperations: () => pgvectorQueryOperations(),
37
- parameterizedCodecs: () => parameterizedCodecDescriptors,
38
13
  create() {
39
14
  return {
40
15
  familyId: "sql",
@@ -45,5 +20,5 @@ const pgvectorRuntimeDescriptor = {
45
20
  var runtime_default = pgvectorRuntimeDescriptor;
46
21
 
47
22
  //#endregion
48
- export { runtime_default as default };
23
+ export { runtime_default as default, pgvectorCodecRegistry };
49
24
  //# sourceMappingURL=runtime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":["arktype","sharedVectorCodec: Codec","pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>"],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { Codec, CodecInstanceContext } from '@prisma-next/framework-components/codec';\nimport { 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 { pgvectorPackMeta, pgvectorQueryOperations } 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\n// pgvector's encode is parameter-independent (the wire format `[v1,v2,...]`\n// doesn't care about declared length), so the resolved codec for every\n// `(length)` instance is the same shared codec object today. The factory\n// returns it directly; `ctx` is unused. When a future refactor wants per-\n// instance state (e.g. capping wire length to declared dimension), the\n// closure over `params` is the place to add it.\n//\n// The factory parameter types as the family-agnostic\n// `CodecInstanceContext` because pgvector doesn't read the SQL-specific\n// `usedAt` field. The SQL runtime materializer passes a\n// `SqlCodecInstanceContext`; family-agnostic factories are structurally\n// compatible with the SQL extended type.\nconst sharedVectorCodec: Codec = codecDefinitions.vector.codec;\nconst vectorFactory = (_params: { readonly length: number }) => (_ctx: CodecInstanceContext) =>\n sharedVectorCodec;\n\nconst parameterizedCodecDescriptors = [\n {\n codecId: VECTOR_CODEC_ID,\n traits: ['equality'] as const,\n targetTypes: ['vector'] as const,\n paramsSchema: vectorParamsSchema,\n renderOutputType: (params: { readonly length: number }) => `Vector<${params.length}>`,\n factory: vectorFactory,\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 // Mirror `pgvectorPackMeta.types.codecTypes.codecInstances` here so that\n // runtime-plane assemblers driven by `extractCodecLookup` (which reads\n // `descriptor.types?.codecTypes?.codecInstances`) discover `pg/vector@1`.\n // Without this, the Postgres adapter's runtime-plane codec lookup misses\n // the vector codec and `$N::vector` would silently disappear once the\n // renderer switches to lookup-driven cast policy.\n types: {\n codecTypes: {\n codecInstances: Object.values(codecDefinitions).map((def) => def.codec),\n },\n },\n codecs: createPgvectorCodecRegistry,\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":";;;;;;AAWA,MAAM,qBAAqBA,KAAQ,EACjC,QAAQ,UACT,CAAC,CAAC,QAAQ,QAAQ,QAAQ;CACzB,MAAM,EAAE,WAAW;AACnB,KAAI,CAAC,OAAO,UAAU,OAAO,CAC3B,QAAO,IAAI,OAAO,aAAa;AAEjC,KAAI,SAAS,KAAK,SAAS,eACzB,QAAO,IAAI,OAAO,oBAAoB,eAAe,GAAG;AAE1D,QAAO;EACP;AAcF,MAAMC,oBAA2B,iBAAiB,OAAO;AACzD,MAAM,iBAAiB,aAA0C,SAC/D;AAEF,MAAM,gCAAgC,CACpC;CACE,SAAS;CACT,QAAQ,CAAC,WAAW;CACpB,aAAa,CAAC,SAAS;CACvB,cAAc;CACd,mBAAmB,WAAwC,UAAU,OAAO,OAAO;CACnF,SAAS;CACV,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;CAOV,OAAO,EACL,YAAY,EACV,gBAAgB,OAAO,OAAO,iBAAiB,CAAC,KAAK,QAAQ,IAAI,MAAM,EACxE,EACF;CACD,QAAQ;CACR,uBAAuB,yBAAyB;CAChD,2BAA2B;CAC3B,SAAS;AACP,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ;AAED,sBAAe"}
1
+ {"version":3,"file":"runtime.mjs","names":["pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>"],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';\nimport { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';\nimport { pgvectorCodecRegistry } from '../core/registry';\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 // Expose the unified descriptor list so `extractCodecLookup` reads `targetTypes` / `meta` / `renderOutputType` directly off the descriptors and materializes the representative `Codec` for the SQL renderer's cast-policy lookup.\n types: {\n codecTypes: {\n codecDescriptors: Array.from(pgvectorCodecRegistry.values()),\n },\n },\n codecs: () => Array.from(pgvectorCodecRegistry.values()),\n queryOperations: () => pgvectorQueryOperations(),\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n\nexport { pgvectorCodecRegistry };\nexport default pgvectorRuntimeDescriptor;\n"],"mappings":";;;AAIA,MAAMA,4BAAuE;CAC3E,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,UAAU;CACV,UAAU;CAEV,OAAO,EACL,YAAY,EACV,kBAAkB,MAAM,KAAK,sBAAsB,QAAQ,CAAC,EAC7D,EACF;CACD,cAAc,MAAM,KAAK,sBAAsB,QAAQ,CAAC;CACxD,uBAAuB,yBAAyB;CAChD,SAAS;AACP,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ;AAGD,sBAAe"}
package/package.json CHANGED
@@ -1,30 +1,31 @@
1
1
  {
2
2
  "name": "@prisma-next/extension-pgvector",
3
- "version": "0.5.0-dev.60",
3
+ "version": "0.5.0-dev.62",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "dependencies": {
8
+ "@standard-schema/spec": "^1.1.0",
8
9
  "arktype": "^2.0.0",
9
- "@prisma-next/contract": "0.5.0-dev.60",
10
- "@prisma-next/contract-authoring": "0.5.0-dev.60",
11
- "@prisma-next/family-sql": "0.5.0-dev.60",
12
- "@prisma-next/framework-components": "0.5.0-dev.60",
13
- "@prisma-next/sql-relational-core": "0.5.0-dev.60",
14
- "@prisma-next/sql-schema-ir": "0.5.0-dev.60",
15
- "@prisma-next/sql-runtime": "0.5.0-dev.60",
16
- "@prisma-next/sql-operations": "0.5.0-dev.60"
10
+ "@prisma-next/contract": "0.5.0-dev.62",
11
+ "@prisma-next/family-sql": "0.5.0-dev.62",
12
+ "@prisma-next/framework-components": "0.5.0-dev.62",
13
+ "@prisma-next/sql-relational-core": "0.5.0-dev.62",
14
+ "@prisma-next/contract-authoring": "0.5.0-dev.62",
15
+ "@prisma-next/sql-operations": "0.5.0-dev.62",
16
+ "@prisma-next/sql-schema-ir": "0.5.0-dev.62",
17
+ "@prisma-next/sql-runtime": "0.5.0-dev.62"
17
18
  },
18
19
  "devDependencies": {
19
20
  "tsdown": "0.18.4",
20
21
  "typescript": "5.9.3",
21
22
  "vitest": "4.0.17",
22
- "@prisma-next/sql-contract": "0.5.0-dev.60",
23
- "@prisma-next/operations": "0.5.0-dev.60",
23
+ "@prisma-next/operations": "0.5.0-dev.62",
24
+ "@prisma-next/sql-contract-ts": "0.5.0-dev.62",
24
25
  "@prisma-next/test-utils": "0.0.1",
25
- "@prisma-next/sql-contract-ts": "0.5.0-dev.60",
26
+ "@prisma-next/tsconfig": "0.0.0",
26
27
  "@prisma-next/tsdown": "0.0.0",
27
- "@prisma-next/tsconfig": "0.0.0"
28
+ "@prisma-next/sql-contract": "0.5.0-dev.62"
28
29
  },
29
30
  "files": [
30
31
  "dist",
@@ -1,77 +1,145 @@
1
1
  /**
2
- * Vector codec implementation for pgvector extension.
2
+ * pgvector extension codec.
3
3
  *
4
- * Provides encoding/decoding for the `vector` PostgreSQL type.
5
- * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
4
+ * Mirrors the patterns in `postgres/codecs-class.ts` and `sqlite/codecs-class.ts` for the single `pg/vector@1` codec. Three artifacts:
5
+ *
6
+ * 1. `PgVectorCodec` extends {@link CodecImpl} with the runtime encode/decode/encodeJson/decodeJson conversions inline. Conversions are simple enough (PostgreSQL `[1,2,3]` text format) that no shared helper module is warranted; the class body is the source of truth.
7
+ * 2. `PgVectorDescriptor` extends {@link CodecDescriptorImpl} with the codec id, traits, target types, params schema (`{ length: number }`, validated against {@link VECTOR_MAX_DIM}), `meta` (postgres `nativeType: 'vector'`), and the emit-path `renderOutputType` producing `Vector<${length}>`.
8
+ * 3. `pgVectorColumn(length)` per-codec column helper invoking `descriptor.factory({ length })` directly + passing the bare `nativeType: 'vector'`. The family-layer {@link expandNativeType} hook renders the parameterized form (`vector(1536)`) at emit/verify time from `nativeType` + `typeParams`.
9
+ *
10
+ * `length` threads into the runtime codec via the constructor so encode/decode/encodeJson/decodeJson enforce the declared dimension at every ingress path. Without this, `vector(3)` and `vector(1536)` would produce codecs with identical behaviour and a dimension-mismatched value would round-trip undetected.
6
11
  */
7
12
 
8
- import { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';
9
-
10
- const pgVectorCodec = codec({
11
- typeId: 'pg/vector@1',
12
- targetTypes: ['vector'],
13
- traits: ['equality'],
14
- renderOutputType: (typeParams) => {
15
- const length = typeParams['length'];
16
- if (length === undefined) return undefined;
17
- if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {
18
- throw new Error(
19
- `renderOutputType: expected positive integer "length" in typeParams for Vector, got ${String(length)}`,
20
- );
21
- }
22
- return `Vector<${length}>`;
23
- },
24
- encode: (value: number[]): string => {
25
- // Validate that value is an array of numbers
13
+ import type { JsonValue } from '@prisma-next/contract/types';
14
+ import {
15
+ type AnyCodecDescriptor,
16
+ type CodecCallContext,
17
+ CodecDescriptorImpl,
18
+ CodecImpl,
19
+ type CodecInstanceContext,
20
+ type ColumnHelperFor,
21
+ type ColumnHelperForStrict,
22
+ column,
23
+ } from '@prisma-next/framework-components/codec';
24
+ import type { ExtractCodecTypes } from '@prisma-next/sql-relational-core/ast';
25
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
26
+ import { type as arktype } from 'arktype';
27
+ import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from './constants';
28
+
29
+ type VectorParams = { readonly length: number };
30
+
31
+ const vectorParamsSchema = arktype({
32
+ length: 'number',
33
+ }).narrow((params, ctx) => {
34
+ const { length } = params;
35
+ if (!Number.isInteger(length)) {
36
+ return ctx.mustBe('an integer');
37
+ }
38
+ if (length < 1 || length > VECTOR_MAX_DIM) {
39
+ return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
40
+ }
41
+ return true;
42
+ }) satisfies StandardSchemaV1<VectorParams>;
43
+
44
+ const PG_VECTOR_META = { db: { sql: { postgres: { nativeType: 'vector' } } } } as const;
45
+
46
+ export class PgVectorCodec extends CodecImpl<
47
+ typeof VECTOR_CODEC_ID,
48
+ readonly ['equality'],
49
+ string,
50
+ number[]
51
+ > {
52
+ readonly length: number | undefined;
53
+
54
+ constructor(descriptor: AnyCodecDescriptor, length: number | undefined) {
55
+ super(descriptor);
56
+ this.length = length;
57
+ }
58
+
59
+ assertVector(value: unknown): asserts value is number[] {
26
60
  if (!Array.isArray(value)) {
27
61
  throw new Error('Vector value must be an array of numbers');
28
62
  }
29
63
  if (!value.every((v) => typeof v === 'number')) {
30
64
  throw new Error('Vector value must contain only numbers');
31
65
  }
32
- // Format as PostgreSQL vector text format: [1,2,3]
33
- // PostgreSQL's pg library requires the vector format string
66
+ if (this.length !== undefined && value.length !== this.length) {
67
+ throw new Error(`Vector length mismatch: expected ${this.length}, got ${value.length}`);
68
+ }
69
+ }
70
+
71
+ async encode(value: number[], _ctx: CodecCallContext): Promise<string> {
72
+ this.assertVector(value);
34
73
  return `[${value.join(',')}]`;
35
- },
36
- decode: (wire: string): number[] => {
37
- // Handle string format from PostgreSQL: [1,2,3]
74
+ }
75
+
76
+ async decode(wire: string, _ctx: CodecCallContext): Promise<number[]> {
38
77
  if (typeof wire !== 'string') {
39
78
  throw new Error('Vector wire value must be a string');
40
79
  }
41
- // Parse PostgreSQL vector format: [1,2,3]
42
80
  if (!wire.startsWith('[') || !wire.endsWith(']')) {
43
81
  throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
44
82
  }
45
83
  const content = wire.slice(1, -1).trim();
46
- if (content === '') {
47
- return [];
48
- }
49
- const values = content.split(',').map((v) => {
50
- const num = Number.parseFloat(v.trim());
51
- if (Number.isNaN(num)) {
52
- throw new Error(`Invalid vector value: "${v}" is not a number`);
53
- }
54
- return num;
55
- });
56
- return values;
57
- },
58
- meta: {
59
- db: {
60
- sql: {
61
- postgres: {
62
- nativeType: 'vector',
63
- },
64
- },
65
- },
66
- },
67
- });
68
-
69
- // Build codec definitions using the builder DSL
70
- const codecs = defineCodecs().add('vector', pgVectorCodec);
71
-
72
- // Export derived structures directly from codecs builder
73
- export const codecDefinitions = codecs.codecDefinitions;
74
- export const dataTypes = codecs.dataTypes;
75
-
76
- // Export types derived from codecs builder
77
- export type CodecTypes = typeof codecs.CodecTypes;
84
+ const parsed =
85
+ content === ''
86
+ ? []
87
+ : content.split(',').map((v) => {
88
+ const num = Number.parseFloat(v.trim());
89
+ if (Number.isNaN(num)) {
90
+ throw new Error(`Invalid vector value: "${v}" is not a number`);
91
+ }
92
+ return num;
93
+ });
94
+ this.assertVector(parsed);
95
+ return parsed;
96
+ }
97
+
98
+ encodeJson(value: number[]): JsonValue {
99
+ this.assertVector(value);
100
+ return value;
101
+ }
102
+
103
+ decodeJson(json: JsonValue): number[] {
104
+ this.assertVector(json);
105
+ return json;
106
+ }
107
+ }
108
+
109
+ export class PgVectorDescriptor extends CodecDescriptorImpl<VectorParams> {
110
+ override readonly codecId = VECTOR_CODEC_ID;
111
+ override readonly traits = ['equality'] as const;
112
+ override readonly targetTypes = ['vector'] as const;
113
+ override readonly meta = PG_VECTOR_META;
114
+ override readonly paramsSchema: StandardSchemaV1<VectorParams> = vectorParamsSchema;
115
+ override renderOutputType(params: VectorParams): string {
116
+ return `Vector<${params.length}>`;
117
+ }
118
+ /**
119
+ * The runtime calls `factory(undefined)(ctx)` to materialize a representative codec for parameterized descriptors that ship a no-params column variant (here, `vectorColumn` vs `vector(N)`). The runtime cast widens `params` to `unknown`, so guarding with an optional read keeps the typed call site (`factory({ length })`) strict while still producing a length-agnostic codec for representative use. Encode/decode for an undimensioned column run through this representative; the wire format `[v1,v2,...]` is dimension-independent.
120
+ */
121
+ override factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec {
122
+ return () => new PgVectorCodec(this, (params as VectorParams | undefined)?.length);
123
+ }
124
+ }
125
+
126
+ export const pgVectorDescriptor = new PgVectorDescriptor();
127
+
128
+ /**
129
+ * Per-codec column helper for `pg/vector@1`. Generic over `N extends number` so the column site preserves the dimension literal in `typeParams` (e.g. `pgVectorColumn(1536)` packs `typeParams: { length: 1536 }`).
130
+ *
131
+ * Passes the bare `nativeType: 'vector'`; the family-layer `expandNativeType` hook renders the parameterized form (`vector(1536)`) at emit/verify time from `nativeType` + `typeParams`.
132
+ */
133
+ export const pgVectorColumn = <N extends number>(length: N) =>
134
+ column(pgVectorDescriptor.factory({ length }), pgVectorDescriptor.codecId, { length }, 'vector');
135
+
136
+ pgVectorColumn satisfies ColumnHelperFor<PgVectorDescriptor>;
137
+ pgVectorColumn satisfies ColumnHelperForStrict<PgVectorDescriptor>;
138
+
139
+ const codecDescriptorMap = {
140
+ vector: pgVectorDescriptor,
141
+ } as const;
142
+
143
+ export type CodecTypes = ExtractCodecTypes<typeof codecDescriptorMap>;
144
+
145
+ export const codecDescriptors: readonly AnyCodecDescriptor[] = Object.values(codecDescriptorMap);
@@ -3,11 +3,12 @@ import {
3
3
  buildOperation,
4
4
  type CodecExpression,
5
5
  type Expression,
6
+ refsOf,
6
7
  toExpr,
7
8
  } from '@prisma-next/sql-relational-core/expression';
8
9
  import type { CodecTypes } from '../types/codec-types';
9
10
  import { pgvectorAuthoringTypes } from './authoring';
10
- import { codecDefinitions } from './codecs';
11
+ import { pgvectorCodecRegistry } from './registry';
11
12
 
12
13
  const pgvectorTypeId = 'pg/vector@1' as const;
13
14
 
@@ -23,17 +24,19 @@ export function pgvectorQueryOperations<
23
24
  impl: (
24
25
  self: CodecExpression<'pg/vector@1', boolean, CT>,
25
26
  other: CodecExpression<'pg/vector@1', boolean, CT>,
26
- ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>
27
- buildOperation({
27
+ ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> => {
28
+ const selfRefs = refsOf(self);
29
+ return buildOperation({
28
30
  method: 'cosineDistance',
29
- args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
31
+ args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],
30
32
  returns: { codecId: 'pg/float8@1', nullable: false },
31
33
  lowering: {
32
34
  targetFamily: 'sql',
33
35
  strategy: 'function',
34
36
  template: '{{self}} <=> {{arg0}}',
35
37
  },
36
- }),
38
+ });
39
+ },
37
40
  },
38
41
  {
39
42
  method: 'cosineSimilarity',
@@ -41,17 +44,19 @@ export function pgvectorQueryOperations<
41
44
  impl: (
42
45
  self: CodecExpression<'pg/vector@1', boolean, CT>,
43
46
  other: CodecExpression<'pg/vector@1', boolean, CT>,
44
- ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>
45
- buildOperation({
47
+ ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> => {
48
+ const selfRefs = refsOf(self);
49
+ return buildOperation({
46
50
  method: 'cosineSimilarity',
47
- args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
51
+ args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],
48
52
  returns: { codecId: 'pg/float8@1', nullable: false },
49
53
  lowering: {
50
54
  targetFamily: 'sql',
51
55
  strategy: 'function',
52
56
  template: '1 - ({{self}} <=> {{arg0}})',
53
57
  },
54
- }),
58
+ });
59
+ },
55
60
  },
56
61
  ];
57
62
  }
@@ -72,7 +77,7 @@ const pgvectorPackMetaBase = {
72
77
  },
73
78
  types: {
74
79
  codecTypes: {
75
- codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
80
+ codecDescriptors: Array.from(pgvectorCodecRegistry.values()),
76
81
  import: {
77
82
  package: '@prisma-next/extension-pgvector/codec-types',
78
83
  named: 'CodecTypes',
@@ -0,0 +1,11 @@
1
+ import { buildCodecDescriptorRegistry } from '@prisma-next/sql-relational-core/codec-descriptor-registry';
2
+ import type { CodecDescriptorRegistry } from '@prisma-next/sql-relational-core/query-lane-context';
3
+ import { codecDescriptors } from './codecs';
4
+
5
+ /**
6
+ * Registry of every codec descriptor shipped by `@prisma-next/extension-pgvector`.
7
+ *
8
+ * Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.
9
+ */
10
+ export const pgvectorCodecRegistry: CodecDescriptorRegistry =
11
+ buildCodecDescriptorRegistry(codecDescriptors);
@@ -1,16 +1,14 @@
1
1
  /**
2
2
  * Column type descriptors for pgvector extension.
3
3
  *
4
- * These descriptors provide both codecId and nativeType for use in contract authoring.
5
- * They are derived from the same source of truth as codec definitions and manifests.
4
+ * These descriptors provide both codecId and nativeType for use in contract authoring. They are derived from the same source of truth as codec definitions and manifests.
6
5
  */
7
6
 
8
- import type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';
7
+ import type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';
9
8
  import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
10
9
 
11
10
  /**
12
- * Static vector column descriptor without dimension.
13
- * Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
11
+ * Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
14
12
  */
15
13
  export const vectorColumn = {
16
14
  codecId: VECTOR_CODEC_ID,
@@ -25,7 +23,6 @@ export const vectorColumn = {
25
23
  * .column('embedding', { type: vector(1536), nullable: false })
26
24
  * // Produces: nativeType: 'vector', typeParams: { length: 1536 }
27
25
  * ```
28
- *
29
26
  * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
30
27
  * @returns A column type descriptor with `typeParams.length` set
31
28
  * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
@@ -1,63 +1,6 @@
1
- import type { Codec, CodecInstanceContext } from '@prisma-next/framework-components/codec';
2
- import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
- import type {
4
- RuntimeParameterizedCodecDescriptor,
5
- SqlRuntimeExtensionDescriptor,
6
- } from '@prisma-next/sql-runtime';
7
- import { type as arktype } from 'arktype';
8
- import { codecDefinitions } from '../core/codecs';
9
- import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
1
+ import type { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';
10
2
  import { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';
11
-
12
- const vectorParamsSchema = arktype({
13
- length: 'number',
14
- }).narrow((params, ctx) => {
15
- const { length } = params;
16
- if (!Number.isInteger(length)) {
17
- return ctx.mustBe('an integer');
18
- }
19
- if (length < 1 || length > VECTOR_MAX_DIM) {
20
- return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
21
- }
22
- return true;
23
- });
24
-
25
- // pgvector's encode is parameter-independent (the wire format `[v1,v2,...]`
26
- // doesn't care about declared length), so the resolved codec for every
27
- // `(length)` instance is the same shared codec object today. The factory
28
- // returns it directly; `ctx` is unused. When a future refactor wants per-
29
- // instance state (e.g. capping wire length to declared dimension), the
30
- // closure over `params` is the place to add it.
31
- //
32
- // The factory parameter types as the family-agnostic
33
- // `CodecInstanceContext` because pgvector doesn't read the SQL-specific
34
- // `usedAt` field. The SQL runtime materializer passes a
35
- // `SqlCodecInstanceContext`; family-agnostic factories are structurally
36
- // compatible with the SQL extended type.
37
- const sharedVectorCodec: Codec = codecDefinitions.vector.codec;
38
- const vectorFactory = (_params: { readonly length: number }) => (_ctx: CodecInstanceContext) =>
39
- sharedVectorCodec;
40
-
41
- const parameterizedCodecDescriptors = [
42
- {
43
- codecId: VECTOR_CODEC_ID,
44
- traits: ['equality'] as const,
45
- targetTypes: ['vector'] as const,
46
- paramsSchema: vectorParamsSchema,
47
- renderOutputType: (params: { readonly length: number }) => `Vector<${params.length}>`,
48
- factory: vectorFactory,
49
- },
50
- ] as const satisfies ReadonlyArray<
51
- RuntimeParameterizedCodecDescriptor<{ readonly length: number }>
52
- >;
53
-
54
- function createPgvectorCodecRegistry() {
55
- const registry = createCodecRegistry();
56
- for (const def of Object.values(codecDefinitions)) {
57
- registry.register(def.codec);
58
- }
59
- return registry;
60
- }
3
+ import { pgvectorCodecRegistry } from '../core/registry';
61
4
 
62
5
  const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
63
6
  kind: 'extension' as const,
@@ -65,20 +8,14 @@ const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
65
8
  version: pgvectorPackMeta.version,
66
9
  familyId: 'sql' as const,
67
10
  targetId: 'postgres' as const,
68
- // Mirror `pgvectorPackMeta.types.codecTypes.codecInstances` here so that
69
- // runtime-plane assemblers driven by `extractCodecLookup` (which reads
70
- // `descriptor.types?.codecTypes?.codecInstances`) discover `pg/vector@1`.
71
- // Without this, the Postgres adapter's runtime-plane codec lookup misses
72
- // the vector codec and `$N::vector` would silently disappear once the
73
- // renderer switches to lookup-driven cast policy.
11
+ // Expose the unified descriptor list so `extractCodecLookup` reads `targetTypes` / `meta` / `renderOutputType` directly off the descriptors and materializes the representative `Codec` for the SQL renderer's cast-policy lookup.
74
12
  types: {
75
13
  codecTypes: {
76
- codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
14
+ codecDescriptors: Array.from(pgvectorCodecRegistry.values()),
77
15
  },
78
16
  },
79
- codecs: createPgvectorCodecRegistry,
17
+ codecs: () => Array.from(pgvectorCodecRegistry.values()),
80
18
  queryOperations: () => pgvectorQueryOperations(),
81
- parameterizedCodecs: () => parameterizedCodecDescriptors,
82
19
  create() {
83
20
  return {
84
21
  familyId: 'sql' as const,
@@ -87,4 +24,5 @@ const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
87
24
  },
88
25
  };
89
26
 
27
+ export { pgvectorCodecRegistry };
90
28
  export default pgvectorRuntimeDescriptor;
@@ -1,27 +0,0 @@
1
- import * as _prisma_next_sql_relational_core_ast0 from "@prisma-next/sql-relational-core/ast";
2
-
3
- //#region src/core/codecs.d.ts
4
-
5
- /**
6
- * Vector codec implementation for pgvector extension.
7
- *
8
- * Provides encoding/decoding for the `vector` PostgreSQL type.
9
- * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
10
- */
11
- declare const codecs: _prisma_next_sql_relational_core_ast0.CodecDefBuilder<{} & Record<"vector", _prisma_next_sql_relational_core_ast0.Codec<"pg/vector@1", readonly ["equality"], string, number[], Record<string, unknown>, unknown>>>;
12
- type CodecTypes$1 = typeof codecs.CodecTypes;
13
- //#endregion
14
- //#region src/types/codec-types.d.ts
15
- /**
16
- * Type-level branded vector.
17
- *
18
- * The runtime values are plain number arrays, but parameterized column typing can
19
- * carry the dimension at the type level (e.g. Vector<1536>).
20
- */
21
- type Vector<N extends number = number> = number[] & {
22
- readonly __vectorLength?: N;
23
- };
24
- type CodecTypes = CodecTypes$1;
25
- //#endregion
26
- export { Vector as n, CodecTypes as t };
27
- //# sourceMappingURL=codec-types-BifaP625.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codec-types-BifaP625.d.mts","names":[],"sources":["../src/core/codecs.ts","../src/types/codec-types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAqEY;;;cAAN,MAAM,EAAA,qCAAA,CAAA,eAAA,CAAA,CAAA,CAAA,GAAA,MAAA,CAAA,QAAA,EAAA,qCAAA,CAAA,KAAA,CAAA,aAAA,EAAA,SAAA,CAAA,UAAA,CAAA,EAAA,MAAA,EAAA,MAAA,EAAA,EAAA,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,CAAA,CAAA,CAAA;KAOA,YAAA,UAAoB,MAAA,CAAO;;;AAAvC;;;;AC3DA;AAEA;KAFY;4BAA2E;;KAE3E,UAAA,GAAa"}
@@ -1,147 +0,0 @@
1
- import { n as VECTOR_MAX_DIM } from "./constants-Co5golCK.mjs";
2
- import { buildOperation, toExpr } from "@prisma-next/sql-relational-core/expression";
3
- import { codec, defineCodecs } from "@prisma-next/sql-relational-core/ast";
4
-
5
- //#region src/core/authoring.ts
6
- const pgvectorAuthoringTypes = { pgvector: { Vector: {
7
- kind: "typeConstructor",
8
- args: [{
9
- kind: "number",
10
- name: "length",
11
- integer: true,
12
- minimum: 1,
13
- maximum: VECTOR_MAX_DIM
14
- }],
15
- output: {
16
- codecId: "pg/vector@1",
17
- nativeType: "vector",
18
- typeParams: { length: {
19
- kind: "arg",
20
- index: 0
21
- } }
22
- }
23
- } } };
24
-
25
- //#endregion
26
- //#region src/core/codecs.ts
27
- /**
28
- * Vector codec implementation for pgvector extension.
29
- *
30
- * Provides encoding/decoding for the `vector` PostgreSQL type.
31
- * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
32
- */
33
- const pgVectorCodec = codec({
34
- typeId: "pg/vector@1",
35
- targetTypes: ["vector"],
36
- traits: ["equality"],
37
- renderOutputType: (typeParams) => {
38
- const length = typeParams["length"];
39
- if (length === void 0) return void 0;
40
- if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected positive integer "length" in typeParams for Vector, got ${String(length)}`);
41
- return `Vector<${length}>`;
42
- },
43
- encode: (value) => {
44
- if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
45
- if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
46
- return `[${value.join(",")}]`;
47
- },
48
- decode: (wire) => {
49
- if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
50
- if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
51
- const content = wire.slice(1, -1).trim();
52
- if (content === "") return [];
53
- return content.split(",").map((v) => {
54
- const num = Number.parseFloat(v.trim());
55
- if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
56
- return num;
57
- });
58
- },
59
- meta: { db: { sql: { postgres: { nativeType: "vector" } } } }
60
- });
61
- const codecs = defineCodecs().add("vector", pgVectorCodec);
62
- const codecDefinitions = codecs.codecDefinitions;
63
- const dataTypes = codecs.dataTypes;
64
-
65
- //#endregion
66
- //#region src/core/descriptor-meta.ts
67
- const pgvectorTypeId = "pg/vector@1";
68
- function pgvectorQueryOperations() {
69
- return [{
70
- method: "cosineDistance",
71
- self: { codecId: pgvectorTypeId },
72
- impl: (self, other) => buildOperation({
73
- method: "cosineDistance",
74
- args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
75
- returns: {
76
- codecId: "pg/float8@1",
77
- nullable: false
78
- },
79
- lowering: {
80
- targetFamily: "sql",
81
- strategy: "function",
82
- template: "{{self}} <=> {{arg0}}"
83
- }
84
- })
85
- }, {
86
- method: "cosineSimilarity",
87
- self: { codecId: pgvectorTypeId },
88
- impl: (self, other) => buildOperation({
89
- method: "cosineSimilarity",
90
- args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
91
- returns: {
92
- codecId: "pg/float8@1",
93
- nullable: false
94
- },
95
- lowering: {
96
- targetFamily: "sql",
97
- strategy: "function",
98
- template: "1 - ({{self}} <=> {{arg0}})"
99
- }
100
- })
101
- }];
102
- }
103
- const pgvectorPackMetaBase = {
104
- kind: "extension",
105
- id: "pgvector",
106
- familyId: "sql",
107
- targetId: "postgres",
108
- version: "0.0.1",
109
- capabilities: { postgres: { "pgvector.cosine": true } },
110
- authoring: { type: pgvectorAuthoringTypes },
111
- types: {
112
- codecTypes: {
113
- codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
114
- import: {
115
- package: "@prisma-next/extension-pgvector/codec-types",
116
- named: "CodecTypes",
117
- alias: "PgVectorTypes"
118
- },
119
- typeImports: [{
120
- package: "@prisma-next/extension-pgvector/codec-types",
121
- named: "Vector",
122
- alias: "Vector"
123
- }]
124
- },
125
- operationTypes: { import: {
126
- package: "@prisma-next/extension-pgvector/operation-types",
127
- named: "OperationTypes",
128
- alias: "PgVectorOperationTypes"
129
- } },
130
- queryOperationTypes: { import: {
131
- package: "@prisma-next/extension-pgvector/operation-types",
132
- named: "QueryOperationTypes",
133
- alias: "PgVectorQueryOperationTypes"
134
- } },
135
- storage: [{
136
- typeId: pgvectorTypeId,
137
- familyId: "sql",
138
- targetId: "postgres",
139
- nativeType: "vector"
140
- }]
141
- }
142
- };
143
- const pgvectorPackMeta = pgvectorPackMetaBase;
144
-
145
- //#endregion
146
- export { pgvectorQueryOperations as n, codecDefinitions as r, pgvectorPackMeta as t };
147
- //# sourceMappingURL=descriptor-meta-DTopW_37.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor-meta-DTopW_37.mjs","names":["pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n}"],"sources":["../src/core/authoring.ts","../src/core/codecs.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport { VECTOR_MAX_DIM } from './constants';\n\nexport const pgvectorAuthoringTypes = {\n pgvector: {\n Vector: {\n kind: 'typeConstructor',\n args: [\n { kind: 'number', name: 'length', integer: true, minimum: 1, maximum: VECTOR_MAX_DIM },\n ],\n output: {\n codecId: 'pg/vector@1',\n nativeType: 'vector',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\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 renderOutputType: (typeParams) => {\n const length = typeParams['length'];\n if (length === undefined) return undefined;\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error(\n `renderOutputType: expected positive integer \"length\" in typeParams for Vector, got ${String(length)}`,\n );\n }\n return `Vector<${length}>`;\n },\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 type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport {\n buildOperation,\n type CodecExpression,\n type Expression,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport { pgvectorAuthoringTypes } from './authoring';\nimport { codecDefinitions } from './codecs';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\nexport function pgvectorQueryOperations<\n CT extends CodecTypesBase,\n>(): readonly SqlOperationDescriptor[] {\n return [\n {\n method: 'cosineDistance',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>\n buildOperation({\n method: 'cosineDistance',\n args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n }),\n },\n {\n method: 'cosineSimilarity',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>\n buildOperation({\n method: 'cosineSimilarity',\n args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],\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 ];\n}\n\nconst pgvectorPackMetaBase = {\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 authoring: {\n type: pgvectorAuthoringTypes,\n },\n types: {\n codecTypes: {\n codecInstances: Object.values(codecDefinitions).map((def) => def.codec),\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 },\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\nexport const pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = pgvectorPackMetaBase;\n"],"mappings":"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"}