@prisma-next/extension-pgvector 0.3.0-pr.100.2 → 0.3.0-pr.100.4
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/chunk-BYJDSW2E.js +7 -0
- package/dist/chunk-BYJDSW2E.js.map +1 -0
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/exports/column-types.d.ts +1 -0
- package/dist/exports/column-types.d.ts.map +1 -1
- package/dist/exports/column-types.js +9 -0
- package/dist/exports/column-types.js.map +1 -1
- package/dist/exports/runtime.d.ts.map +1 -1
- package/dist/exports/runtime.js +12 -0
- package/dist/exports/runtime.js.map +1 -1
- package/package.json +15 -15
- package/src/core/constants.ts +4 -0
- package/src/exports/column-types.ts +7 -0
- package/src/exports/runtime.ts +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/constants.ts"],"sourcesContent":["/**\n * Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).\n */\nexport const VECTOR_MAX_DIM = 16000;\n"],"mappings":";AAGO,IAAM,iBAAiB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC"}
|
|
@@ -24,6 +24,7 @@ export declare const vectorColumn: {
|
|
|
24
24
|
*
|
|
25
25
|
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
26
26
|
* @returns A column type descriptor with `typeParams.length` set
|
|
27
|
+
* @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
27
28
|
*/
|
|
28
29
|
export declare function vector<N extends number>(length: N): ColumnTypeDescriptor & {
|
|
29
30
|
readonly typeParams: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.d.ts","sourceRoot":"","sources":["../../src/exports/column-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"column-types.d.ts","sourceRoot":"","sources":["../../src/exports/column-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAG5E;;;GAGG;AACH,eAAO,MAAM,YAAY;;;CAGgB,CAAC;AAE1C;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EACrC,MAAM,EAAE,CAAC,GACR,oBAAoB,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CAAA;CAAE,CAWxE"}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VECTOR_MAX_DIM
|
|
3
|
+
} from "../chunk-BYJDSW2E.js";
|
|
4
|
+
|
|
1
5
|
// src/exports/column-types.ts
|
|
2
6
|
var vectorColumn = {
|
|
3
7
|
codecId: "pg/vector@1",
|
|
4
8
|
nativeType: "vector"
|
|
5
9
|
};
|
|
6
10
|
function vector(length) {
|
|
11
|
+
if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {
|
|
12
|
+
throw new RangeError(
|
|
13
|
+
`pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
7
16
|
return {
|
|
8
17
|
codecId: "pg/vector@1",
|
|
9
18
|
nativeType: `vector(${length})`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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';\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: 'pg/vector@1',\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(1536)', 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 */\nexport function vector<N extends number>(\n length: N,\n): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {\n return {\n codecId: 'pg/vector@1',\n nativeType: `vector(${length})`,\n typeParams: { length },\n } as const;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"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_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: 'pg/vector@1',\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(1536)', 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: 'pg/vector@1',\n nativeType: `vector(${length})`,\n typeParams: { length },\n } as const;\n}\n"],"mappings":";;;;;AAcO,IAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,EACT,YAAY;AACd;AAeO,SAAS,OACd,QACwE;AACxE,MAAI,CAAC,OAAO,UAAU,MAAM,KAAK,SAAS,KAAK,SAAS,gBAAgB;AACtE,UAAM,IAAI;AAAA,MACR,iDAAiD,cAAc,UAAU,MAAM;AAAA,IACjF;AAAA,EACF;AACA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,UAAU,MAAM;AAAA,IAC5B,YAAY,EAAE,OAAO;AAAA,EACvB;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/exports/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,6BAA6B,EAE9B,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/exports/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,6BAA6B,EAE9B,MAAM,0BAA0B,CAAC;AAqDlC;;;GAGG;AACH,QAAA,MAAM,yBAAyB,EAAE,6BAA6B,CAAC,UAAU,CASxE,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
package/dist/exports/runtime.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VECTOR_MAX_DIM
|
|
3
|
+
} from "../chunk-BYJDSW2E.js";
|
|
1
4
|
import {
|
|
2
5
|
pgvectorPackMeta,
|
|
3
6
|
pgvectorRuntimeOperation
|
|
@@ -59,6 +62,15 @@ var dataTypes = codecs.dataTypes;
|
|
|
59
62
|
var vectorTypeId = "pg/vector@1";
|
|
60
63
|
var vectorParamsSchema = arktype({
|
|
61
64
|
length: "number"
|
|
65
|
+
}).narrow((params, ctx) => {
|
|
66
|
+
const { length } = params;
|
|
67
|
+
if (!Number.isInteger(length)) {
|
|
68
|
+
return ctx.mustBe("an integer");
|
|
69
|
+
}
|
|
70
|
+
if (length < 1 || length > VECTOR_MAX_DIM) {
|
|
71
|
+
return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
62
74
|
});
|
|
63
75
|
var PgVectorRuntimeExtensionInstance = class {
|
|
64
76
|
familyId = "sql";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/runtime.ts","../../src/core/codecs.ts"],"sourcesContent":["import type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeExtensionDescriptor,\n SqlRuntimeExtensionInstance,\n} from '@prisma-next/sql-runtime';\nimport { type as arktype } from 'arktype';\nimport { codecDefinitions } from '../core/codecs';\nimport { pgvectorPackMeta, pgvectorRuntimeOperation } from '../core/descriptor-meta';\n\nconst vectorTypeId = 'pg/vector@1' as const;\nconst vectorParamsSchema = arktype({\n length: 'number',\n});\n\n/**\n * pgvector SQL runtime extension instance.\n * Provides codecs and operations for vector data type and similarity operations.\n */\nclass PgVectorRuntimeExtensionInstance implements SqlRuntimeExtensionInstance<'postgres'> {\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n codecs(): CodecRegistry {\n const registry = createCodecRegistry();\n // Register all codecs from codecDefinitions\n for (const def of Object.values(codecDefinitions)) {\n registry.register(def.codec);\n }\n return registry;\n }\n\n operations(): ReadonlyArray<SqlOperationSignature> {\n return [pgvectorRuntimeOperation];\n }\n\n parameterizedCodecs(): ReadonlyArray<\n RuntimeParameterizedCodecDescriptor<{ readonly length: number }>\n > {\n return [\n {\n codecId: vectorTypeId,\n paramsSchema: vectorParamsSchema,\n },\n ];\n }\n}\n\n/**\n * pgvector SQL runtime extension descriptor.\n * Provides metadata and factory for creating runtime extension instances.\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 create(): SqlRuntimeExtensionInstance<'postgres'> {\n return new PgVectorRuntimeExtensionInstance();\n },\n};\n\nexport default pgvectorRuntimeDescriptor;\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<'pg/vector@1', string, number[]>({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/runtime.ts","../../src/core/codecs.ts"],"sourcesContent":["import type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeExtensionDescriptor,\n SqlRuntimeExtensionInstance,\n} from '@prisma-next/sql-runtime';\nimport { type as arktype } from 'arktype';\nimport { codecDefinitions } from '../core/codecs';\nimport { VECTOR_MAX_DIM } from '../core/constants';\nimport { pgvectorPackMeta, pgvectorRuntimeOperation } from '../core/descriptor-meta';\n\nconst vectorTypeId = 'pg/vector@1' as const;\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/**\n * pgvector SQL runtime extension instance.\n * Provides codecs and operations for vector data type and similarity operations.\n */\nclass PgVectorRuntimeExtensionInstance implements SqlRuntimeExtensionInstance<'postgres'> {\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n codecs(): CodecRegistry {\n const registry = createCodecRegistry();\n // Register all codecs from codecDefinitions\n for (const def of Object.values(codecDefinitions)) {\n registry.register(def.codec);\n }\n return registry;\n }\n\n operations(): ReadonlyArray<SqlOperationSignature> {\n return [pgvectorRuntimeOperation];\n }\n\n parameterizedCodecs(): ReadonlyArray<\n RuntimeParameterizedCodecDescriptor<{ readonly length: number }>\n > {\n return [\n {\n codecId: vectorTypeId,\n paramsSchema: vectorParamsSchema,\n },\n ];\n }\n}\n\n/**\n * pgvector SQL runtime extension descriptor.\n * Provides metadata and factory for creating runtime extension instances.\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 create(): SqlRuntimeExtensionInstance<'postgres'> {\n return new PgVectorRuntimeExtensionInstance();\n },\n};\n\nexport default pgvectorRuntimeDescriptor;\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<'pg/vector@1', string, number[]>({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\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"],"mappings":";;;;;;;;;AAEA,SAAS,2BAA2B;AAMpC,SAAS,QAAQ,eAAe;;;ACDhC,SAAS,OAAO,oBAAoB;AAEpC,IAAM,gBAAgB,MAAuC;AAAA,EAC3D,QAAQ;AAAA,EACR,aAAa,CAAC,QAAQ;AAAA,EACtB,QAAQ,CAAC,UAA4B;AAEnC,QAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,YAAM,IAAI,MAAM,0CAA0C;AAAA,IAC5D;AACA,QAAI,CAAC,MAAM,MAAM,CAAC,MAAM,OAAO,MAAM,QAAQ,GAAG;AAC9C,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAGA,WAAO,IAAI,MAAM,KAAK,GAAG,CAAC;AAAA,EAC5B;AAAA,EACA,QAAQ,CAAC,SAA2B;AAElC,QAAI,OAAO,SAAS,UAAU;AAC5B,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AAEA,QAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,GAAG,GAAG;AAChD,YAAM,IAAI,MAAM,iDAAiD,IAAI,GAAG;AAAA,IAC1E;AACA,UAAM,UAAU,KAAK,MAAM,GAAG,EAAE,EAAE,KAAK;AACvC,QAAI,YAAY,IAAI;AAClB,aAAO,CAAC;AAAA,IACV;AACA,UAAM,SAAS,QAAQ,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM;AAC3C,YAAM,MAAM,OAAO,WAAW,EAAE,KAAK,CAAC;AACtC,UAAI,OAAO,MAAM,GAAG,GAAG;AACrB,cAAM,IAAI,MAAM,0BAA0B,CAAC,mBAAmB;AAAA,MAChE;AACA,aAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EACA,MAAM;AAAA,IACJ,IAAI;AAAA,MACF,KAAK;AAAA,QACH,UAAU;AAAA,UACR,YAAY;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAGD,IAAM,SAAS,aAAa,EAAE,IAAI,UAAU,aAAa;AAGlD,IAAM,mBAAmB,OAAO;AAChC,IAAM,YAAY,OAAO;;;ADjDhC,IAAM,eAAe;AACrB,IAAM,qBAAqB,QAAQ;AAAA,EACjC,QAAQ;AACV,CAAC,EAAE,OAAO,CAAC,QAAQ,QAAQ;AACzB,QAAM,EAAE,OAAO,IAAI;AACnB,MAAI,CAAC,OAAO,UAAU,MAAM,GAAG;AAC7B,WAAO,IAAI,OAAO,YAAY;AAAA,EAChC;AACA,MAAI,SAAS,KAAK,SAAS,gBAAgB;AACzC,WAAO,IAAI,OAAO,oBAAoB,cAAc,GAAG;AAAA,EACzD;AACA,SAAO;AACT,CAAC;AAMD,IAAM,mCAAN,MAA0F;AAAA,EAC/E,WAAW;AAAA,EACX,WAAW;AAAA,EAEpB,SAAwB;AACtB,UAAM,WAAW,oBAAoB;AAErC,eAAW,OAAO,OAAO,OAAO,gBAAgB,GAAG;AACjD,eAAS,SAAS,IAAI,KAAK;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,aAAmD;AACjD,WAAO,CAAC,wBAAwB;AAAA,EAClC;AAAA,EAEA,sBAEE;AACA,WAAO;AAAA,MACL;AAAA,QACE,SAAS;AAAA,QACT,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;AAMA,IAAM,4BAAuE;AAAA,EAC3E,MAAM;AAAA,EACN,IAAI,iBAAiB;AAAA,EACrB,SAAS,iBAAiB;AAAA,EAC1B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAkD;AAChD,WAAO,IAAI,iCAAiC;AAAA,EAC9C;AACF;AAEA,IAAO,kBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.3.0-pr.100.
|
|
3
|
+
"version": "0.3.0-pr.100.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
|
-
"@prisma-next/cli": "0.3.0-pr.100.
|
|
9
|
-
"@prisma-next/contract
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/sql-
|
|
13
|
-
"@prisma-next/sql-
|
|
14
|
-
"@prisma-next/sql-
|
|
15
|
-
"@prisma-next/
|
|
16
|
-
"@prisma-next/contract": "0.3.0-pr.100.
|
|
8
|
+
"@prisma-next/cli": "0.3.0-pr.100.4",
|
|
9
|
+
"@prisma-next/contract": "0.3.0-pr.100.4",
|
|
10
|
+
"@prisma-next/family-sql": "0.3.0-pr.100.4",
|
|
11
|
+
"@prisma-next/sql-operations": "0.3.0-pr.100.4",
|
|
12
|
+
"@prisma-next/sql-relational-core": "0.3.0-pr.100.4",
|
|
13
|
+
"@prisma-next/sql-runtime": "0.3.0-pr.100.4",
|
|
14
|
+
"@prisma-next/sql-schema-ir": "0.3.0-pr.100.4",
|
|
15
|
+
"@prisma-next/core-control-plane": "0.3.0-pr.100.4",
|
|
16
|
+
"@prisma-next/contract-authoring": "0.3.0-pr.100.4"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tsup": "8.5.1",
|
|
20
20
|
"typescript": "5.9.3",
|
|
21
21
|
"vitest": "4.0.16",
|
|
22
|
-
"@prisma-next/adapter-postgres": "0.3.0-pr.100.
|
|
23
|
-
"@prisma-next/operations": "0.3.0-pr.100.
|
|
24
|
-
"@prisma-next/sql-contract": "0.3.0-pr.100.
|
|
25
|
-
"@prisma-next/sql-contract-ts": "0.3.0-pr.100.
|
|
26
|
-
"@prisma-next/sql-lane": "0.3.0-pr.100.
|
|
22
|
+
"@prisma-next/adapter-postgres": "0.3.0-pr.100.4",
|
|
23
|
+
"@prisma-next/operations": "0.3.0-pr.100.4",
|
|
24
|
+
"@prisma-next/sql-contract": "0.3.0-pr.100.4",
|
|
25
|
+
"@prisma-next/sql-contract-ts": "0.3.0-pr.100.4",
|
|
26
|
+
"@prisma-next/sql-lane": "0.3.0-pr.100.4",
|
|
27
27
|
"@prisma-next/test-utils": "0.0.1",
|
|
28
28
|
"@prisma-next/tsconfig": "0.0.0"
|
|
29
29
|
},
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';
|
|
9
|
+
import { VECTOR_MAX_DIM } from '../core/constants';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Static vector column descriptor without dimension.
|
|
@@ -27,10 +28,16 @@ export const vectorColumn = {
|
|
|
27
28
|
*
|
|
28
29
|
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
29
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]
|
|
30
32
|
*/
|
|
31
33
|
export function vector<N extends number>(
|
|
32
34
|
length: N,
|
|
33
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
|
+
}
|
|
34
41
|
return {
|
|
35
42
|
codecId: 'pg/vector@1',
|
|
36
43
|
nativeType: `vector(${length})`,
|
package/src/exports/runtime.ts
CHANGED
|
@@ -8,11 +8,21 @@ import type {
|
|
|
8
8
|
} from '@prisma-next/sql-runtime';
|
|
9
9
|
import { type as arktype } from 'arktype';
|
|
10
10
|
import { codecDefinitions } from '../core/codecs';
|
|
11
|
+
import { VECTOR_MAX_DIM } from '../core/constants';
|
|
11
12
|
import { pgvectorPackMeta, pgvectorRuntimeOperation } from '../core/descriptor-meta';
|
|
12
13
|
|
|
13
14
|
const vectorTypeId = 'pg/vector@1' as const;
|
|
14
15
|
const vectorParamsSchema = arktype({
|
|
15
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}]`);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
16
26
|
});
|
|
17
27
|
|
|
18
28
|
/**
|