@prisma-next/extension-pgvector 0.5.0-dev.14 → 0.5.0-dev.16
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/dist/control.mjs +2 -2
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-BQbvJJxu.mjs → descriptor-meta-DTopW_37.mjs} +36 -37
- package/dist/descriptor-meta-DTopW_37.mjs.map +1 -0
- package/dist/operation-types.d.mts +18 -42
- package/dist/operation-types.d.mts.map +1 -1
- package/dist/pack.d.mts +1 -0
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/runtime.mjs.map +1 -1
- package/package.json +13 -13
- package/src/core/descriptor-meta.ts +48 -26
- package/src/exports/control.ts +1 -1
- package/src/exports/runtime.ts +1 -1
- package/src/types/operation-types.ts +24 -30
- package/dist/descriptor-meta-BQbvJJxu.mjs.map +0 -1
package/dist/control.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-DTopW_37.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",
|
package/dist/control.mjs.map
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { n as VECTOR_MAX_DIM } from "./constants-Co5golCK.mjs";
|
|
2
|
+
import { buildOperation, toExpr } from "@prisma-next/sql-relational-core/expression";
|
|
2
3
|
import { codec, defineCodecs } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
|
|
4
5
|
//#region src/core/authoring.ts
|
|
@@ -64,43 +65,41 @@ const dataTypes = codecs.dataTypes;
|
|
|
64
65
|
//#endregion
|
|
65
66
|
//#region src/core/descriptor-meta.ts
|
|
66
67
|
const pgvectorTypeId = "pg/vector@1";
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
codecId: pgvectorTypeId,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}, {
|
|
86
|
-
method: "cosineSimilarity",
|
|
87
|
-
args: [{
|
|
88
|
-
codecId: pgvectorTypeId,
|
|
89
|
-
nullable: false
|
|
68
|
+
function pgvectorQueryOperations() {
|
|
69
|
+
return [{
|
|
70
|
+
method: "cosineDistance",
|
|
71
|
+
self: { codecId: pgvectorTypeId },
|
|
72
|
+
impl: (self, other) => buildOperation({
|
|
73
|
+
method: "cosineDistance",
|
|
74
|
+
args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
|
|
75
|
+
returns: {
|
|
76
|
+
codecId: "pg/float8@1",
|
|
77
|
+
nullable: false
|
|
78
|
+
},
|
|
79
|
+
lowering: {
|
|
80
|
+
targetFamily: "sql",
|
|
81
|
+
strategy: "function",
|
|
82
|
+
template: "{{self}} <=> {{arg0}}"
|
|
83
|
+
}
|
|
84
|
+
})
|
|
90
85
|
}, {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
86
|
+
method: "cosineSimilarity",
|
|
87
|
+
self: { codecId: pgvectorTypeId },
|
|
88
|
+
impl: (self, other) => buildOperation({
|
|
89
|
+
method: "cosineSimilarity",
|
|
90
|
+
args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
|
|
91
|
+
returns: {
|
|
92
|
+
codecId: "pg/float8@1",
|
|
93
|
+
nullable: false
|
|
94
|
+
},
|
|
95
|
+
lowering: {
|
|
96
|
+
targetFamily: "sql",
|
|
97
|
+
strategy: "function",
|
|
98
|
+
template: "1 - ({{self}} <=> {{arg0}})"
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}];
|
|
102
|
+
}
|
|
104
103
|
const pgvectorPackMetaBase = {
|
|
105
104
|
kind: "extension",
|
|
106
105
|
id: "pgvector",
|
|
@@ -145,4 +144,4 @@ const pgvectorPackMeta = pgvectorPackMetaBase;
|
|
|
145
144
|
|
|
146
145
|
//#endregion
|
|
147
146
|
export { pgvectorQueryOperations as n, codecDefinitions as r, pgvectorPackMeta as t };
|
|
148
|
-
//# sourceMappingURL=descriptor-meta-
|
|
147
|
+
//# sourceMappingURL=descriptor-meta-DTopW_37.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-DTopW_37.mjs","names":["pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n}"],"sources":["../src/core/authoring.ts","../src/core/codecs.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport { VECTOR_MAX_DIM } from './constants';\n\nexport const pgvectorAuthoringTypes = {\n pgvector: {\n Vector: {\n kind: 'typeConstructor',\n args: [\n { kind: 'number', name: 'length', integer: true, minimum: 1, maximum: VECTOR_MAX_DIM },\n ],\n output: {\n codecId: 'pg/vector@1',\n nativeType: 'vector',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\n * Vector codec implementation for pgvector extension.\n *\n * Provides encoding/decoding for the `vector` PostgreSQL type.\n * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).\n */\n\nimport { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';\n\nconst pgVectorCodec = codec({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\n traits: ['equality'],\n renderOutputType: (typeParams) => {\n const length = typeParams['length'];\n if (length === undefined) return undefined;\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error(\n `renderOutputType: expected positive integer \"length\" in typeParams for Vector, got ${String(length)}`,\n );\n }\n return `Vector<${length}>`;\n },\n encode: (value: number[]): string => {\n // Validate that value is an array of numbers\n if (!Array.isArray(value)) {\n throw new Error('Vector value must be an array of numbers');\n }\n if (!value.every((v) => typeof v === 'number')) {\n throw new Error('Vector value must contain only numbers');\n }\n // Format as PostgreSQL vector text format: [1,2,3]\n // PostgreSQL's pg library requires the vector format string\n return `[${value.join(',')}]`;\n },\n decode: (wire: string): number[] => {\n // Handle string format from PostgreSQL: [1,2,3]\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n // Parse PostgreSQL vector format: [1,2,3]\n if (!wire.startsWith('[') || !wire.endsWith(']')) {\n throw new Error(`Invalid vector format: expected \"[...]\", got \"${wire}\"`);\n }\n const content = wire.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n const values = content.split(',').map((v) => {\n const num = Number.parseFloat(v.trim());\n if (Number.isNaN(num)) {\n throw new Error(`Invalid vector value: \"${v}\" is not a number`);\n }\n return num;\n });\n return values;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'vector',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs().add('vector', pgVectorCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\n// Export types derived from codecs builder\nexport type CodecTypes = typeof codecs.CodecTypes;\n","import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport {\n buildOperation,\n type CodecExpression,\n type Expression,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport { pgvectorAuthoringTypes } from './authoring';\nimport { codecDefinitions } from './codecs';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\nexport function pgvectorQueryOperations<\n CT extends CodecTypesBase,\n>(): readonly SqlOperationDescriptor[] {\n return [\n {\n method: 'cosineDistance',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>\n buildOperation({\n method: 'cosineDistance',\n args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n }),\n },\n {\n method: 'cosineSimilarity',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>\n buildOperation({\n method: 'cosineSimilarity',\n args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '1 - ({{self}} <=> {{arg0}})',\n },\n }),\n },\n ];\n}\n\nconst pgvectorPackMetaBase = {\n kind: 'extension',\n id: 'pgvector',\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'pgvector.cosine': true,\n },\n },\n authoring: {\n type: pgvectorAuthoringTypes,\n },\n types: {\n codecTypes: {\n codecInstances: Object.values(codecDefinitions).map((def) => def.codec),\n import: {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'CodecTypes',\n alias: 'PgVectorTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'Vector',\n alias: 'Vector',\n },\n ],\n },\n operationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'OperationTypes',\n alias: 'PgVectorOperationTypes',\n },\n },\n queryOperationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PgVectorQueryOperationTypes',\n },\n },\n storage: [\n { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },\n ],\n },\n} as const;\n\nexport const pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = pgvectorPackMetaBase;\n"],"mappings":";;;;;AAGA,MAAa,yBAAyB,EACpC,UAAU,EACR,QAAQ;CACN,MAAM;CACN,MAAM,CACJ;EAAE,MAAM;EAAU,MAAM;EAAU,SAAS;EAAM,SAAS;EAAG,SAAS;EAAgB,CACvF;CACD,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MA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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
|
|
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
|
|
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
|
|
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
|
|
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":";;;;;;
|
|
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
|
@@ -2,6 +2,7 @@ import { t as CodecTypes } from "./codec-types-BifaP625.mjs";
|
|
|
2
2
|
import * as _prisma_next_sql_relational_core_ast0 from "@prisma-next/sql-relational-core/ast";
|
|
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";
|
package/dist/pack.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":";;;;;cA0DM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAgDI,qCAAA,CAAA,8DAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEG,yBAAyB;0BACZ"}
|
package/dist/pack.mjs
CHANGED
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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-
|
|
2
|
+
import { n as pgvectorQueryOperations, r as codecDefinitions, t as pgvectorPackMeta } from "./descriptor-meta-DTopW_37.mjs";
|
|
3
3
|
import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
|
|
4
4
|
import { type } from "arktype";
|
|
5
5
|
|
|
@@ -25,7 +25,7 @@ const pgvectorRuntimeDescriptor = {
|
|
|
25
25
|
familyId: "sql",
|
|
26
26
|
targetId: "postgres",
|
|
27
27
|
codecs: createPgvectorCodecRegistry,
|
|
28
|
-
queryOperations: () => pgvectorQueryOperations,
|
|
28
|
+
queryOperations: () => pgvectorQueryOperations(),
|
|
29
29
|
parameterizedCodecs: () => parameterizedCodecDescriptors,
|
|
30
30
|
create() {
|
|
31
31
|
return {
|
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 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;
|
|
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,yBAAyB;CAChD,2BAA2B;CAC3B,SAAS;AACP,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ;AAED,sBAAe"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
|
-
"@prisma-next/contract
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/sql-operations": "0.5.0-dev.
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/sql-
|
|
15
|
-
"@prisma-next/sql-
|
|
8
|
+
"@prisma-next/contract": "0.5.0-dev.16",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.5.0-dev.16",
|
|
10
|
+
"@prisma-next/sql-operations": "0.5.0-dev.16",
|
|
11
|
+
"@prisma-next/framework-components": "0.5.0-dev.16",
|
|
12
|
+
"@prisma-next/family-sql": "0.5.0-dev.16",
|
|
13
|
+
"@prisma-next/sql-runtime": "0.5.0-dev.16",
|
|
14
|
+
"@prisma-next/sql-schema-ir": "0.5.0-dev.16",
|
|
15
|
+
"@prisma-next/sql-relational-core": "0.5.0-dev.16"
|
|
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/operations": "0.5.0-dev.
|
|
22
|
-
"@prisma-next/sql-contract": "0.5.0-dev.
|
|
23
|
-
"@prisma-next/sql-contract-ts": "0.5.0-dev.
|
|
24
|
-
"@prisma-next/tsdown": "0.0.0",
|
|
21
|
+
"@prisma-next/operations": "0.5.0-dev.16",
|
|
22
|
+
"@prisma-next/sql-contract": "0.5.0-dev.16",
|
|
23
|
+
"@prisma-next/sql-contract-ts": "0.5.0-dev.16",
|
|
25
24
|
"@prisma-next/test-utils": "0.0.1",
|
|
25
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
26
26
|
"@prisma-next/tsconfig": "0.0.0"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
@@ -1,38 +1,60 @@
|
|
|
1
1
|
import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';
|
|
2
|
+
import {
|
|
3
|
+
buildOperation,
|
|
4
|
+
type CodecExpression,
|
|
5
|
+
type Expression,
|
|
6
|
+
toExpr,
|
|
7
|
+
} from '@prisma-next/sql-relational-core/expression';
|
|
2
8
|
import type { CodecTypes } from '../types/codec-types';
|
|
3
9
|
import { pgvectorAuthoringTypes } from './authoring';
|
|
4
10
|
import { codecDefinitions } from './codecs';
|
|
5
11
|
|
|
6
12
|
const pgvectorTypeId = 'pg/vector@1' as const;
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
type CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;
|
|
15
|
+
|
|
16
|
+
export function pgvectorQueryOperations<
|
|
17
|
+
CT extends CodecTypesBase,
|
|
18
|
+
>(): readonly SqlOperationDescriptor[] {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
method: 'cosineDistance',
|
|
22
|
+
self: { codecId: pgvectorTypeId },
|
|
23
|
+
impl: (
|
|
24
|
+
self: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
25
|
+
other: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
26
|
+
): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>
|
|
27
|
+
buildOperation({
|
|
28
|
+
method: 'cosineDistance',
|
|
29
|
+
args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
|
|
30
|
+
returns: { codecId: 'pg/float8@1', nullable: false },
|
|
31
|
+
lowering: {
|
|
32
|
+
targetFamily: 'sql',
|
|
33
|
+
strategy: 'function',
|
|
34
|
+
template: '{{self}} <=> {{arg0}}',
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
20
37
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
{
|
|
39
|
+
method: 'cosineSimilarity',
|
|
40
|
+
self: { codecId: pgvectorTypeId },
|
|
41
|
+
impl: (
|
|
42
|
+
self: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
43
|
+
other: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
44
|
+
): Expression<{ codecId: 'pg/float8@1'; nullable: false }> =>
|
|
45
|
+
buildOperation({
|
|
46
|
+
method: 'cosineSimilarity',
|
|
47
|
+
args: [toExpr(self, pgvectorTypeId), toExpr(other, pgvectorTypeId)],
|
|
48
|
+
returns: { codecId: 'pg/float8@1', nullable: false },
|
|
49
|
+
lowering: {
|
|
50
|
+
targetFamily: 'sql',
|
|
51
|
+
strategy: 'function',
|
|
52
|
+
template: '1 - ({{self}} <=> {{arg0}})',
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
33
55
|
},
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
];
|
|
57
|
+
}
|
|
36
58
|
|
|
37
59
|
const pgvectorPackMetaBase = {
|
|
38
60
|
kind: 'extension',
|
package/src/exports/control.ts
CHANGED
|
@@ -75,7 +75,7 @@ const pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {
|
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
77
|
},
|
|
78
|
-
queryOperations: () => pgvectorQueryOperations,
|
|
78
|
+
queryOperations: () => pgvectorQueryOperations(),
|
|
79
79
|
databaseDependencies: pgvectorDatabaseDependencies,
|
|
80
80
|
create: () => ({
|
|
81
81
|
familyId: 'sql' as const,
|
package/src/exports/runtime.ts
CHANGED
|
@@ -45,7 +45,7 @@ const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
|
|
|
45
45
|
familyId: 'sql' as const,
|
|
46
46
|
targetId: 'postgres' as const,
|
|
47
47
|
codecs: createPgvectorCodecRegistry,
|
|
48
|
-
queryOperations: () => pgvectorQueryOperations,
|
|
48
|
+
queryOperations: () => pgvectorQueryOperations(),
|
|
49
49
|
parameterizedCodecs: () => parameterizedCodecDescriptors,
|
|
50
50
|
create() {
|
|
51
51
|
return {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { SqlQueryOperationTypes } from '@prisma-next/sql-contract/types';
|
|
2
|
+
import type { CodecExpression, Expression } from '@prisma-next/sql-relational-core/expression';
|
|
3
|
+
|
|
4
|
+
type CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Operation type definitions for pgvector extension.
|
|
@@ -10,40 +13,31 @@ import type { SqlQueryOperationTypes } from '@prisma-next/sql-contract/types';
|
|
|
10
13
|
export type OperationTypes = {
|
|
11
14
|
readonly 'pg/vector@1': {
|
|
12
15
|
readonly cosineDistance: {
|
|
13
|
-
readonly
|
|
14
|
-
readonly returns: { readonly codecId: 'pg/float8@1'; readonly nullable: false };
|
|
15
|
-
readonly lowering: {
|
|
16
|
-
readonly targetFamily: 'sql';
|
|
17
|
-
readonly strategy: 'function';
|
|
18
|
-
readonly template: string;
|
|
19
|
-
};
|
|
16
|
+
readonly self: { readonly codecId: 'pg/vector@1' };
|
|
20
17
|
};
|
|
21
18
|
readonly cosineSimilarity: {
|
|
22
|
-
readonly
|
|
23
|
-
readonly returns: { readonly codecId: 'pg/float8@1'; readonly nullable: false };
|
|
24
|
-
readonly lowering: {
|
|
25
|
-
readonly targetFamily: 'sql';
|
|
26
|
-
readonly strategy: 'function';
|
|
27
|
-
readonly template: string;
|
|
28
|
-
};
|
|
19
|
+
readonly self: { readonly codecId: 'pg/vector@1' };
|
|
29
20
|
};
|
|
30
21
|
};
|
|
31
22
|
};
|
|
32
23
|
|
|
33
24
|
/** Flat operation signatures for the query builder. */
|
|
34
|
-
export type QueryOperationTypes = SqlQueryOperationTypes<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{ readonly codecId: 'pg/vector@1'
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{ readonly codecId: 'pg/vector@1'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}>;
|
|
25
|
+
export type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<
|
|
26
|
+
CT,
|
|
27
|
+
{
|
|
28
|
+
readonly cosineDistance: {
|
|
29
|
+
readonly self: { readonly codecId: 'pg/vector@1' };
|
|
30
|
+
readonly impl: (
|
|
31
|
+
self: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
32
|
+
other: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
33
|
+
) => Expression<{ codecId: 'pg/float8@1'; nullable: false }>;
|
|
34
|
+
};
|
|
35
|
+
readonly cosineSimilarity: {
|
|
36
|
+
readonly self: { readonly codecId: 'pg/vector@1' };
|
|
37
|
+
readonly impl: (
|
|
38
|
+
self: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
39
|
+
other: CodecExpression<'pg/vector@1', boolean, CT>,
|
|
40
|
+
) => Expression<{ codecId: 'pg/float8@1'; nullable: false }>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-BQbvJJxu.mjs","names":["pgvectorQueryOperations: readonly SqlOperationDescriptor[]","pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n}"],"sources":["../src/core/authoring.ts","../src/core/codecs.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport { VECTOR_MAX_DIM } from './constants';\n\nexport const pgvectorAuthoringTypes = {\n pgvector: {\n Vector: {\n kind: 'typeConstructor',\n args: [\n { kind: 'number', name: 'length', integer: true, minimum: 1, maximum: VECTOR_MAX_DIM },\n ],\n output: {\n codecId: 'pg/vector@1',\n nativeType: 'vector',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\n * Vector codec implementation for pgvector extension.\n *\n * Provides encoding/decoding for the `vector` PostgreSQL type.\n * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).\n */\n\nimport { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';\n\nconst pgVectorCodec = codec({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\n traits: ['equality'],\n renderOutputType: (typeParams) => {\n const length = typeParams['length'];\n if (length === undefined) return undefined;\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error(\n `renderOutputType: expected positive integer \"length\" in typeParams for Vector, got ${String(length)}`,\n );\n }\n return `Vector<${length}>`;\n },\n encode: (value: number[]): string => {\n // Validate that value is an array of numbers\n if (!Array.isArray(value)) {\n throw new Error('Vector value must be an array of numbers');\n }\n if (!value.every((v) => typeof v === 'number')) {\n throw new Error('Vector value must contain only numbers');\n }\n // Format as PostgreSQL vector text format: [1,2,3]\n // PostgreSQL's pg library requires the vector format string\n return `[${value.join(',')}]`;\n },\n decode: (wire: string): number[] => {\n // Handle string format from PostgreSQL: [1,2,3]\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n // Parse PostgreSQL vector format: [1,2,3]\n if (!wire.startsWith('[') || !wire.endsWith(']')) {\n throw new Error(`Invalid vector format: expected \"[...]\", got \"${wire}\"`);\n }\n const content = wire.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n const values = content.split(',').map((v) => {\n const num = Number.parseFloat(v.trim());\n if (Number.isNaN(num)) {\n throw new Error(`Invalid vector value: \"${v}\" is not a number`);\n }\n return num;\n });\n return values;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'vector',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs().add('vector', pgVectorCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\n// Export types derived from codecs builder\nexport type CodecTypes = typeof codecs.CodecTypes;\n","import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport type { CodecTypes } from '../types/codec-types';\nimport { pgvectorAuthoringTypes } from './authoring';\nimport { codecDefinitions } from './codecs';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\nexport const pgvectorQueryOperations: readonly SqlOperationDescriptor[] = [\n {\n method: 'cosineDistance',\n args: [\n { codecId: pgvectorTypeId, nullable: false },\n { codecId: pgvectorTypeId, nullable: false },\n ],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n },\n {\n method: 'cosineSimilarity',\n args: [\n { codecId: pgvectorTypeId, nullable: false },\n { codecId: pgvectorTypeId, nullable: false },\n ],\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\nconst pgvectorPackMetaBase = {\n kind: 'extension',\n id: 'pgvector',\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'pgvector.cosine': true,\n },\n },\n authoring: {\n type: pgvectorAuthoringTypes,\n },\n types: {\n codecTypes: {\n codecInstances: Object.values(codecDefinitions).map((def) => def.codec),\n import: {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'CodecTypes',\n alias: 'PgVectorTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'Vector',\n alias: 'Vector',\n },\n ],\n },\n operationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'OperationTypes',\n alias: 'PgVectorOperationTypes',\n },\n },\n queryOperationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PgVectorQueryOperationTypes',\n },\n },\n storage: [\n { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },\n ],\n },\n} as const;\n\nexport const pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = pgvectorPackMetaBase;\n"],"mappings":";;;;AAGA,MAAa,yBAAyB,EACpC,UAAU,EACR,QAAQ;CACN,MAAM;CACN,MAAM,CACJ;EAAE,MAAM;EAAU,MAAM;EAAU,SAAS;EAAM,SAAS;EAAG,SAAS;EAAgB,CACvF;CACD,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MAA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