@prisma-next/extension-pgvector 0.5.0-dev.6 → 0.5.0-dev.61

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.
package/README.md CHANGED
@@ -69,7 +69,7 @@ Add vector columns to your contract and enable the namespace via pack refs:
69
69
  import { int4Column, textColumn } from '@prisma-next/adapter-postgres/column-types';
70
70
  import sqlFamily from '@prisma-next/family-sql/pack';
71
71
  import { defineContract, field, model } from '@prisma-next/sql-contract-ts/contract-builder';
72
- import { vectorColumn } from '@prisma-next/extension-pgvector/column-types';
72
+ import { vector, vectorColumn } from '@prisma-next/extension-pgvector/column-types';
73
73
  import pgvector from '@prisma-next/extension-pgvector/pack';
74
74
  import postgres from '@prisma-next/target-postgres/pack';
75
75
 
@@ -82,13 +82,16 @@ export const contract = defineContract({
82
82
  fields: {
83
83
  id: field.column(int4Column).id(),
84
84
  title: field.column(textColumn),
85
- embedding: field.column(vectorColumn).optional(),
85
+ // Dimensioned vector — `field.embedding` resolves to `Vector<1536>`.
86
+ embedding: field.column(vector(1536)).optional(),
86
87
  },
87
88
  }).sql({ table: 'post' }),
88
89
  },
89
90
  });
90
91
  ```
91
92
 
93
+ The `vector(N)` factory is registered through the unified `CodecDescriptor<{ length: number }>` shape — `paramsSchema` validates the dimension at the contract boundary, `renderOutputType: ({ length }) => 'Vector<' + length + '>'` produces the column's TS type for `contract.d.ts`, and the curried `factory` materializes the runtime codec at context construction. See [ADR 208 — Higher-order codecs for parameterized types](../../../docs/architecture%20docs/adrs/ADR%20208%20-%20Higher-order%20codecs%20for%20parameterized%20types.md) for the descriptor model. For undimensioned vector columns (rare; typically only valid in legacy schemas where `vector` was declared without a dimension), use `vectorColumn` instead.
94
+
92
95
  ### Runtime Setup
93
96
 
94
97
  Register the extension when creating your execution stack:
@@ -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-BQbvJJxu.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";
@@ -47,7 +47,7 @@ const pgvectorExtensionDescriptor = {
47
47
  controlPlaneHooks: { [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks }
48
48
  }
49
49
  },
50
- queryOperations: () => pgvectorQueryOperations,
50
+ queryOperations: () => pgvectorQueryOperations(),
51
51
  databaseDependencies: pgvectorDatabaseDependencies,
52
52
  create: () => ({
53
53
  familyId: "sql",
@@ -1 +1 @@
1
- {"version":3,"file":"control.mjs","names":["vectorControlPlaneHooks: CodecControlHooks","pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown>","pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'>"],"sources":["../src/exports/control.ts"],"sourcesContent":["import type {\n CodecControlHooks,\n ComponentDatabaseDependencies,\n SqlControlExtensionDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';\n\nconst PGVECTOR_CODEC_ID = 'pg/vector@1' as const;\n\nfunction buildVectorIdentityValue(typeParams: Record<string, unknown> | undefined): string | null {\n const length = typeParams?.['length'];\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n\n const zeroVector = `[${new Array(length).fill('0').join(',')}]`;\n return `'${zeroVector}'::vector`;\n}\n\nconst vectorControlPlaneHooks: CodecControlHooks = {\n expandNativeType: ({ nativeType, typeParams }) => {\n const length = typeParams?.['length'];\n if (typeof length === 'number' && Number.isInteger(length) && length > 0) {\n return `${nativeType}(${length})`;\n }\n return nativeType;\n },\n resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams),\n};\n\nconst pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {\n init: [\n {\n id: 'postgres.extension.vector',\n label: 'Enable vector extension',\n install: [\n {\n id: 'extension.vector',\n label: 'Enable extension \"vector\"',\n summary: 'Ensures the vector extension is available for pgvector operations',\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: 'verify extension \"vector\" is not already enabled',\n sql: \"SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n execute: [\n {\n description: 'create extension \"vector\"',\n sql: 'CREATE EXTENSION IF NOT EXISTS vector',\n },\n ],\n postcheck: [\n {\n description: 'confirm extension \"vector\" is enabled',\n sql: \"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n },\n ],\n },\n ],\n};\n\nconst pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {\n ...pgvectorPackMeta,\n types: {\n ...pgvectorPackMeta.types,\n codecTypes: {\n ...pgvectorPackMeta.types.codecTypes,\n controlPlaneHooks: {\n [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks,\n },\n },\n },\n queryOperations: () => pgvectorQueryOperations,\n databaseDependencies: pgvectorDatabaseDependencies,\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n};\n\nexport { pgvectorExtensionDescriptor };\nexport default pgvectorExtensionDescriptor;\n"],"mappings":";;;AAOA,MAAM,oBAAoB;AAE1B,SAAS,yBAAyB,YAAgE;CAChG,MAAM,SAAS,aAAa;AAC5B,KAAI,OAAO,WAAW,YAAY,CAAC,OAAO,UAAU,OAAO,IAAI,UAAU,EACvE,QAAO;AAIT,QAAO,IADY,IAAI,IAAI,MAAM,OAAO,CAAC,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC,GACvC;;AAGxB,MAAMA,0BAA6C;CACjD,mBAAmB,EAAE,YAAY,iBAAiB;EAChD,MAAM,SAAS,aAAa;AAC5B,MAAI,OAAO,WAAW,YAAY,OAAO,UAAU,OAAO,IAAI,SAAS,EACrE,QAAO,GAAG,WAAW,GAAG,OAAO;AAEjC,SAAO;;CAET,uBAAuB,EAAE,iBAAiB,yBAAyB,WAAW;CAC/E;AAED,MAAMC,+BAAuE,EAC3E,MAAM,CACJ;CACE,IAAI;CACJ,OAAO;CACP,SAAS,CACP;EACE,IAAI;EACJ,OAAO;EACP,SAAS;EACT,gBAAgB;EAChB,QAAQ,EAAE,IAAI,YAAY;EAC1B,UAAU,CACR;GACE,aAAa;GACb,KAAK;GACN,CACF;EACD,SAAS,CACP;GACE,aAAa;GACb,KAAK;GACN,CACF;EACD,WAAW,CACT;GACE,aAAa;GACb,KAAK;GACN,CACF;EACF,CACF;CACF,CACF,EACF;AAED,MAAMC,8BAAyE;CAC7E,GAAG;CACH,OAAO;EACL,GAAG,iBAAiB;EACpB,YAAY;GACV,GAAG,iBAAiB,MAAM;GAC1B,mBAAmB,GAChB,oBAAoB,yBACtB;GACF;EACF;CACD,uBAAuB;CACvB,sBAAsB;CACtB,eAAe;EACb,UAAU;EACV,UAAU;EACX;CACF;AAGD,sBAAe"}
1
+ {"version":3,"file":"control.mjs","names":["vectorControlPlaneHooks: CodecControlHooks","pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown>","pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'>"],"sources":["../src/exports/control.ts"],"sourcesContent":["import type {\n CodecControlHooks,\n ComponentDatabaseDependencies,\n SqlControlExtensionDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';\n\nconst PGVECTOR_CODEC_ID = 'pg/vector@1' as const;\n\nfunction buildVectorIdentityValue(typeParams: Record<string, unknown> | undefined): string | null {\n const length = typeParams?.['length'];\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n\n const zeroVector = `[${new Array(length).fill('0').join(',')}]`;\n return `'${zeroVector}'::vector`;\n}\n\nconst vectorControlPlaneHooks: CodecControlHooks = {\n expandNativeType: ({ nativeType, typeParams }) => {\n const length = typeParams?.['length'];\n if (typeof length === 'number' && Number.isInteger(length) && length > 0) {\n return `${nativeType}(${length})`;\n }\n return nativeType;\n },\n resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams),\n};\n\nconst pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {\n init: [\n {\n id: 'postgres.extension.vector',\n label: 'Enable vector extension',\n install: [\n {\n id: 'extension.vector',\n label: 'Enable extension \"vector\"',\n summary: 'Ensures the vector extension is available for pgvector operations',\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: 'verify extension \"vector\" is not already enabled',\n sql: \"SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n execute: [\n {\n description: 'create extension \"vector\"',\n sql: 'CREATE EXTENSION IF NOT EXISTS vector',\n },\n ],\n postcheck: [\n {\n description: 'confirm extension \"vector\" is enabled',\n sql: \"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n },\n ],\n },\n ],\n};\n\nconst pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {\n ...pgvectorPackMeta,\n types: {\n ...pgvectorPackMeta.types,\n codecTypes: {\n ...pgvectorPackMeta.types.codecTypes,\n controlPlaneHooks: {\n [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks,\n },\n },\n },\n queryOperations: () => pgvectorQueryOperations(),\n databaseDependencies: pgvectorDatabaseDependencies,\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n};\n\nexport { pgvectorExtensionDescriptor };\nexport default pgvectorExtensionDescriptor;\n"],"mappings":";;;AAOA,MAAM,oBAAoB;AAE1B,SAAS,yBAAyB,YAAgE;CAChG,MAAM,SAAS,aAAa;AAC5B,KAAI,OAAO,WAAW,YAAY,CAAC,OAAO,UAAU,OAAO,IAAI,UAAU,EACvE,QAAO;AAIT,QAAO,IADY,IAAI,IAAI,MAAM,OAAO,CAAC,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC,GACvC;;AAGxB,MAAMA,0BAA6C;CACjD,mBAAmB,EAAE,YAAY,iBAAiB;EAChD,MAAM,SAAS,aAAa;AAC5B,MAAI,OAAO,WAAW,YAAY,OAAO,UAAU,OAAO,IAAI,SAAS,EACrE,QAAO,GAAG,WAAW,GAAG,OAAO;AAEjC,SAAO;;CAET,uBAAuB,EAAE,iBAAiB,yBAAyB,WAAW;CAC/E;AAED,MAAMC,+BAAuE,EAC3E,MAAM,CACJ;CACE,IAAI;CACJ,OAAO;CACP,SAAS,CACP;EACE,IAAI;EACJ,OAAO;EACP,SAAS;EACT,gBAAgB;EAChB,QAAQ,EAAE,IAAI,YAAY;EAC1B,UAAU,CACR;GACE,aAAa;GACb,KAAK;GACN,CACF;EACD,SAAS,CACP;GACE,aAAa;GACb,KAAK;GACN,CACF;EACD,WAAW,CACT;GACE,aAAa;GACb,KAAK;GACN,CACF;EACF,CACF;CACF,CACF,EACF;AAED,MAAMC,8BAAyE;CAC7E,GAAG;CACH,OAAO;EACL,GAAG,iBAAiB;EACpB,YAAY;GACV,GAAG,iBAAiB,MAAM;GAC1B,mBAAmB,GAChB,oBAAoB,yBACtB;GACF;EACF;CACD,uBAAuB,yBAAyB;CAChD,sBAAsB;CACtB,eAAe;EACb,UAAU;EACV,UAAU;EACX;CACF;AAGD,sBAAe"}
@@ -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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"}
@@ -1,7 +1,11 @@
1
+ import { CodecExpression, Expression } from "@prisma-next/sql-relational-core/expression";
1
2
  import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
2
3
 
3
4
  //#region src/types/operation-types.d.ts
4
-
5
+ type CodecTypesBase = Record<string, {
6
+ readonly input: unknown;
7
+ readonly output: unknown;
8
+ }>;
5
9
  /**
6
10
  * Operation type definitions for pgvector extension.
7
11
  *
@@ -11,64 +15,36 @@ import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
11
15
  type OperationTypes = {
12
16
  readonly 'pg/vector@1': {
13
17
  readonly cosineDistance: {
14
- readonly args: readonly [{
18
+ readonly self: {
15
19
  readonly codecId: 'pg/vector@1';
16
- readonly nullable: false;
17
- }];
18
- readonly returns: {
19
- readonly codecId: 'pg/float8@1';
20
- readonly nullable: false;
21
- };
22
- readonly lowering: {
23
- readonly targetFamily: 'sql';
24
- readonly strategy: 'function';
25
- readonly template: string;
26
20
  };
27
21
  };
28
22
  readonly cosineSimilarity: {
29
- readonly args: readonly [{
23
+ readonly self: {
30
24
  readonly codecId: 'pg/vector@1';
31
- readonly nullable: false;
32
- }];
33
- readonly returns: {
34
- readonly codecId: 'pg/float8@1';
35
- readonly nullable: false;
36
- };
37
- readonly lowering: {
38
- readonly targetFamily: 'sql';
39
- readonly strategy: 'function';
40
- readonly template: string;
41
25
  };
42
26
  };
43
27
  };
44
28
  };
45
29
  /** Flat operation signatures for the query builder. */
46
- type QueryOperationTypes = SqlQueryOperationTypes<{
30
+ type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<CT, {
47
31
  readonly cosineDistance: {
48
- readonly args: readonly [{
49
- readonly codecId: 'pg/vector@1';
50
- readonly nullable: boolean;
51
- }, {
32
+ readonly self: {
52
33
  readonly codecId: 'pg/vector@1';
53
- readonly nullable: boolean;
54
- }];
55
- readonly returns: {
56
- readonly codecId: 'pg/float8@1';
57
- readonly nullable: false;
58
34
  };
35
+ readonly impl: (self: CodecExpression<'pg/vector@1', boolean, CT>, other: CodecExpression<'pg/vector@1', boolean, CT>) => Expression<{
36
+ codecId: 'pg/float8@1';
37
+ nullable: false;
38
+ }>;
59
39
  };
60
40
  readonly cosineSimilarity: {
61
- readonly args: readonly [{
62
- readonly codecId: 'pg/vector@1';
63
- readonly nullable: boolean;
64
- }, {
41
+ readonly self: {
65
42
  readonly codecId: 'pg/vector@1';
66
- readonly nullable: boolean;
67
- }];
68
- readonly returns: {
69
- readonly codecId: 'pg/float8@1';
70
- readonly nullable: false;
71
43
  };
44
+ readonly impl: (self: CodecExpression<'pg/vector@1', boolean, CT>, other: CodecExpression<'pg/vector@1', boolean, CT>) => Expression<{
45
+ codecId: 'pg/float8@1';
46
+ nullable: false;
47
+ }>;
72
48
  };
73
49
  }>;
74
50
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;AAwBA;;;KAxBY,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwBA,mBAAA,GAAsB"}
1
+ {"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"sourcesContent":[],"mappings":";;;;KAGK,cAAA,GAAiB;;EAAjB,SAAA,MAAA,EAAc,OAAA;AASnB,CAAA,CAAA;AAYA;;;;;;AAOe,KAnBH,cAAA,GAmBG;EACJ,SAAA,aAAA,EAAA;IAK2C,SAAA,cAAA,EAAA;MAAxC,SAAA,IAAA,EAAA;QACyC,SAAA,OAAA,EAAA,aAAA;MAAxC,CAAA;IACJ,CAAA;IAfkD,SAAA,gBAAA,EAAA;MAAsB,SAAA,IAAA,EAAA;;;;;;;KAAvE,+BAA+B,kBAAkB,uBAC3D;;;;;0BAKY,wCAAwC,YACvC,wCAAwC,QAC5C;;;;;;;;;0BAKG,wCAAwC,YACvC,wCAAwC,QAC5C"}
package/dist/pack.d.mts CHANGED
@@ -1,7 +1,8 @@
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
6
  declare const pgvectorPackMetaBase: {
6
7
  readonly kind: "extension";
7
8
  readonly id: "pgvector";
@@ -41,7 +42,7 @@ declare const pgvectorPackMetaBase: {
41
42
  };
42
43
  readonly types: {
43
44
  readonly codecTypes: {
44
- 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>[];
45
46
  readonly import: {
46
47
  readonly package: "@prisma-next/extension-pgvector/codec-types";
47
48
  readonly named: "CodecTypes";
@@ -1 +1 @@
1
- {"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":";;;;cAoCM;EAAA,SAAA,IAAA,EAAA,WAgDI;EAEG,SAAA,EAAA,EAAA,UAEW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAJd,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-BQbvJJxu.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":";;;cAwCM,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,32 +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-BQbvJJxu.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 parameterizedCodecDescriptors = [{
8
- codecId: VECTOR_CODEC_ID,
9
- paramsSchema: type({ length: "number" }).narrow((params, ctx) => {
10
- const { length } = params;
11
- if (!Number.isInteger(length)) return ctx.mustBe("an integer");
12
- if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
13
- return true;
14
- })
15
- }];
16
- function createPgvectorCodecRegistry() {
17
- const registry = createCodecRegistry();
18
- for (const def of Object.values(codecDefinitions)) registry.register(def.codec);
19
- return registry;
20
- }
21
4
  const pgvectorRuntimeDescriptor = {
22
5
  kind: "extension",
23
6
  id: pgvectorPackMeta.id,
24
7
  version: pgvectorPackMeta.version,
25
8
  familyId: "sql",
26
9
  targetId: "postgres",
27
- codecs: createPgvectorCodecRegistry,
28
- queryOperations: () => pgvectorQueryOperations,
29
- parameterizedCodecs: () => parameterizedCodecDescriptors,
10
+ types: { codecTypes: { codecDescriptors: Array.from(pgvectorCodecRegistry.values()) } },
11
+ codecs: () => Array.from(pgvectorCodecRegistry.values()),
12
+ queryOperations: () => pgvectorQueryOperations(),
30
13
  create() {
31
14
  return {
32
15
  familyId: "sql",
@@ -37,5 +20,5 @@ const pgvectorRuntimeDescriptor = {
37
20
  var runtime_default = pgvectorRuntimeDescriptor;
38
21
 
39
22
  //#endregion
40
- export { runtime_default as default };
23
+ export { runtime_default as default, pgvectorCodecRegistry };
41
24
  //# sourceMappingURL=runtime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":["arktype","pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>"],"sources":["../src/exports/runtime.ts"],"sourcesContent":["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 { 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\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 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":";;;;;;AAuBA,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,uBAAuB;CACvB,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"}