@prisma-next/extension-pgvector 0.5.0-dev.30 → 0.5.0-dev.41
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 +5 -2
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +13 -6
- package/dist/runtime.mjs.map +1 -1
- package/package.json +14 -14
- package/src/exports/runtime.ts +21 -0
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
|
-
|
|
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:
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;cA6DM,2BAA2B"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -4,14 +4,21 @@ import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
|
|
|
4
4
|
import { type } from "arktype";
|
|
5
5
|
|
|
6
6
|
//#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;
|
|
7
15
|
const parameterizedCodecDescriptors = [{
|
|
8
16
|
codecId: VECTOR_CODEC_ID,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
17
|
+
traits: ["equality"],
|
|
18
|
+
targetTypes: ["vector"],
|
|
19
|
+
paramsSchema: vectorParamsSchema,
|
|
20
|
+
renderOutputType: (params) => `Vector<${params.length}>`,
|
|
21
|
+
factory: vectorFactory
|
|
15
22
|
}];
|
|
16
23
|
function createPgvectorCodecRegistry() {
|
|
17
24
|
const registry = createCodecRegistry();
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -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 // 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":";;;;;;
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
|
-
"@prisma-next/
|
|
9
|
-
"@prisma-next/contract-authoring": "0.5.0-dev.
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/sql-
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/sql-schema-ir": "0.5.0-dev.
|
|
8
|
+
"@prisma-next/family-sql": "0.5.0-dev.41",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.5.0-dev.41",
|
|
10
|
+
"@prisma-next/sql-operations": "0.5.0-dev.41",
|
|
11
|
+
"@prisma-next/sql-relational-core": "0.5.0-dev.41",
|
|
12
|
+
"@prisma-next/contract": "0.5.0-dev.41",
|
|
13
|
+
"@prisma-next/sql-runtime": "0.5.0-dev.41",
|
|
14
|
+
"@prisma-next/framework-components": "0.5.0-dev.41",
|
|
15
|
+
"@prisma-next/sql-schema-ir": "0.5.0-dev.41"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tsdown": "0.18.4",
|
|
19
19
|
"typescript": "5.9.3",
|
|
20
20
|
"vitest": "4.0.17",
|
|
21
|
-
"@prisma-next/
|
|
22
|
-
"@prisma-next/
|
|
23
|
-
"@prisma-next/
|
|
24
|
-
"@prisma-next/
|
|
21
|
+
"@prisma-next/operations": "0.5.0-dev.41",
|
|
22
|
+
"@prisma-next/sql-contract": "0.5.0-dev.41",
|
|
23
|
+
"@prisma-next/sql-contract-ts": "0.5.0-dev.41",
|
|
24
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
25
25
|
"@prisma-next/tsdown": "0.0.0",
|
|
26
|
-
"@prisma-next/
|
|
26
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
package/src/exports/runtime.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Codec, CodecInstanceContext } from '@prisma-next/framework-components/codec';
|
|
1
2
|
import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
2
3
|
import type {
|
|
3
4
|
RuntimeParameterizedCodecDescriptor,
|
|
@@ -21,10 +22,30 @@ const vectorParamsSchema = arktype({
|
|
|
21
22
|
return true;
|
|
22
23
|
});
|
|
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
|
+
|
|
24
41
|
const parameterizedCodecDescriptors = [
|
|
25
42
|
{
|
|
26
43
|
codecId: VECTOR_CODEC_ID,
|
|
44
|
+
traits: ['equality'] as const,
|
|
45
|
+
targetTypes: ['vector'] as const,
|
|
27
46
|
paramsSchema: vectorParamsSchema,
|
|
47
|
+
renderOutputType: (params: { readonly length: number }) => `Vector<${params.length}>`,
|
|
48
|
+
factory: vectorFactory,
|
|
28
49
|
},
|
|
29
50
|
] as const satisfies ReadonlyArray<
|
|
30
51
|
RuntimeParameterizedCodecDescriptor<{ readonly length: number }>
|