@prisma-next/extension-pgvector 0.3.0-dev.11 → 0.3.0-dev.114
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/LICENSE +201 -0
- package/README.md +19 -16
- package/dist/codec-types-BcHC4dXB.d.mts +41 -0
- package/dist/codec-types-BcHC4dXB.d.mts.map +1 -0
- package/dist/codec-types.d.mts +2 -0
- package/dist/codec-types.mjs +1 -0
- package/dist/column-types.d.mts +33 -0
- package/dist/column-types.d.mts.map +1 -0
- package/dist/column-types.mjs +36 -0
- package/dist/column-types.mjs.map +1 -0
- package/dist/constants-BmZpaev5.mjs +13 -0
- package/dist/constants-BmZpaev5.mjs.map +1 -0
- package/dist/control.d.mts +7 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +61 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-DKfA8aF2.mjs +81 -0
- package/dist/descriptor-meta-DKfA8aF2.mjs.map +1 -0
- package/dist/operation-types.d.mts +51 -0
- package/dist/operation-types.d.mts.map +1 -0
- package/dist/operation-types.mjs +1 -0
- package/dist/pack.d.mts +10 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +9 -0
- package/dist/pack.mjs.map +1 -0
- package/dist/runtime.d.mts +7 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +76 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +37 -49
- package/src/core/codecs.ts +2 -1
- package/src/core/constants.ts +9 -0
- package/src/core/descriptor-meta.ts +40 -17
- package/src/exports/codec-types.ts +1 -1
- package/src/exports/column-types.ts +34 -1
- package/src/exports/control.ts +32 -26
- package/src/exports/operation-types.ts +1 -1
- package/src/exports/pack.ts +5 -1
- package/src/exports/runtime.ts +42 -27
- package/src/types/codec-types.ts +23 -1
- package/src/types/operation-types.ts +13 -0
- package/dist/chunk-SHWLERB3.js +0 -60
- package/dist/chunk-SHWLERB3.js.map +0 -1
- package/dist/core/codecs.d.ts +0 -23
- package/dist/core/codecs.d.ts.map +0 -1
- package/dist/core/descriptor-meta.d.ts +0 -53
- package/dist/core/descriptor-meta.d.ts.map +0 -1
- package/dist/exports/codec-types.d.ts +0 -7
- package/dist/exports/codec-types.d.ts.map +0 -1
- package/dist/exports/codec-types.js +0 -1
- package/dist/exports/codec-types.js.map +0 -1
- package/dist/exports/column-types.d.ts +0 -11
- package/dist/exports/column-types.d.ts.map +0 -1
- package/dist/exports/column-types.js +0 -9
- package/dist/exports/column-types.js.map +0 -1
- package/dist/exports/control.d.ts +0 -9
- package/dist/exports/control.d.ts.map +0 -1
- package/dist/exports/control.js +0 -67
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/operation-types.d.ts +0 -7
- package/dist/exports/operation-types.d.ts.map +0 -1
- package/dist/exports/operation-types.js +0 -1
- package/dist/exports/operation-types.js.map +0 -1
- package/dist/exports/pack.d.ts +0 -52
- package/dist/exports/pack.d.ts.map +0 -1
- package/dist/exports/pack.js +0 -11
- package/dist/exports/pack.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -8
- package/dist/exports/runtime.d.ts.map +0 -1
- package/dist/exports/runtime.js +0 -86
- package/dist/exports/runtime.js.map +0 -1
- package/dist/types/codec-types.d.ts +0 -10
- package/dist/types/codec-types.d.ts.map +0 -1
- package/dist/types/operation-types.d.ts +0 -31
- package/dist/types/operation-types.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;AAsBA;;;;;;;KAtBY,cAAA;;;;;;;;;;;;;;;;;;;KAsBA,mBAAA,GAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/pack.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as CodecTypes } from "./codec-types-BcHC4dXB.mjs";
|
|
2
|
+
import { ExtensionPackRef } from "@prisma-next/contract/framework-components";
|
|
3
|
+
|
|
4
|
+
//#region src/exports/pack.d.ts
|
|
5
|
+
declare const _default: ExtensionPackRef<"sql", "postgres"> & {
|
|
6
|
+
readonly __codecTypes?: CodecTypes;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { _default as default };
|
|
10
|
+
//# sourceMappingURL=pack.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":[],"mappings":";;;;cAEuD,UAIxB;0BACL;AAL6B,CAAA"}
|
package/dist/pack.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { n as pgvectorPackMeta } from "./descriptor-meta-DKfA8aF2.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/pack.ts
|
|
4
|
+
const pgvectorPack = pgvectorPackMeta;
|
|
5
|
+
var pack_default = pgvectorPack;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { pack_default as default };
|
|
9
|
+
//# sourceMappingURL=pack.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.mjs","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":["import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';\nimport { pgvectorPackMeta } from '../core/descriptor-meta';\nimport type { CodecTypes } from '../types/codec-types';\n\nconst pgvectorPack = pgvectorPackMeta;\n\nexport default pgvectorPack as ExtensionPackRef<'sql', 'postgres'> & {\n readonly __codecTypes?: CodecTypes;\n};\n"],"mappings":";;;AAIA,MAAM,eAAe;AAErB,mBAAe"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SqlRuntimeExtensionDescriptor } from "@prisma-next/sql-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/runtime.d.ts
|
|
4
|
+
declare const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { pgvectorRuntimeDescriptor as default };
|
|
7
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;cA4CM,2BAA2B"}
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { n as pgvectorPackMeta, r as pgvectorQueryOperations, t as pgvectorOperationSignature } from "./descriptor-meta-DKfA8aF2.mjs";
|
|
2
|
+
import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-BmZpaev5.mjs";
|
|
3
|
+
import { codec, createCodecRegistry, defineCodecs } from "@prisma-next/sql-relational-core/ast";
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
|
|
6
|
+
//#region src/core/codecs.ts
|
|
7
|
+
/**
|
|
8
|
+
* Vector codec implementation for pgvector extension.
|
|
9
|
+
*
|
|
10
|
+
* Provides encoding/decoding for the `vector` PostgreSQL type.
|
|
11
|
+
* Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
|
|
12
|
+
*/
|
|
13
|
+
const pgVectorCodec = codec({
|
|
14
|
+
typeId: "pg/vector@1",
|
|
15
|
+
targetTypes: ["vector"],
|
|
16
|
+
traits: ["equality"],
|
|
17
|
+
encode: (value) => {
|
|
18
|
+
if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
|
|
19
|
+
if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
|
|
20
|
+
return `[${value.join(",")}]`;
|
|
21
|
+
},
|
|
22
|
+
decode: (wire) => {
|
|
23
|
+
if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
|
|
24
|
+
if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
|
|
25
|
+
const content = wire.slice(1, -1).trim();
|
|
26
|
+
if (content === "") return [];
|
|
27
|
+
return content.split(",").map((v) => {
|
|
28
|
+
const num = Number.parseFloat(v.trim());
|
|
29
|
+
if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
|
|
30
|
+
return num;
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
meta: { db: { sql: { postgres: { nativeType: "vector" } } } }
|
|
34
|
+
});
|
|
35
|
+
const codecs = defineCodecs().add("vector", pgVectorCodec);
|
|
36
|
+
const codecDefinitions = codecs.codecDefinitions;
|
|
37
|
+
const dataTypes = codecs.dataTypes;
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/exports/runtime.ts
|
|
41
|
+
const parameterizedCodecDescriptors = [{
|
|
42
|
+
codecId: VECTOR_CODEC_ID,
|
|
43
|
+
paramsSchema: type({ length: "number" }).narrow((params, ctx) => {
|
|
44
|
+
const { length } = params;
|
|
45
|
+
if (!Number.isInteger(length)) return ctx.mustBe("an integer");
|
|
46
|
+
if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
|
|
47
|
+
return true;
|
|
48
|
+
})
|
|
49
|
+
}];
|
|
50
|
+
function createPgvectorCodecRegistry() {
|
|
51
|
+
const registry = createCodecRegistry();
|
|
52
|
+
for (const def of Object.values(codecDefinitions)) registry.register(def.codec);
|
|
53
|
+
return registry;
|
|
54
|
+
}
|
|
55
|
+
const pgvectorRuntimeDescriptor = {
|
|
56
|
+
kind: "extension",
|
|
57
|
+
id: pgvectorPackMeta.id,
|
|
58
|
+
version: pgvectorPackMeta.version,
|
|
59
|
+
familyId: "sql",
|
|
60
|
+
targetId: "postgres",
|
|
61
|
+
codecs: createPgvectorCodecRegistry,
|
|
62
|
+
operationSignatures: () => [pgvectorOperationSignature],
|
|
63
|
+
queryOperations: () => pgvectorQueryOperations,
|
|
64
|
+
parameterizedCodecs: () => parameterizedCodecDescriptors,
|
|
65
|
+
create() {
|
|
66
|
+
return {
|
|
67
|
+
familyId: "sql",
|
|
68
|
+
targetId: "postgres"
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var runtime_default = pgvectorRuntimeDescriptor;
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { runtime_default as default };
|
|
76
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["arktype","pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>"],"sources":["../src/core/codecs.ts","../src/exports/runtime.ts"],"sourcesContent":["/**\n * Vector codec implementation for pgvector extension.\n *\n * Provides encoding/decoding for the `vector` PostgreSQL type.\n * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).\n */\n\nimport { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';\n\nconst pgVectorCodec = codec({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\n traits: ['equality'],\n encode: (value: number[]): string => {\n // Validate that value is an array of numbers\n if (!Array.isArray(value)) {\n throw new Error('Vector value must be an array of numbers');\n }\n if (!value.every((v) => typeof v === 'number')) {\n throw new Error('Vector value must contain only numbers');\n }\n // Format as PostgreSQL vector text format: [1,2,3]\n // PostgreSQL's pg library requires the vector format string\n return `[${value.join(',')}]`;\n },\n decode: (wire: string): number[] => {\n // Handle string format from PostgreSQL: [1,2,3]\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n // Parse PostgreSQL vector format: [1,2,3]\n if (!wire.startsWith('[') || !wire.endsWith(']')) {\n throw new Error(`Invalid vector format: expected \"[...]\", got \"${wire}\"`);\n }\n const content = wire.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n const values = content.split(',').map((v) => {\n const num = Number.parseFloat(v.trim());\n if (Number.isNaN(num)) {\n throw new Error(`Invalid vector value: \"${v}\" is not a number`);\n }\n return num;\n });\n return values;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'vector',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs().add('vector', pgVectorCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\n// Export types derived from codecs builder\nexport type CodecTypes = typeof codecs.CodecTypes;\n","import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeExtensionDescriptor,\n} from '@prisma-next/sql-runtime';\nimport { type as arktype } from 'arktype';\nimport { codecDefinitions } from '../core/codecs';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';\nimport {\n pgvectorOperationSignature,\n pgvectorPackMeta,\n pgvectorQueryOperations,\n} from '../core/descriptor-meta';\n\nconst vectorParamsSchema = arktype({\n length: 'number',\n}).narrow((params, ctx) => {\n const { length } = params;\n if (!Number.isInteger(length)) {\n return ctx.mustBe('an integer');\n }\n if (length < 1 || length > VECTOR_MAX_DIM) {\n return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);\n }\n return true;\n});\n\nconst parameterizedCodecDescriptors = [\n {\n codecId: VECTOR_CODEC_ID,\n paramsSchema: vectorParamsSchema,\n },\n] as const satisfies ReadonlyArray<\n RuntimeParameterizedCodecDescriptor<{ readonly length: number }>\n>;\n\nfunction createPgvectorCodecRegistry() {\n const registry = createCodecRegistry();\n for (const def of Object.values(codecDefinitions)) {\n registry.register(def.codec);\n }\n return registry;\n}\n\nconst pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: pgvectorPackMeta.id,\n version: pgvectorPackMeta.version,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n codecs: createPgvectorCodecRegistry,\n operationSignatures: () => [pgvectorOperationSignature],\n queryOperations: () => pgvectorQueryOperations,\n parameterizedCodecs: () => parameterizedCodecDescriptors,\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n\nexport default pgvectorRuntimeDescriptor;\n"],"mappings":";;;;;;;;;;;;AASA,MAAM,gBAAgB,MAAM;CAC1B,QAAQ;CACR,aAAa,CAAC,SAAS;CACvB,QAAQ,CAAC,WAAW;CACpB,SAAS,UAA4B;AAEnC,MAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,OAAM,IAAI,MAAM,2CAA2C;AAE7D,MAAI,CAAC,MAAM,OAAO,MAAM,OAAO,MAAM,SAAS,CAC5C,OAAM,IAAI,MAAM,yCAAyC;AAI3D,SAAO,IAAI,MAAM,KAAK,IAAI,CAAC;;CAE7B,SAAS,SAA2B;AAElC,MAAI,OAAO,SAAS,SAClB,OAAM,IAAI,MAAM,qCAAqC;AAGvD,MAAI,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAC9C,OAAM,IAAI,MAAM,iDAAiD,KAAK,GAAG;EAE3E,MAAM,UAAU,KAAK,MAAM,GAAG,GAAG,CAAC,MAAM;AACxC,MAAI,YAAY,GACd,QAAO,EAAE;AASX,SAPe,QAAQ,MAAM,IAAI,CAAC,KAAK,MAAM;GAC3C,MAAM,MAAM,OAAO,WAAW,EAAE,MAAM,CAAC;AACvC,OAAI,OAAO,MAAM,IAAI,CACnB,OAAM,IAAI,MAAM,0BAA0B,EAAE,mBAAmB;AAEjE,UAAO;IACP;;CAGJ,MAAM,EACJ,IAAI,EACF,KAAK,EACH,UAAU,EACR,YAAY,UACb,EACF,EACF,EACF;CACF,CAAC;AAGF,MAAM,SAAS,cAAc,CAAC,IAAI,UAAU,cAAc;AAG1D,MAAa,mBAAmB,OAAO;AACvC,MAAa,YAAY,OAAO;;;;ACpChC,MAAM,gCAAgC,CACpC;CACE,SAAS;CACT,cAhBuBA,KAAQ,EACjC,QAAQ,UACT,CAAC,CAAC,QAAQ,QAAQ,QAAQ;EACzB,MAAM,EAAE,WAAW;AACnB,MAAI,CAAC,OAAO,UAAU,OAAO,CAC3B,QAAO,IAAI,OAAO,aAAa;AAEjC,MAAI,SAAS,KAAK,SAAS,eACzB,QAAO,IAAI,OAAO,oBAAoB,eAAe,GAAG;AAE1D,SAAO;GACP;CAMC,CACF;AAID,SAAS,8BAA8B;CACrC,MAAM,WAAW,qBAAqB;AACtC,MAAK,MAAM,OAAO,OAAO,OAAO,iBAAiB,CAC/C,UAAS,SAAS,IAAI,MAAM;AAE9B,QAAO;;AAGT,MAAMC,4BAAuE;CAC3E,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,UAAU;CACV,UAAU;CACV,QAAQ;CACR,2BAA2B,CAAC,2BAA2B;CACvD,uBAAuB;CACvB,2BAA2B;CAC3B,SAAS;AACP,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ;AAED,sBAAe"}
|
package/package.json
CHANGED
|
@@ -1,71 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.114",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
|
-
"@prisma-next/cli": "0.3.0-dev.
|
|
9
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
10
|
-
"@prisma-next/contract
|
|
11
|
-
"@prisma-next/core-control-plane": "0.3.0-dev.
|
|
12
|
-
"@prisma-next/sql
|
|
13
|
-
"@prisma-next/sql-
|
|
14
|
-
"@prisma-next/sql-
|
|
15
|
-
"@prisma-next/sql-
|
|
16
|
-
"@prisma-next/
|
|
8
|
+
"@prisma-next/cli": "0.3.0-dev.114",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.3.0-dev.114",
|
|
10
|
+
"@prisma-next/contract": "0.3.0-dev.114",
|
|
11
|
+
"@prisma-next/core-control-plane": "0.3.0-dev.114",
|
|
12
|
+
"@prisma-next/family-sql": "0.3.0-dev.114",
|
|
13
|
+
"@prisma-next/sql-operations": "0.3.0-dev.114",
|
|
14
|
+
"@prisma-next/sql-schema-ir": "0.3.0-dev.114",
|
|
15
|
+
"@prisma-next/sql-relational-core": "0.3.0-dev.114",
|
|
16
|
+
"@prisma-next/sql-runtime": "0.3.0-dev.114"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"
|
|
20
|
-
"tsup": "8.5.1",
|
|
19
|
+
"tsdown": "0.18.4",
|
|
21
20
|
"typescript": "5.9.3",
|
|
22
|
-
"vitest": "4.0.
|
|
23
|
-
"@prisma-next/
|
|
24
|
-
"@prisma-next/
|
|
25
|
-
"@prisma-next/sql-contract": "0.3.0-dev.
|
|
26
|
-
"@prisma-next/
|
|
27
|
-
"@prisma-next/sql-lane": "0.3.0-dev.
|
|
28
|
-
"@prisma-next/test-utils": "0.0.1"
|
|
21
|
+
"vitest": "4.0.17",
|
|
22
|
+
"@prisma-next/operations": "0.3.0-dev.114",
|
|
23
|
+
"@prisma-next/sql-contract": "0.3.0-dev.114",
|
|
24
|
+
"@prisma-next/sql-contract-ts": "0.3.0-dev.114",
|
|
25
|
+
"@prisma-next/adapter-postgres": "0.3.0-dev.114",
|
|
26
|
+
"@prisma-next/sql-lane": "0.3.0-dev.114",
|
|
27
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
28
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
29
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist",
|
|
32
33
|
"src"
|
|
33
34
|
],
|
|
34
35
|
"exports": {
|
|
35
|
-
"./
|
|
36
|
-
"./
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"./runtime":
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
"./codec-types": {
|
|
49
|
-
"types": "./dist/exports/codec-types.d.ts",
|
|
50
|
-
"import": "./dist/exports/codec-types.js"
|
|
51
|
-
},
|
|
52
|
-
"./column-types": {
|
|
53
|
-
"types": "./dist/exports/column-types.d.ts",
|
|
54
|
-
"import": "./dist/exports/column-types.js"
|
|
55
|
-
},
|
|
56
|
-
"./operation-types": {
|
|
57
|
-
"types": "./dist/exports/operation-types.d.ts",
|
|
58
|
-
"import": "./dist/exports/operation-types.js"
|
|
59
|
-
}
|
|
36
|
+
"./codec-types": "./dist/codec-types.mjs",
|
|
37
|
+
"./column-types": "./dist/column-types.mjs",
|
|
38
|
+
"./control": "./dist/control.mjs",
|
|
39
|
+
"./operation-types": "./dist/operation-types.mjs",
|
|
40
|
+
"./pack": "./dist/pack.mjs",
|
|
41
|
+
"./runtime": "./dist/runtime.mjs",
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
47
|
+
"directory": "packages/3-extensions/pgvector"
|
|
60
48
|
},
|
|
61
49
|
"scripts": {
|
|
62
|
-
"build": "
|
|
50
|
+
"build": "tsdown",
|
|
63
51
|
"test": "vitest run",
|
|
64
52
|
"test:coverage": "vitest run --coverage",
|
|
65
53
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
66
|
-
"lint": "biome check . --
|
|
67
|
-
"lint:fix": "biome check --write .
|
|
68
|
-
"lint:fix:unsafe": "biome check --write --unsafe .
|
|
69
|
-
"clean": "
|
|
54
|
+
"lint": "biome check . --error-on-warnings",
|
|
55
|
+
"lint:fix": "biome check --write .",
|
|
56
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
57
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
70
58
|
}
|
|
71
59
|
}
|
package/src/core/codecs.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';
|
|
9
9
|
|
|
10
|
-
const pgVectorCodec = codec
|
|
10
|
+
const pgVectorCodec = codec({
|
|
11
11
|
typeId: 'pg/vector@1',
|
|
12
12
|
targetTypes: ['vector'],
|
|
13
|
+
traits: ['equality'],
|
|
13
14
|
encode: (value: number[]): string => {
|
|
14
15
|
// Validate that value is an array of numbers
|
|
15
16
|
if (!Array.isArray(value)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';
|
|
2
1
|
import type { SqlOperationSignature } from '@prisma-next/sql-operations';
|
|
2
|
+
import type { QueryOperationDescriptor } from '@prisma-next/sql-relational-core/query-operations';
|
|
3
3
|
|
|
4
4
|
const pgvectorTypeId = 'pg/vector@1' as const;
|
|
5
5
|
|
|
@@ -9,10 +9,6 @@ const cosineLowering = {
|
|
|
9
9
|
template: '1 - ({{self}} <=> {{arg0}})',
|
|
10
10
|
} as const;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Shared operation definition used by both pack metadata and runtime descriptor.
|
|
14
|
-
* Frozen to prevent accidental mutation.
|
|
15
|
-
*/
|
|
16
12
|
const cosineDistanceOperation = Object.freeze({
|
|
17
13
|
method: 'cosineDistance',
|
|
18
14
|
args: [{ kind: 'param' }],
|
|
@@ -20,6 +16,27 @@ const cosineDistanceOperation = Object.freeze({
|
|
|
20
16
|
lowering: cosineLowering,
|
|
21
17
|
} as const);
|
|
22
18
|
|
|
19
|
+
export const pgvectorOperationSignature: SqlOperationSignature = {
|
|
20
|
+
forTypeId: pgvectorTypeId,
|
|
21
|
+
...cosineDistanceOperation,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const pgvectorQueryOperations: readonly QueryOperationDescriptor[] = [
|
|
25
|
+
{
|
|
26
|
+
method: 'cosineDistance',
|
|
27
|
+
args: [
|
|
28
|
+
{ codecId: pgvectorTypeId, nullable: false },
|
|
29
|
+
{ codecId: pgvectorTypeId, nullable: false },
|
|
30
|
+
],
|
|
31
|
+
returns: { codecId: 'pg/float8@1', nullable: false },
|
|
32
|
+
lowering: {
|
|
33
|
+
targetFamily: 'sql',
|
|
34
|
+
strategy: 'function',
|
|
35
|
+
template: '1 - ({{self}} <=> {{arg0}})',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
23
40
|
export const pgvectorPackMeta = {
|
|
24
41
|
kind: 'extension',
|
|
25
42
|
id: 'pgvector',
|
|
@@ -38,6 +55,16 @@ export const pgvectorPackMeta = {
|
|
|
38
55
|
named: 'CodecTypes',
|
|
39
56
|
alias: 'PgVectorTypes',
|
|
40
57
|
},
|
|
58
|
+
typeImports: [
|
|
59
|
+
{
|
|
60
|
+
package: '@prisma-next/extension-pgvector/codec-types',
|
|
61
|
+
named: 'Vector',
|
|
62
|
+
alias: 'Vector',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
parameterized: {
|
|
66
|
+
[pgvectorTypeId]: 'Vector<{{length}}>',
|
|
67
|
+
},
|
|
41
68
|
},
|
|
42
69
|
operationTypes: {
|
|
43
70
|
import: {
|
|
@@ -46,19 +73,15 @@ export const pgvectorPackMeta = {
|
|
|
46
73
|
alias: 'PgVectorOperationTypes',
|
|
47
74
|
},
|
|
48
75
|
},
|
|
76
|
+
queryOperationTypes: {
|
|
77
|
+
import: {
|
|
78
|
+
package: '@prisma-next/extension-pgvector/operation-types',
|
|
79
|
+
named: 'QueryOperationTypes',
|
|
80
|
+
alias: 'PgVectorQueryOperationTypes',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
49
83
|
storage: [
|
|
50
84
|
{ typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },
|
|
51
85
|
],
|
|
52
86
|
},
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
for: pgvectorTypeId,
|
|
56
|
-
...cosineDistanceOperation,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
} as const satisfies ExtensionPackRef<'sql', 'postgres'>;
|
|
60
|
-
|
|
61
|
-
export const pgvectorRuntimeOperation: SqlOperationSignature = {
|
|
62
|
-
forTypeId: pgvectorTypeId,
|
|
63
|
-
...cosineDistanceOperation,
|
|
64
|
-
};
|
|
87
|
+
} as const;
|
|
@@ -6,8 +6,41 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';
|
|
9
|
+
import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Static vector column descriptor without dimension.
|
|
13
|
+
* Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
|
|
14
|
+
*/
|
|
10
15
|
export const vectorColumn = {
|
|
11
|
-
codecId:
|
|
16
|
+
codecId: VECTOR_CODEC_ID,
|
|
12
17
|
nativeType: 'vector',
|
|
13
18
|
} as const satisfies ColumnTypeDescriptor;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Factory for creating dimensioned vector column descriptors.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* .column('embedding', { type: vector(1536), nullable: false })
|
|
26
|
+
* // Produces: nativeType: 'vector', typeParams: { length: 1536 }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
30
|
+
* @returns A column type descriptor with `typeParams.length` set
|
|
31
|
+
* @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
32
|
+
*/
|
|
33
|
+
export function vector<N extends number>(
|
|
34
|
+
length: N,
|
|
35
|
+
): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {
|
|
36
|
+
if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {
|
|
37
|
+
throw new RangeError(
|
|
38
|
+
`pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
codecId: VECTOR_CODEC_ID,
|
|
43
|
+
nativeType: 'vector',
|
|
44
|
+
typeParams: { length },
|
|
45
|
+
} as const;
|
|
46
|
+
}
|
package/src/exports/control.ts
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import type { SchemaIssue } from '@prisma-next/core-control-plane/types';
|
|
2
1
|
import type {
|
|
2
|
+
CodecControlHooks,
|
|
3
3
|
ComponentDatabaseDependencies,
|
|
4
4
|
SqlControlExtensionDescriptor,
|
|
5
5
|
} from '@prisma-next/family-sql/control';
|
|
6
|
-
import
|
|
7
|
-
import { pgvectorPackMeta } from '../core/descriptor-meta';
|
|
6
|
+
import { pgvectorOperationSignature, pgvectorPackMeta } from '../core/descriptor-meta';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return [
|
|
16
|
-
{
|
|
17
|
-
kind: 'extension_missing',
|
|
18
|
-
table: '',
|
|
19
|
-
message: 'Extension "vector" is missing from database (required by pgvector)',
|
|
20
|
-
},
|
|
21
|
-
];
|
|
8
|
+
const PGVECTOR_CODEC_ID = 'pg/vector@1' as const;
|
|
9
|
+
|
|
10
|
+
function buildVectorIdentityValue(typeParams: Record<string, unknown> | undefined): string | null {
|
|
11
|
+
const length = typeParams?.['length'];
|
|
12
|
+
if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {
|
|
13
|
+
return null;
|
|
22
14
|
}
|
|
23
|
-
|
|
15
|
+
|
|
16
|
+
const zeroVector = `[${new Array(length).fill('0').join(',')}]`;
|
|
17
|
+
return `'${zeroVector}'::vector`;
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
const vectorControlPlaneHooks: CodecControlHooks = {
|
|
21
|
+
expandNativeType: ({ nativeType, typeParams }) => {
|
|
22
|
+
const length = typeParams?.['length'];
|
|
23
|
+
if (typeof length === 'number' && Number.isInteger(length) && length > 0) {
|
|
24
|
+
return `${nativeType}(${length})`;
|
|
25
|
+
}
|
|
26
|
+
return nativeType;
|
|
27
|
+
},
|
|
28
|
+
resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams),
|
|
29
|
+
};
|
|
30
|
+
|
|
30
31
|
const pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {
|
|
31
32
|
init: [
|
|
32
33
|
{
|
|
@@ -59,17 +60,22 @@ const pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {
|
|
|
59
60
|
],
|
|
60
61
|
},
|
|
61
62
|
],
|
|
62
|
-
verifyDatabaseDependencyInstalled: verifyVectorExtensionInstalled,
|
|
63
63
|
},
|
|
64
64
|
],
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
* pgvector extension descriptor for CLI config.
|
|
69
|
-
* Declares database dependencies for the 'vector' Postgres extension.
|
|
70
|
-
*/
|
|
71
67
|
const pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {
|
|
72
68
|
...pgvectorPackMeta,
|
|
69
|
+
types: {
|
|
70
|
+
...pgvectorPackMeta.types,
|
|
71
|
+
codecTypes: {
|
|
72
|
+
...pgvectorPackMeta.types.codecTypes,
|
|
73
|
+
controlPlaneHooks: {
|
|
74
|
+
[PGVECTOR_CODEC_ID]: vectorControlPlaneHooks,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
operationSignatures: () => [pgvectorOperationSignature],
|
|
73
79
|
databaseDependencies: pgvectorDatabaseDependencies,
|
|
74
80
|
create: () => ({
|
|
75
81
|
familyId: 'sql' as const,
|
package/src/exports/pack.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';
|
|
1
2
|
import { pgvectorPackMeta } from '../core/descriptor-meta';
|
|
3
|
+
import type { CodecTypes } from '../types/codec-types';
|
|
2
4
|
|
|
3
5
|
const pgvectorPack = pgvectorPackMeta;
|
|
4
6
|
|
|
5
|
-
export default pgvectorPack
|
|
7
|
+
export default pgvectorPack as ExtensionPackRef<'sql', 'postgres'> & {
|
|
8
|
+
readonly __codecTypes?: CodecTypes;
|
|
9
|
+
};
|
package/src/exports/runtime.ts
CHANGED
|
@@ -1,47 +1,62 @@
|
|
|
1
|
-
import type { SqlOperationSignature } from '@prisma-next/sql-operations';
|
|
2
|
-
import type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
3
1
|
import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
4
2
|
import type {
|
|
3
|
+
RuntimeParameterizedCodecDescriptor,
|
|
5
4
|
SqlRuntimeExtensionDescriptor,
|
|
6
|
-
SqlRuntimeExtensionInstance,
|
|
7
5
|
} from '@prisma-next/sql-runtime';
|
|
6
|
+
import { type as arktype } from 'arktype';
|
|
8
7
|
import { codecDefinitions } from '../core/codecs';
|
|
9
|
-
import {
|
|
8
|
+
import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
|
|
9
|
+
import {
|
|
10
|
+
pgvectorOperationSignature,
|
|
11
|
+
pgvectorPackMeta,
|
|
12
|
+
pgvectorQueryOperations,
|
|
13
|
+
} from '../core/descriptor-meta';
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const registry = createCodecRegistry();
|
|
21
|
-
// Register all codecs from codecDefinitions
|
|
22
|
-
for (const def of Object.values(codecDefinitions)) {
|
|
23
|
-
registry.register(def.codec);
|
|
24
|
-
}
|
|
25
|
-
return registry;
|
|
15
|
+
const vectorParamsSchema = arktype({
|
|
16
|
+
length: 'number',
|
|
17
|
+
}).narrow((params, ctx) => {
|
|
18
|
+
const { length } = params;
|
|
19
|
+
if (!Number.isInteger(length)) {
|
|
20
|
+
return ctx.mustBe('an integer');
|
|
21
|
+
}
|
|
22
|
+
if (length < 1 || length > VECTOR_MAX_DIM) {
|
|
23
|
+
return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
|
|
26
24
|
}
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const parameterizedCodecDescriptors = [
|
|
29
|
+
{
|
|
30
|
+
codecId: VECTOR_CODEC_ID,
|
|
31
|
+
paramsSchema: vectorParamsSchema,
|
|
32
|
+
},
|
|
33
|
+
] as const satisfies ReadonlyArray<
|
|
34
|
+
RuntimeParameterizedCodecDescriptor<{ readonly length: number }>
|
|
35
|
+
>;
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
function createPgvectorCodecRegistry() {
|
|
38
|
+
const registry = createCodecRegistry();
|
|
39
|
+
for (const def of Object.values(codecDefinitions)) {
|
|
40
|
+
registry.register(def.codec);
|
|
30
41
|
}
|
|
42
|
+
return registry;
|
|
31
43
|
}
|
|
32
44
|
|
|
33
|
-
/**
|
|
34
|
-
* pgvector SQL runtime extension descriptor.
|
|
35
|
-
* Provides metadata and factory for creating runtime extension instances.
|
|
36
|
-
*/
|
|
37
45
|
const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
|
|
38
46
|
kind: 'extension' as const,
|
|
39
47
|
id: pgvectorPackMeta.id,
|
|
40
48
|
version: pgvectorPackMeta.version,
|
|
41
49
|
familyId: 'sql' as const,
|
|
42
50
|
targetId: 'postgres' as const,
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
codecs: createPgvectorCodecRegistry,
|
|
52
|
+
operationSignatures: () => [pgvectorOperationSignature],
|
|
53
|
+
queryOperations: () => pgvectorQueryOperations,
|
|
54
|
+
parameterizedCodecs: () => parameterizedCodecDescriptors,
|
|
55
|
+
create() {
|
|
56
|
+
return {
|
|
57
|
+
familyId: 'sql' as const,
|
|
58
|
+
targetId: 'postgres' as const,
|
|
59
|
+
};
|
|
45
60
|
},
|
|
46
61
|
};
|
|
47
62
|
|
package/src/types/codec-types.ts
CHANGED
|
@@ -7,4 +7,26 @@
|
|
|
7
7
|
* Runtime codec implementations are provided by the extension's codec registry.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import type { CodecTypes as CoreCodecTypes } from '../core/codecs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Type-level branded vector.
|
|
14
|
+
*
|
|
15
|
+
* The runtime values are plain number arrays, but parameterized column typing can
|
|
16
|
+
* carry the dimension at the type level (e.g. Vector<1536>).
|
|
17
|
+
*/
|
|
18
|
+
export type Vector<N extends number = number> = number[] & { readonly __vectorLength?: N };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Codec types for pgvector.
|
|
22
|
+
*
|
|
23
|
+
* - Scalar output remains `number[]` (runtime representation).
|
|
24
|
+
* - `parameterizedOutput` enables lane typing to compute `Vector<N>` from column `typeParams`.
|
|
25
|
+
*/
|
|
26
|
+
export type CodecTypes = CoreCodecTypes & {
|
|
27
|
+
readonly 'pg/vector@1': CoreCodecTypes['pg/vector@1'] & {
|
|
28
|
+
readonly parameterizedOutput: <P extends { readonly length: number }>(
|
|
29
|
+
params: P,
|
|
30
|
+
) => P extends { readonly length: infer N extends number } ? Vector<N> : Vector<number>;
|
|
31
|
+
};
|
|
32
|
+
};
|