@prisma/orm-extension-pgvector 8.0.0-rc.18-dev.15 → 8.0.0-rc.18-dev.17
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/{codec-types-CehP5kSY-De2lhpKe.d.mts → codec-types-jJfLAH2N-DGxq6E1l.d.mts} +8 -9
- package/dist/{codec-types-CehP5kSY-De2lhpKe.d.mts.map → codec-types-jJfLAH2N-DGxq6E1l.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/control.mjs +1 -1
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-VztEZTmZ-CrowAvkB.mjs → descriptor-meta-D1aLKkOM-CVU7oPYH.mjs} +57 -55
- package/dist/descriptor-meta-D1aLKkOM-CVU7oPYH.mjs.map +1 -0
- package/dist/pack.d.mts +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/descriptor-meta-VztEZTmZ-CrowAvkB.mjs.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as VECTOR_CODEC_ID } from "./constants-BjLQgqqq-CMdE2ode.mjs";
|
|
2
|
-
import { AnyCodecDescriptor, CodecCallContext, CodecImpl, CodecInstanceContext } from "@prisma/orm-framework/components/codec";
|
|
2
|
+
import { AnyCodecDescriptor, CodecCallContext, CodecImpl, CodecInstanceContext, DataTypeValue } from "@prisma/orm-framework/components/codec";
|
|
3
3
|
import { ExtractCodecTypes, ProjectionExpr } from "@prisma/orm-family-sql/relational-core/ast";
|
|
4
4
|
import { PostgresCodecDescriptor } from "@prisma/orm-target-postgres/target/codec-descriptor";
|
|
5
|
-
import {
|
|
5
|
+
import { ParameterizedOutputTypesFunction } from "@prisma/orm-framework/contract/types";
|
|
6
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
|
-
//#region ../../../3-extensions/pgvector/dist/codec-types-
|
|
7
|
+
//#region ../../../3-extensions/pgvector/dist/codec-types-jJfLAH2N.d.mts
|
|
8
8
|
//#region src/core/codecs.d.ts
|
|
9
9
|
type VectorConversionCode = 'RUNTIME.ENCODE_FAILED' | 'RUNTIME.DECODE_FAILED';
|
|
10
10
|
type VectorParams = {
|
|
@@ -14,11 +14,10 @@ declare class PgVectorCodec extends CodecImpl<typeof VECTOR_CODEC_ID, readonly [
|
|
|
14
14
|
readonly length: number;
|
|
15
15
|
constructor(descriptor: AnyCodecDescriptor, length: number);
|
|
16
16
|
assertVector(value: unknown, code: VectorConversionCode): asserts value is number[];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
private refuseJson;
|
|
17
|
+
toWire(value: number[], _ctx: CodecCallContext): Promise<string>;
|
|
18
|
+
fromWire(wire: string, _ctx: CodecCallContext): Promise<number[]>;
|
|
19
|
+
fromDataTypeValue(value: DataTypeValue<readonly number[]>): number[];
|
|
20
|
+
toDataTypeValue(input: number[]): DataTypeValue;
|
|
22
21
|
}
|
|
23
22
|
declare class PgVectorDescriptor extends PostgresCodecDescriptor<VectorParams> {
|
|
24
23
|
protected jsonProjection(expression: ProjectionExpr): ProjectionExpr;
|
|
@@ -57,4 +56,4 @@ interface ParameterizedOutputTypesForTypeParams extends ParameterizedOutputTypes
|
|
|
57
56
|
}
|
|
58
57
|
//#endregion
|
|
59
58
|
export { ParameterizedOutputTypesForTypeParams as n, Vector as r, CodecTypes as t };
|
|
60
|
-
//# sourceMappingURL=codec-types-
|
|
59
|
+
//# sourceMappingURL=codec-types-jJfLAH2N-DGxq6E1l.d.mts.map
|
package/dist/{codec-types-CehP5kSY-De2lhpKe.d.mts.map → codec-types-jJfLAH2N-DGxq6E1l.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-
|
|
1
|
+
{"version":3,"file":"codec-types-jJfLAH2N-DGxq6E1l.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/codec-types-jJfLAH2N.d.mts"],"mappings":";;;;;;;;KAOK;KACA;WACM;;cAEG,sBAAsB,iBAAiB;WAC1C;EACT,YAAY,YAAY,oBAAoB;EAC5C,aAAa,gBAAgB,MAAM,+BAA+B;EAClE,OAAO,iBAAiB,MAAM,mBAAmB;EACjD,SAAS,cAAc,MAAM,mBAAmB;EAChD,kBAAkB,OAAO;EACzB,gBAAgB,kBAAkB;;cAEtB,2BAA2B,wBAAwB;YACrD,eAAe,YAAY,iBAAiB;WAC7C,yDAAyD;WACzD;WACA;WACA,cAAc,iBAAiB;EACxC,QAAQ,QAAQ,gBAAgB,KAAK,yBAAyB;;cAElD;WACH,QAAQ;;KAEd,eAAe,yBAAyB;;;;;;;;;KASxC,OAAO;WACD,iBAAiB;;KAEvB,aAAa;KACb,cAAc;WACR,eAAe;aACb,cAAc;MACrB,OAAO;;;;;UAKH,8CAA8C;WAC7C,aAAa"}
|
package/dist/codec-types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as ParameterizedOutputTypesForTypeParams, r as Vector, t as CodecTypes } from "./codec-types-
|
|
1
|
+
import { n as ParameterizedOutputTypesForTypeParams, r as Vector, t as CodecTypes } from "./codec-types-jJfLAH2N-DGxq6E1l.mjs";
|
|
2
2
|
export type { CodecTypes, ParameterizedOutputTypesForTypeParams, Vector };
|
package/dist/control.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as pgvectorPackMeta, r as pgvectorQueryOperations } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorPackMeta, r as pgvectorQueryOperations } from "./descriptor-meta-D1aLKkOM-CVU7oPYH.mjs";
|
|
2
2
|
import { contractSpaceFromJson } from "@prisma/orm-toolchain/migration-tools/spaces";
|
|
3
3
|
//#region ../../../3-extensions/pgvector/dist/control.mjs
|
|
4
4
|
var migration_default = {
|
package/dist/control.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/control.mjs"],"sourcesContent":["import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from \"./descriptor-meta-
|
|
1
|
+
{"version":3,"file":"control.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/control.mjs"],"sourcesContent":["import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from \"./descriptor-meta-D1aLKkOM.mjs\";\nimport { contractSpaceFromJson } from \"@internal/migration-tools/spaces\";\n//#region migrations/20260601T0000_install_vector_extension/migration.json\nvar migration_default = {\n\tfrom: null,\n\tto: \"4a96b488a4ce92b434e5f7d6607b6435c0955f0d36b0018077045787764240e6\",\n\tprovidedInvariants: [\"pgvector:install-vector-v1\"],\n\tcreatedAt: \"2026-06-01T00:00:00.000Z\",\n\tmigrationHash: \"ae458aa8c484439df5d79fdfbbe907a3ab7e53b25c79259a95909ab3c61d9a66\"\n};\n//#endregion\n//#region migrations/20260601T0000_install_vector_extension/ops.json\nvar ops_default = [{\n\t\"id\": \"pgvector.install-vector-extension\",\n\t\"label\": \"Enable extension \\\"vector\\\"\",\n\t\"operationClass\": \"additive\",\n\t\"invariantId\": \"pgvector:install-vector-v1\",\n\t\"target\": {\n\t\t\"id\": \"postgres\",\n\t\t\"details\": {\n\t\t\t\"schema\": \"public\",\n\t\t\t\"objectType\": \"dependency\",\n\t\t\t\"name\": \"vector\"\n\t\t}\n\t},\n\t\"precheck\": [{\n\t\t\"description\": \"verify extension \\\"vector\\\" is not already enabled\",\n\t\t\"sql\": \"SELECT NOT EXISTS (SELECT 1 AS \\\"one\\\" FROM \\\"pg_extension\\\" WHERE \\\"extname\\\" = $1) AS \\\"result\\\"\",\n\t\t\"params\": [\"vector\"]\n\t}],\n\t\"execute\": [{\n\t\t\"description\": \"create extension \\\"vector\\\"\",\n\t\t\"sql\": \"CREATE EXTENSION IF NOT EXISTS vector\"\n\t}],\n\t\"postcheck\": [{\n\t\t\"description\": \"confirm extension \\\"vector\\\" is enabled\",\n\t\t\"sql\": \"SELECT EXISTS (SELECT 1 AS \\\"one\\\" FROM \\\"pg_extension\\\" WHERE \\\"extname\\\" = $1) AS \\\"result\\\"\",\n\t\t\"params\": [\"vector\"]\n\t}]\n}];\n//#endregion\n//#region migrations/refs/head.json\nvar head_default = {\n\thash: \"4a96b488a4ce92b434e5f7d6607b6435c0955f0d36b0018077045787764240e6\",\n\tinvariants: [\"pgvector:install-vector-v1\"]\n};\n//#endregion\n//#region src/contract.json\nvar contract_default = {\n\tschemaVersion: \"1\",\n\ttargetFamily: \"sql\",\n\ttarget: \"postgres\",\n\tprofileHash: \"3916f444a8a17ad749191acf9e08dad97d1a327b88c2f1d45d12f240296aa8b2\",\n\troots: {},\n\tdomain: { \"namespaces\": { \"public\": { \"models\": {} } } },\n\tstorage: {\n\t\t\"namespaces\": { \"public\": {\n\t\t\t\"entries\": { \"table\": {} },\n\t\t\t\"id\": \"public\",\n\t\t\t\"kind\": \"postgres-schema\"\n\t\t} },\n\t\t\"storageHash\": \"4a96b488a4ce92b434e5f7d6607b6435c0955f0d36b0018077045787764240e6\",\n\t\t\"types\": { \"vector\": {\n\t\t\t\"codecId\": \"pg/vector@1\",\n\t\t\t\"dataType\": \"pgvector/vector\",\n\t\t\t\"kind\": \"codec-instance\"\n\t\t} }\n\t},\n\tcapabilities: {\n\t\t\"postgres\": {\n\t\t\t\"distinctOn\": true,\n\t\t\t\"forKeyShare\": true,\n\t\t\t\"forNoKeyUpdate\": true,\n\t\t\t\"jsonAgg\": true,\n\t\t\t\"lateral\": true,\n\t\t\t\"limit\": true,\n\t\t\t\"orderBy\": true,\n\t\t\t\"returning\": true\n\t\t},\n\t\t\"sql\": {\n\t\t\t\"checkConstraint\": true,\n\t\t\t\"defaultInInsert\": true,\n\t\t\t\"enums\": true,\n\t\t\t\"forShare\": true,\n\t\t\t\"forUpdate\": true,\n\t\t\t\"insertOnConflictSkip\": true,\n\t\t\t\"insertOnConflictWithoutTarget\": true,\n\t\t\t\"lateral\": true,\n\t\t\t\"lockNowait\": true,\n\t\t\t\"lockOf\": true,\n\t\t\t\"lockSkipLocked\": true,\n\t\t\t\"returning\": true,\n\t\t\t\"scalarList\": true\n\t\t}\n\t},\n\textensions: {},\n\tmeta: {},\n\t_generated: {\n\t\t\"warning\": \"⚠️ GENERATED FILE - DO NOT EDIT\",\n\t\t\"message\": \"This file is automatically generated by \\\"prisma contract emit\\\".\",\n\t\t\"regenerate\": \"To regenerate, run: prisma contract emit\"\n\t}\n};\n//#endregion\n//#region src/core/contract-space-constants.ts\n/**\n* Static names and identifiers used across pgvector's contract space.\n*\n* Centralised here so the contract IR (`./contract`), the baseline\n* migration ops (`./migrations`), the head ref, and the descriptor\n* (`../exports/control`) all reference the same values without typos.\n*\n* The space identifier `'pgvector'` is what the framework writes to\n* `migrations/` in the user's repo and what the marker table's\n* `space` column carries for pgvector-owned rows.\n*\n* The `pgvector:*` invariantId namespace is locked here — once\n* published, an invariantId is immutable so downstream consumers can\n* reference it by literal string match.\n*/\nconst PGVECTOR_SPACE_ID = \"pgvector\";\n//#endregion\n//#region src/exports/control.ts\nconst PGVECTOR_CODEC_ID = \"pg/vector@1\";\nconst BASELINE_DIR_NAME = \"20260601T0000_install_vector_extension\";\nfunction buildVectorIdentityValue(typeParams) {\n\tconst length = typeParams?.[\"length\"];\n\tif (typeof length !== \"number\" || !Number.isInteger(length) || length <= 0) return null;\n\treturn `'${`[${new Array(length).fill(\"0\").join(\",\")}]`}'::vector`;\n}\nconst vectorControlPlaneHooks = { resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams) };\nconst pgvectorContractSpace = contractSpaceFromJson({\n\tcontractJson: contract_default,\n\tmigrations: [{\n\t\tdirName: BASELINE_DIR_NAME,\n\t\tmetadata: migration_default,\n\t\tops: ops_default\n\t}],\n\theadRef: head_default\n});\nconst pgvectorExtensionDescriptor = {\n\t...pgvectorPackMeta,\n\tid: PGVECTOR_SPACE_ID,\n\tcontractSpace: pgvectorContractSpace,\n\ttypes: {\n\t\t...pgvectorPackMeta.types,\n\t\tcodecTypes: {\n\t\t\t...pgvectorPackMeta.types.codecTypes,\n\t\t\tcontrolPlaneHooks: { [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks }\n\t\t}\n\t},\n\tqueryOperations: () => pgvectorQueryOperations(),\n\tcreate: () => ({\n\t\tfamilyId: \"sql\",\n\t\ttargetId: \"postgres\"\n\t})\n};\n//#endregion\nexport { pgvectorExtensionDescriptor as default, pgvectorExtensionDescriptor };\n\n//# sourceMappingURL=control.mjs.map"],"mappings":";;;AAGA,IAAI,oBAAoB;CACvB,MAAM;CACN,IAAI;CACJ,oBAAoB,CAAC,4BAA4B;CACjD,WAAW;CACX,eAAe;AAChB;AAGA,IAAI,cAAc,CAAC;CAClB,MAAM;CACN,SAAS;CACT,kBAAkB;CAClB,eAAe;CACf,UAAU;EACT,MAAM;EACN,WAAW;GACV,UAAU;GACV,cAAc;GACd,QAAQ;EACT;CACD;CACA,YAAY,CAAC;EACZ,eAAe;EACf,OAAO;EACP,UAAU,CAAC,QAAQ;CACpB,CAAC;CACD,WAAW,CAAC;EACX,eAAe;EACf,OAAO;CACR,CAAC;CACD,aAAa,CAAC;EACb,eAAe;EACf,OAAO;EACP,UAAU,CAAC,QAAQ;CACpB,CAAC;AACF,CAAC;AAGD,IAAI,eAAe;CAClB,MAAM;CACN,YAAY,CAAC,4BAA4B;AAC1C;AAGA,IAAI,mBAAmB;CACtB,eAAe;CACf,cAAc;CACd,QAAQ;CACR,aAAa;CACb,OAAO,CAAC;CACR,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE;CACvD,SAAS;EACR,cAAc,EAAE,UAAU;GACzB,WAAW,EAAE,SAAS,CAAC,EAAE;GACzB,MAAM;GACN,QAAQ;EACT,EAAE;EACF,eAAe;EACf,SAAS,EAAE,UAAU;GACpB,WAAW;GACX,YAAY;GACZ,QAAQ;EACT,E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ENAMED
|
@@ -4,12 +4,12 @@ import { CodecImpl, isNonFiniteText, refuseJsonValue } from "@prisma/orm-framewo
|
|
|
4
4
|
import { sqlDataType } from "@prisma/orm-family-sql/contract/data-type";
|
|
5
5
|
import { pgInt2, pgInt4, pgInt8, pgNumeric } from "@prisma/orm-target-postgres/target/data-types";
|
|
6
6
|
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
7
|
+
import { counted } from "@prisma/orm-framework/utils/text";
|
|
7
8
|
import { type } from "arktype";
|
|
8
9
|
import { buildCodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/codec-descriptor-registry";
|
|
9
|
-
import { CastExpr
|
|
10
|
+
import { CastExpr } from "@prisma/orm-family-sql/relational-core/ast";
|
|
10
11
|
import { PostgresCodecDescriptor, definePostgresCodecs } from "@prisma/orm-target-postgres/target/codec-descriptor";
|
|
11
|
-
|
|
12
|
-
//#region ../../../3-extensions/pgvector/dist/descriptor-meta-VztEZTmZ.mjs
|
|
12
|
+
//#region ../../../3-extensions/pgvector/dist/descriptor-meta-D1aLKkOM.mjs
|
|
13
13
|
const pgvectorAuthoringTypes = { pgvector: { Vector: {
|
|
14
14
|
kind: "typeConstructor",
|
|
15
15
|
inferred: true,
|
|
@@ -37,29 +37,38 @@ function elementNumber(element) {
|
|
|
37
37
|
fix: "Use a finite number for every element."
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const pgvectorVectorParams = type({ length: `number.integer >= 1 & number.integer <= ${VECTOR_MAX_DIM}` });
|
|
41
|
+
/** A `vector(n)` value is an array of exactly `n` finite numbers, each one a `real` holds exactly. */
|
|
42
42
|
function isFiniteNumber(element) {
|
|
43
43
|
return typeof element === "number" && Number.isFinite(element);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
fix: "Write the vector as an array of numbers, as in [1, 2, 3]."
|
|
58
|
-
});
|
|
45
|
+
const readVector = (json, params) => {
|
|
46
|
+
const length = typeof params["length"] === "number" ? params["length"] : void 0;
|
|
47
|
+
const expected = length === void 0 ? "an array of finite numbers" : `an array of ${counted(length, "finite number")}`;
|
|
48
|
+
if (!Array.isArray(json) || length !== void 0 && json.length !== length) return refuseJsonValue("pgvector/vector", expected, json);
|
|
49
|
+
if (!json.every(isFiniteNumber)) return refuseJsonValue("pgvector/vector", expected, json);
|
|
50
|
+
for (const [index, element] of json.entries()) {
|
|
51
|
+
const refuse = (why) => refuseJsonValue("pgvector/vector", `an array of numbers real holds exactly; element ${index + 1}, ${element}, ${why}`, json);
|
|
52
|
+
if (!Number.isFinite(Math.fround(element))) return refuse("is outside the range real holds, which PostgreSQL refuses");
|
|
53
|
+
const stored = realText(element);
|
|
54
|
+
if (Number(stored) !== element) return refuse(`would be stored as ${stored}`);
|
|
55
|
+
}
|
|
56
|
+
return json;
|
|
59
57
|
};
|
|
60
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The text PostgreSQL prints for `value` stored as a `real`, which is what a row reads back: the shortest decimal that reads back as the same single-precision number.
|
|
60
|
+
*/
|
|
61
|
+
function realText(value) {
|
|
62
|
+
const single = Math.fround(value);
|
|
63
|
+
for (let digits = 1; digits <= 9; digits++) {
|
|
64
|
+
const text = String(Number(single.toPrecision(digits)));
|
|
65
|
+
if (Math.fround(Number(text)) === single) return text;
|
|
66
|
+
}
|
|
67
|
+
return String(single);
|
|
68
|
+
}
|
|
61
69
|
const pgvectorVector = sqlDataType("pgvector/vector", {
|
|
62
70
|
params: pgvectorVectorParams,
|
|
71
|
+
read: readVector,
|
|
63
72
|
texts: [{
|
|
64
73
|
text: "vector({length})",
|
|
65
74
|
written: true,
|
|
@@ -73,13 +82,23 @@ const pgvectorVector = sqlDataType("pgvector/vector", {
|
|
|
73
82
|
pgNumeric.id
|
|
74
83
|
],
|
|
75
84
|
cast: (elements) => elements.map(elementNumber)
|
|
76
|
-
}
|
|
77
|
-
toCanonicalForm: vectorCanonicalForm
|
|
85
|
+
}
|
|
78
86
|
});
|
|
79
87
|
const pgvectorDataTypes = [pgvectorVector];
|
|
80
88
|
function pgVectorError(code, message, options) {
|
|
81
89
|
return structuredError(code, message, options);
|
|
82
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* pgvector extension codec.
|
|
93
|
+
*
|
|
94
|
+
* Mirrors the patterns in `postgres/codecs-class.ts` and `sqlite/codecs-class.ts` for the single `pg/vector@1` codec. Three artifacts:
|
|
95
|
+
*
|
|
96
|
+
* 1. `PgVectorCodec` extends {@link CodecImpl} with the wire and value conversions inline. Conversions are simple enough (PostgreSQL `[1,2,3]` text format) that no shared helper module is warranted; the class body is the source of truth.
|
|
97
|
+
* 2. `PgVectorDescriptor` extends {@link PostgresCodecDescriptor} with the codec id, traits, the `pgvector/vector` data type and its params schema, and explicit target behavior. The column's type, `Vector<${length}>`, comes from the pack's type function in `types/codec-types.ts`. The data type declares the type's name and the bounds of `length`.
|
|
98
|
+
* 3. `pgVectorColumn(length)` per-codec column helper invoking `descriptor.factory({ length })` directly.
|
|
99
|
+
*
|
|
100
|
+
* `length` threads into the runtime codec via the constructor so the wire methods enforce the declared dimension, and `pgvector/vector` checks it for every stored value. Without this, `vector(3)` and `vector(1536)` would produce codecs with identical behaviour and a dimension-mismatched value would round-trip undetected.
|
|
101
|
+
*/
|
|
83
102
|
function parseVector(value) {
|
|
84
103
|
if (!value.startsWith("[") || !value.endsWith("]")) throw pgVectorError("RUNTIME.DECODE_FAILED", `Invalid vector format: expected "[...]", got "${value}"`, {
|
|
85
104
|
why: "The database returned a vector value that is not in the PostgreSQL \"[x,y,z]\" text format.",
|
|
@@ -104,7 +123,7 @@ function parseVector(value) {
|
|
|
104
123
|
var PgVectorCodec = class extends CodecImpl {
|
|
105
124
|
length;
|
|
106
125
|
constructor(descriptor, length) {
|
|
107
|
-
super(descriptor);
|
|
126
|
+
super(descriptor, pgvectorVector, { length });
|
|
108
127
|
this.length = length;
|
|
109
128
|
}
|
|
110
129
|
assertVector(value, code) {
|
|
@@ -125,52 +144,35 @@ var PgVectorCodec = class extends CodecImpl {
|
|
|
125
144
|
}
|
|
126
145
|
});
|
|
127
146
|
}
|
|
128
|
-
async
|
|
147
|
+
async toWire(value, _ctx) {
|
|
129
148
|
this.assertVector(value, "RUNTIME.ENCODE_FAILED");
|
|
130
149
|
return `[${value.join(",")}]`;
|
|
131
150
|
}
|
|
132
|
-
async
|
|
151
|
+
async fromWire(wire, _ctx) {
|
|
133
152
|
if (typeof wire !== "string") throw pgVectorError("RUNTIME.DECODE_FAILED", "Vector wire value must be a string", { meta: { codecId: VECTOR_CODEC_ID } });
|
|
134
153
|
const value = parseVector(wire);
|
|
135
154
|
this.assertVector(value, "RUNTIME.DECODE_FAILED");
|
|
136
155
|
return value;
|
|
137
156
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return [...value];
|
|
141
|
-
}
|
|
142
|
-
decodeJson(json) {
|
|
143
|
-
if (!Array.isArray(json) || json.length !== this.length) return this.refuseJson(json);
|
|
144
|
-
const numbers = [];
|
|
145
|
-
for (const element of json) {
|
|
146
|
-
if (typeof element !== "number" || !Number.isFinite(element)) return this.refuseJson(json);
|
|
147
|
-
numbers.push(element);
|
|
148
|
-
}
|
|
149
|
-
return numbers;
|
|
157
|
+
fromDataTypeValue(value) {
|
|
158
|
+
return [...value.value];
|
|
150
159
|
}
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
toDataTypeValue(input) {
|
|
161
|
+
this.assertVector(input, "RUNTIME.ENCODE_FAILED");
|
|
162
|
+
return this.dataTypeValueOf([...input]);
|
|
153
163
|
}
|
|
154
164
|
};
|
|
155
165
|
/**
|
|
156
|
-
* Projects a `vector` as
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* The route matters as much as the destination. A vector's elements are `real`,
|
|
163
|
-
* and its text form prints the shortest decimal that round-trips *as a `real`* —
|
|
164
|
-
* `0.1` for a value the application holds as `0.10000000149011612`. Reading that
|
|
165
|
-
* text back as a double therefore lands on a different number, so casting the
|
|
166
|
-
* text to `json` would lose precision the value still had. Widening each element
|
|
167
|
-
* to `float8` first keeps the exact value the `real` denotes, which is what
|
|
168
|
-
* `encodeJson` returns.
|
|
166
|
+
* Projects a `vector` as the text PostgreSQL prints for it, the value the runtime driver returns for
|
|
167
|
+
* an ordinary row, so `fromWire` reads an included vector as it reads a row. A JSON array of the
|
|
168
|
+
* elements would not do: an element is a `real`, and the text holds the shortest decimal that
|
|
169
|
+
* reads back as that `real`, so the row reads `0.1` where the element widened to a double is
|
|
170
|
+
* `0.10000000149011612`.
|
|
169
171
|
*/
|
|
170
|
-
const
|
|
172
|
+
const vectorTextJsonProjection = (expression) => CastExpr.as(expression, "text");
|
|
171
173
|
var PgVectorDescriptor = class extends PostgresCodecDescriptor {
|
|
172
174
|
jsonProjection(expression) {
|
|
173
|
-
return
|
|
175
|
+
return vectorTextJsonProjection(expression);
|
|
174
176
|
}
|
|
175
177
|
dataType = pgvectorVector.id;
|
|
176
178
|
codecId = VECTOR_CODEC_ID;
|
|
@@ -266,4 +268,4 @@ const pgvectorPackMeta = {
|
|
|
266
268
|
//#endregion
|
|
267
269
|
export { pgvectorPackMeta as n, pgvectorQueryOperations as r, pgvectorCodecRegistry as t };
|
|
268
270
|
|
|
269
|
-
//# sourceMappingURL=descriptor-meta-
|
|
271
|
+
//# sourceMappingURL=descriptor-meta-D1aLKkOM-CVU7oPYH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-D1aLKkOM-CVU7oPYH.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/descriptor-meta-D1aLKkOM.mjs"],"sourcesContent":["import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from \"./constants-D8Ccy-f4.mjs\";\nimport { buildOperation, codecOf, toExpr } from \"@internal/sql-relational-core/expression\";\nimport { CodecImpl, isNonFiniteText, refuseJsonValue } from \"@internal/framework-components/codec\";\nimport { sqlDataType } from \"@internal/sql-contract/data-type\";\nimport { pgInt2, pgInt4, pgInt8, pgNumeric } from \"@internal/target-postgres/data-types\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { counted } from \"@internal/utils/text\";\nimport { type } from \"arktype\";\nimport { buildCodecDescriptorRegistry } from \"@internal/sql-relational-core/codec-descriptor-registry\";\nimport { CastExpr } from \"@internal/sql-relational-core/ast\";\nimport { PostgresCodecDescriptor, definePostgresCodecs } from \"@internal/target-postgres/codec-descriptor\";\n//#region src/core/authoring.ts\nconst pgvectorAuthoringTypes = { pgvector: { Vector: {\n\tkind: \"typeConstructor\",\n\tinferred: true,\n\targs: [{\n\t\tkind: \"number\",\n\t\tname: \"length\",\n\t\tinteger: true\n\t}],\n\toutput: {\n\t\tcodecId: \"pg/vector@1\",\n\t\ttypeParams: { length: {\n\t\t\tkind: \"arg\",\n\t\t\tindex: 0\n\t\t} }\n\t}\n} } };\n//#endregion\n//#region src/core/data-types.ts\nfunction elementNumber(element) {\n\tif (typeof element === \"number\") return element;\n\tif (typeof element === \"string\" && !isNonFiniteText(element)) {\n\t\tconst converted = Number(element);\n\t\tif (Number.isFinite(converted)) return converted;\n\t}\n\tthrow structuredError(\"CONTRACT.CAST_REFUSED\", `A vector holds finite numbers, and ${JSON.stringify(element)} is not one.`, {\n\t\twhy: \"A vector element is a finite number; NaN and the two infinities have no place in one.\",\n\t\tfix: \"Use a finite number for every element.\"\n\t});\n}\nconst pgvectorVectorParams = type({ length: `number.integer >= 1 & number.integer <= ${VECTOR_MAX_DIM}` });\n/** A `vector(n)` value is an array of exactly `n` finite numbers, each one a `real` holds exactly. */\nfunction isFiniteNumber(element) {\n\treturn typeof element === \"number\" && Number.isFinite(element);\n}\nconst readVector = (json, params) => {\n\tconst length = typeof params[\"length\"] === \"number\" ? params[\"length\"] : void 0;\n\tconst expected = length === void 0 ? \"an array of finite numbers\" : `an array of ${counted(length, \"finite number\")}`;\n\tif (!Array.isArray(json) || length !== void 0 && json.length !== length) return refuseJsonValue(\"pgvector/vector\", expected, json);\n\tif (!json.every(isFiniteNumber)) return refuseJsonValue(\"pgvector/vector\", expected, json);\n\tfor (const [index, element] of json.entries()) {\n\t\tconst refuse = (why) => refuseJsonValue(\"pgvector/vector\", `an array of numbers real holds exactly; element ${index + 1}, ${element}, ${why}`, json);\n\t\tif (!Number.isFinite(Math.fround(element))) return refuse(\"is outside the range real holds, which PostgreSQL refuses\");\n\t\tconst stored = realText(element);\n\t\tif (Number(stored) !== element) return refuse(`would be stored as ${stored}`);\n\t}\n\treturn json;\n};\n/**\n* The text PostgreSQL prints for `value` stored as a `real`, which is what a row reads back: the shortest decimal that reads back as the same single-precision number.\n*/\nfunction realText(value) {\n\tconst single = Math.fround(value);\n\tfor (let digits = 1; digits <= 9; digits++) {\n\t\tconst text = String(Number(single.toPrecision(digits)));\n\t\tif (Math.fround(Number(text)) === single) return text;\n\t}\n\treturn String(single);\n}\nconst pgvectorVector = sqlDataType(\"pgvector/vector\", {\n\tparams: pgvectorVectorParams,\n\tread: readVector,\n\ttexts: [{\n\t\ttext: \"vector({length})\",\n\t\twritten: true,\n\t\tcatalog: true\n\t}],\n\tlistCast: {\n\t\tof: [\n\t\t\tpgInt2.id,\n\t\t\tpgInt4.id,\n\t\t\tpgInt8.id,\n\t\t\tpgNumeric.id\n\t\t],\n\t\tcast: (elements) => elements.map(elementNumber)\n\t}\n});\nconst pgvectorDataTypes = [pgvectorVector];\n//#endregion\n//#region src/core/errors.ts\nfunction pgVectorError(code, message, options) {\n\treturn structuredError(code, message, options);\n}\n//#endregion\n//#region src/core/codecs.ts\n/**\n* pgvector extension codec.\n*\n* Mirrors the patterns in `postgres/codecs-class.ts` and `sqlite/codecs-class.ts` for the single `pg/vector@1` codec. Three artifacts:\n*\n* 1. `PgVectorCodec` extends {@link CodecImpl} with the wire and value conversions inline. Conversions are simple enough (PostgreSQL `[1,2,3]` text format) that no shared helper module is warranted; the class body is the source of truth.\n* 2. `PgVectorDescriptor` extends {@link PostgresCodecDescriptor} with the codec id, traits, the `pgvector/vector` data type and its params schema, and explicit target behavior. The column's type, `Vector<${length}>`, comes from the pack's type function in `types/codec-types.ts`. The data type declares the type's name and the bounds of `length`.\n* 3. `pgVectorColumn(length)` per-codec column helper invoking `descriptor.factory({ length })` directly.\n*\n* `length` threads into the runtime codec via the constructor so the wire methods enforce the declared dimension, and `pgvector/vector` checks it for every stored value. Without this, `vector(3)` and `vector(1536)` would produce codecs with identical behaviour and a dimension-mismatched value would round-trip undetected.\n*/\nfunction parseVector(value) {\n\tif (!value.startsWith(\"[\") || !value.endsWith(\"]\")) throw pgVectorError(\"RUNTIME.DECODE_FAILED\", `Invalid vector format: expected \"[...]\", got \"${value}\"`, {\n\t\twhy: \"The database returned a vector value that is not in the PostgreSQL \\\"[x,y,z]\\\" text format.\",\n\t\tmeta: {\n\t\t\tcodecId: VECTOR_CODEC_ID,\n\t\t\twirePreview: value\n\t\t}\n\t});\n\tconst content = value.slice(1, -1).trim();\n\treturn content === \"\" ? [] : content.split(\",\").map((entry) => {\n\t\tconst number = Number.parseFloat(entry.trim());\n\t\tif (Number.isNaN(number)) throw pgVectorError(\"RUNTIME.DECODE_FAILED\", `Invalid vector value: \"${entry}\" is not a number`, {\n\t\t\twhy: \"A vector entry returned by the database could not be parsed as a number.\",\n\t\t\tmeta: {\n\t\t\t\tcodecId: VECTOR_CODEC_ID,\n\t\t\t\twirePreview: value\n\t\t\t}\n\t\t});\n\t\treturn number;\n\t});\n}\nvar PgVectorCodec = class extends CodecImpl {\n\tlength;\n\tconstructor(descriptor, length) {\n\t\tsuper(descriptor, pgvectorVector, { length });\n\t\tthis.length = length;\n\t}\n\tassertVector(value, code) {\n\t\tconst meta = {\n\t\t\tcodecId: VECTOR_CODEC_ID,\n\t\t\texpectedLength: this.length\n\t\t};\n\t\tif (!Array.isArray(value)) throw pgVectorError(code, \"Vector value must be an array of numbers\", { meta });\n\t\tfor (const element of value) {\n\t\t\tif (typeof element !== \"number\") throw pgVectorError(code, \"Vector value must contain only numbers\", { meta });\n\t\t\tif (!Number.isFinite(element)) throw pgVectorError(code, \"Vector value must contain only finite numbers\", { meta });\n\t\t}\n\t\tif (value.length !== this.length) throw pgVectorError(code, `Vector length mismatch: expected ${this.length}, got ${value.length}`, {\n\t\t\twhy: `This column is declared as vector(${this.length}); every value must have exactly that many dimensions.`,\n\t\t\tmeta: {\n\t\t\t\t...meta,\n\t\t\t\treceivedLength: value.length\n\t\t\t}\n\t\t});\n\t}\n\tasync toWire(value, _ctx) {\n\t\tthis.assertVector(value, \"RUNTIME.ENCODE_FAILED\");\n\t\treturn `[${value.join(\",\")}]`;\n\t}\n\tasync fromWire(wire, _ctx) {\n\t\tif (typeof wire !== \"string\") throw pgVectorError(\"RUNTIME.DECODE_FAILED\", \"Vector wire value must be a string\", { meta: { codecId: VECTOR_CODEC_ID } });\n\t\tconst value = parseVector(wire);\n\t\tthis.assertVector(value, \"RUNTIME.DECODE_FAILED\");\n\t\treturn value;\n\t}\n\tfromDataTypeValue(value) {\n\t\treturn [...value.value];\n\t}\n\ttoDataTypeValue(input) {\n\t\tthis.assertVector(input, \"RUNTIME.ENCODE_FAILED\");\n\t\treturn this.dataTypeValueOf([...input]);\n\t}\n};\n/**\n* Projects a `vector` as the text PostgreSQL prints for it, the value the runtime driver returns for\n* an ordinary row, so `fromWire` reads an included vector as it reads a row. A JSON array of the\n* elements would not do: an element is a `real`, and the text holds the shortest decimal that\n* reads back as that `real`, so the row reads `0.1` where the element widened to a double is\n* `0.10000000149011612`.\n*/\nconst vectorTextJsonProjection = (expression) => CastExpr.as(expression, \"text\");\nvar PgVectorDescriptor = class extends PostgresCodecDescriptor {\n\tjsonProjection(expression) {\n\t\treturn vectorTextJsonProjection(expression);\n\t}\n\tdataType = pgvectorVector.id;\n\tcodecId = VECTOR_CODEC_ID;\n\ttraits = [\"equality\"];\n\tparamsSchema = pgvectorVectorParams;\n\tfactory(params) {\n\t\treturn () => new PgVectorCodec(this, params.length);\n\t}\n};\nconst codecDescriptorMap = { vector: new PgVectorDescriptor() };\n//#endregion\n//#region src/core/registry.ts\n/**\n* Registry of every codec descriptor shipped by `@internal/extension-pgvector`.\n*\n* Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.\n*/\nconst pgvectorCodecRegistry = buildCodecDescriptorRegistry(definePostgresCodecs(Object.values(codecDescriptorMap)));\n//#endregion\n//#region src/core/descriptor-meta.ts\nconst pgvectorTypeId = \"pg/vector@1\";\nfunction pgvectorQueryOperations() {\n\treturn {\n\t\tcosineDistance: {\n\t\t\tself: { codecId: pgvectorTypeId },\n\t\t\timpl: (self, other) => {\n\t\t\t\tconst selfCodec = codecOf(self);\n\t\t\t\treturn buildOperation({\n\t\t\t\t\tmethod: \"cosineDistance\",\n\t\t\t\t\targs: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n\t\t\t\t\treturns: {\n\t\t\t\t\t\tcodecId: \"pg/float8@1\",\n\t\t\t\t\t\tnullable: false\n\t\t\t\t\t},\n\t\t\t\t\tlowering: {\n\t\t\t\t\t\ttargetFamily: \"sql\",\n\t\t\t\t\t\ttemplate: \"{{self}} <=> {{arg0}}\"\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcosineSimilarity: {\n\t\t\tself: { codecId: pgvectorTypeId },\n\t\t\timpl: (self, other) => {\n\t\t\t\tconst selfCodec = codecOf(self);\n\t\t\t\treturn buildOperation({\n\t\t\t\t\tmethod: \"cosineSimilarity\",\n\t\t\t\t\targs: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n\t\t\t\t\treturns: {\n\t\t\t\t\t\tcodecId: \"pg/float8@1\",\n\t\t\t\t\t\tnullable: false\n\t\t\t\t\t},\n\t\t\t\t\tlowering: {\n\t\t\t\t\t\ttargetFamily: \"sql\",\n\t\t\t\t\t\ttemplate: \"1 - ({{self}} <=> {{arg0}})\"\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n}\nconst pgvectorPackMeta = {\n\tkind: \"extension\",\n\tid: \"pgvector\",\n\tfamilyId: \"sql\",\n\ttargetId: \"postgres\",\n\tversion: \"0.0.1\",\n\tcapabilities: { postgres: { \"pgvector.cosine\": true } },\n\tauthoring: { type: pgvectorAuthoringTypes },\n\tdataTypes: pgvectorDataTypes,\n\ttypes: {\n\t\tcodecTypes: {\n\t\t\tcodecDescriptors: Array.from(pgvectorCodecRegistry.values()),\n\t\t\timport: {\n\t\t\t\tpackage: \"@internal/extension-pgvector/codec-types\",\n\t\t\t\tnamed: \"CodecTypes\",\n\t\t\t\talias: \"PgVectorTypes\"\n\t\t\t},\n\t\t\tparameterizedOutputTypes: {\n\t\t\t\tpackage: \"@internal/extension-pgvector/codec-types\",\n\t\t\t\tnamed: \"ParameterizedOutputTypesForTypeParams\",\n\t\t\t\talias: \"PgVectorParameterizedOutputTypes\"\n\t\t\t}\n\t\t},\n\t\toperationTypes: { import: {\n\t\t\tpackage: \"@internal/extension-pgvector/operation-types\",\n\t\t\tnamed: \"OperationTypes\",\n\t\t\talias: \"PgVectorOperationTypes\"\n\t\t} },\n\t\tqueryOperationTypes: { import: {\n\t\t\tpackage: \"@internal/extension-pgvector/operation-types\",\n\t\t\tnamed: \"QueryOperationTypes\",\n\t\t\talias: \"PgVectorQueryOperationTypes\"\n\t\t} }\n\t}\n};\n//#endregion\nexport { pgvectorQueryOperations as n, pgvectorCodecRegistry as r, pgvectorPackMeta as t };\n\n//# sourceMappingURL=descriptor-meta-D1aLKkOM.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,MAAM,yBAAyB,EAAE,UAAU,EAAE,QAAQ;CACpD,MAAM;CACN,UAAU;CACV,MAAM,CAAC;E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N,YAAY;GACX,kBAAkB,MAAM,KAAK,sBAAsB,OAAO,CAAC;GAC3D,QAAQ;IACP,SAAS;IACT,OAAO;IACP,OAAO;GACR;GACA,0BAA0B;IACzB,SAAS;IACT,OAAO;IACP,OAAO;GACR;EACD;EACA,gBAAgB,EAAE,QAAQ;GACzB,SAAS;GACT,OAAO;GACP,OAAO;EACR,EAAE;EACF,qBAAqB,EAAE,QAAQ;GAC9B,SAAS;GACT,OAAO;GACP,OAAO;EACR,EAAE;CACH;AACD"}
|
package/dist/pack.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ParameterizedOutputTypesForTypeParams, r as Vector, t as CodecTypes } from "./codec-types-
|
|
1
|
+
import { n as ParameterizedOutputTypesForTypeParams, r as Vector, t as CodecTypes } from "./codec-types-jJfLAH2N-DGxq6E1l.mjs";
|
|
2
2
|
import { n as QueryOperationTypesForCodecs } from "./operation-types-SKTIzyy9-DXQ_bE1A.mjs";
|
|
3
3
|
//#region ../../../3-extensions/pgvector/dist/pack.d.mts
|
|
4
4
|
//#region src/core/descriptor-meta.d.ts
|
package/dist/pack.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as pgvectorPackMeta } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorPackMeta } from "./descriptor-meta-D1aLKkOM-CVU7oPYH.mjs";
|
|
2
2
|
export { pgvectorPackMeta as default };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as VECTOR_CODEC_ID } from "./constants-BjLQgqqq-CMdE2ode.mjs";
|
|
2
|
-
import { r as Vector } from "./codec-types-
|
|
2
|
+
import { r as Vector } from "./codec-types-jJfLAH2N-DGxq6E1l.mjs";
|
|
3
3
|
import { SqlRuntimeExtensionDescriptor } from "@prisma/orm-family-sql/runtime";
|
|
4
4
|
import { CodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/query-lane-context";
|
|
5
5
|
import { CollectionMethodContributionType, CollectionMethodModelType } from "@prisma/orm-family-sql/relational-core/collection-methods";
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as pgvectorPackMeta, r as pgvectorQueryOperations, t as pgvectorCodecRegistry } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorPackMeta, r as pgvectorQueryOperations, t as pgvectorCodecRegistry } from "./descriptor-meta-D1aLKkOM-CVU7oPYH.mjs";
|
|
2
2
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
3
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
4
4
|
//#region ../../../3-extensions/pgvector/dist/runtime.mjs
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/runtime.mjs"],"sourcesContent":["import { n as pgvectorQueryOperations, r as pgvectorCodecRegistry, t as pgvectorPackMeta } from \"./descriptor-meta-
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/runtime.mjs"],"sourcesContent":["import { n as pgvectorQueryOperations, r as pgvectorCodecRegistry, t as pgvectorPackMeta } from \"./descriptor-meta-D1aLKkOM.mjs\";\nimport \"./constants-D8Ccy-f4.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { InternalError } from \"@internal/utils/internal-error\";\n//#region src/core/nearest-collection-method.ts\nfunction distanceTo(model, field, vector) {\n\tconst accessor = blindCast(model)[field];\n\tif (accessor === void 0) throw new InternalError(`The model accessor has no vector field \"${field}\".`);\n\treturn accessor.cosineDistance(vector);\n}\nfunction nearestMethod(field) {\n\treturn (collection, ...args) => {\n\t\tconst [vector, maxDistance] = blindCast(args);\n\t\tlet shared;\n\t\tconst distance = (model) => {\n\t\t\tshared ??= distanceTo(model, field, vector);\n\t\t\treturn shared;\n\t\t};\n\t\tconst ordered = collection.orderBy((model) => distance(model).asc());\n\t\treturn maxDistance === void 0 ? ordered : ordered.where((model) => distance(model).lt(maxDistance));\n\t};\n}\n/** The run-time half of `PgvectorNearestMethods`. */\nconst pgvectorNearestMethods = {\n\tid: \"pgvector/nearest\",\n\tmethodsFor: (model) => Object.fromEntries(Object.entries(model.fields).flatMap(([name, field]) => !field.many && field.type.kind === \"scalar\" && field.type.codecId === \"pg/vector@1\" ? [[`${name}_nearest`, nearestMethod(name)]] : []))\n};\n//#endregion\n//#region src/exports/runtime.ts\nconst pgvectorRuntimeDescriptor = {\n\tkind: \"extension\",\n\tid: pgvectorPackMeta.id,\n\tversion: pgvectorPackMeta.version,\n\tdataTypes: pgvectorPackMeta.dataTypes,\n\tfamilyId: \"sql\",\n\ttargetId: \"postgres\",\n\ttypes: { codecTypes: { codecDescriptors: Array.from(pgvectorCodecRegistry.values()) } },\n\tcodecs: () => Array.from(pgvectorCodecRegistry.values()),\n\tqueryOperations: () => pgvectorQueryOperations(),\n\tcollectionMethods: () => [pgvectorNearestMethods],\n\tcreate() {\n\t\treturn {\n\t\t\tfamilyId: \"sql\",\n\t\t\ttargetId: \"postgres\"\n\t\t};\n\t}\n};\n//#endregion\nexport { pgvectorRuntimeDescriptor as default, pgvectorCodecRegistry };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;AAKA,SAAS,WAAW,OAAO,OAAO,QAAQ;CACzC,MAAM,WAAW,UAAU,KAAK,CAAC,CAAC;CAClC,IAAI,aAAa,KAAK,GAAG,MAAM,IAAI,cAAc,2CAA2C,MAAM,GAAG;CACrG,OAAO,SAAS,eAAe,MAAM;AACtC;AACA,SAAS,cAAc,OAAO;CAC7B,QAAQ,YAAY,GAAG,SAAS;EAC/B,MAAM,CAAC,QAAQ,eAAe,UAAU,IAAI;EAC5C,IAAI;EACJ,MAAM,YAAY,UAAU;GAC3B,WAAW,WAAW,OAAO,OAAO,MAAM;GAC1C,OAAO;EACR;EACA,MAAM,UAAU,WAAW,SAAS,UAAU,SAAS,KAAK,CAAC,CAAC,IAAI,CAAC;EACnE,OAAO,gBAAgB,KAAK,IAAI,UAAU,QAAQ,OAAO,UAAU,SAAS,KAAK,CAAC,CAAC,GAAG,WAAW,CAAC;CACnG;AACD;;AAEA,MAAM,yBAAyB;CAC9B,IAAI;CACJ,aAAa,UAAU,OAAO,YAAY,OAAO,QAAQ,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,WAAW,CAAC,MAAM,QAAQ,MAAM,KAAK,SAAS,YAAY,MAAM,KAAK,YAAY,gBAAgB,CAAC,CAAC,GAAG,KAAK,WAAW,cAAc,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACzO;AAGA,MAAM,4BAA4B;CACjC,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,WAAW,iBAAiB;CAC5B,UAAU;CACV,UAAU;CACV,OAAO,EAAE,YAAY,EAAE,kBAAkB,MAAM,KAAK,sBAAsB,OAAO,CAAC,EAAE,EAAE;CACtF,cAAc,MAAM,KAAK,sBAAsB,OAAO,CAAC;CACvD,uBAAuB,wBAAwB;CAC/C,yBAAyB,CAAC,sBAAsB;CAChD,SAAS;EACR,OAAO;GACN,UAAU;GACV,UAAU;EACX;CACD;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-extension-pgvector",
|
|
3
|
-
"version": "8.0.0-rc.18-dev.
|
|
3
|
+
"version": "8.0.0-rc.18-dev.17",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@prisma/orm-family-sql": "8.0.0-rc.18-dev.
|
|
13
|
-
"@prisma/orm-framework": "8.0.0-rc.18-dev.
|
|
14
|
-
"@prisma/orm-toolchain": "8.0.0-rc.18-dev.
|
|
12
|
+
"@prisma/orm-family-sql": "8.0.0-rc.18-dev.17",
|
|
13
|
+
"@prisma/orm-framework": "8.0.0-rc.18-dev.17",
|
|
14
|
+
"@prisma/orm-toolchain": "8.0.0-rc.18-dev.17",
|
|
15
15
|
"@standard-schema/spec": "^1.1.0",
|
|
16
16
|
"arktype": "^2.2.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@internal/extension-pgvector": "8.0.0-rc.18-dev.
|
|
20
|
-
"@repo/tsconfig": "8.0.0-rc.18-dev.
|
|
21
|
-
"@repo/tsdown": "8.0.0-rc.18-dev.
|
|
22
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.
|
|
19
|
+
"@internal/extension-pgvector": "8.0.0-rc.18-dev.17",
|
|
20
|
+
"@repo/tsconfig": "8.0.0-rc.18-dev.17",
|
|
21
|
+
"@repo/tsdown": "8.0.0-rc.18-dev.17",
|
|
22
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.17",
|
|
23
23
|
"tsdown": "0.22.14",
|
|
24
24
|
"typescript": "5.9.3"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.
|
|
27
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.17",
|
|
28
28
|
"typescript": ">=5.9"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-VztEZTmZ-CrowAvkB.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/descriptor-meta-VztEZTmZ.mjs"],"sourcesContent":["import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from \"./constants-D8Ccy-f4.mjs\";\nimport { buildOperation, codecOf, toExpr } from \"@internal/sql-relational-core/expression\";\nimport { CodecImpl, isNonFiniteText, refuseJsonValue } from \"@internal/framework-components/codec\";\nimport { sqlDataType } from \"@internal/sql-contract/data-type\";\nimport { pgInt2, pgInt4, pgInt8, pgNumeric } from \"@internal/target-postgres/data-types\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { type } from \"arktype\";\nimport { buildCodecDescriptorRegistry } from \"@internal/sql-relational-core/codec-descriptor-registry\";\nimport { CastExpr, FunctionCallExpr } from \"@internal/sql-relational-core/ast\";\nimport { PostgresCodecDescriptor, definePostgresCodecs } from \"@internal/target-postgres/codec-descriptor\";\nimport { counted } from \"@internal/utils/text\";\n//#region src/core/authoring.ts\nconst pgvectorAuthoringTypes = { pgvector: { Vector: {\n\tkind: \"typeConstructor\",\n\tinferred: true,\n\targs: [{\n\t\tkind: \"number\",\n\t\tname: \"length\",\n\t\tinteger: true\n\t}],\n\toutput: {\n\t\tcodecId: \"pg/vector@1\",\n\t\ttypeParams: { length: {\n\t\t\tkind: \"arg\",\n\t\t\tindex: 0\n\t\t} }\n\t}\n} } };\n//#endregion\n//#region src/core/data-types.ts\nfunction elementNumber(element) {\n\tif (typeof element === \"number\") return element;\n\tif (typeof element === \"string\" && !isNonFiniteText(element)) {\n\t\tconst converted = Number(element);\n\t\tif (Number.isFinite(converted)) return converted;\n\t}\n\tthrow structuredError(\"CONTRACT.CAST_REFUSED\", `A vector holds finite numbers, and ${JSON.stringify(element)} is not one.`, {\n\t\twhy: \"A vector element is a finite number; NaN and the two infinities have no place in one.\",\n\t\tfix: \"Use a finite number for every element.\"\n\t});\n}\nconst PRINTED_VECTOR = /^\\[(.*)\\]$/s;\nconst PRINTED_ELEMENT = /^[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?$/;\nfunction isFiniteNumber(element) {\n\treturn typeof element === \"number\" && Number.isFinite(element);\n}\nfunction printedVector(text) {\n\tconst body = PRINTED_VECTOR.exec(text)?.[1]?.trim();\n\tif (body === void 0) return void 0;\n\tif (body === \"\") return [];\n\tconst entries = body.split(\",\").map((entry) => entry.trim());\n\treturn entries.every((entry) => PRINTED_ELEMENT.test(entry)) ? entries.map(Number) : void 0;\n}\nconst vectorCanonicalForm = (value) => {\n\tconst elements = typeof value === \"string\" ? printedVector(value) : value;\n\tif (Array.isArray(elements) && elements.every(isFiniteNumber)) return elements.map((element) => Object.is(element, -0) ? 0 : element);\n\tthrow structuredError(\"CONTRACT.CAST_REFUSED\", `A vector is an array of finite numbers, or the text PostgreSQL prints for one, as in \"[1,2,3]\". ${JSON.stringify(value)} is neither.`, {\n\t\twhy: \"pgvector/vector stores a vector as its array of numbers (ADR 254), and reads that array and the text PostgreSQL prints.\",\n\t\tfix: \"Write the vector as an array of numbers, as in [1, 2, 3].\"\n\t});\n};\nconst pgvectorVectorParams = type({ length: `number.integer >= 1 & number.integer <= ${VECTOR_MAX_DIM}` });\nconst pgvectorVector = sqlDataType(\"pgvector/vector\", {\n\tparams: pgvectorVectorParams,\n\ttexts: [{\n\t\ttext: \"vector({length})\",\n\t\twritten: true,\n\t\tcatalog: true\n\t}],\n\tlistCast: {\n\t\tof: [\n\t\t\tpgInt2.id,\n\t\t\tpgInt4.id,\n\t\t\tpgInt8.id,\n\t\t\tpgNumeric.id\n\t\t],\n\t\tcast: (elements) => elements.map(elementNumber)\n\t},\n\ttoCanonicalForm: vectorCanonicalForm\n});\nconst pgvectorDataTypes = [pgvectorVector];\n//#endregion\n//#region src/core/errors.ts\nfunction pgVectorError(code, message, options) {\n\treturn structuredError(code, message, options);\n}\n//#endregion\n//#region src/core/codecs.ts\nfunction parseVector(value) {\n\tif (!value.startsWith(\"[\") || !value.endsWith(\"]\")) throw pgVectorError(\"RUNTIME.DECODE_FAILED\", `Invalid vector format: expected \"[...]\", got \"${value}\"`, {\n\t\twhy: \"The database returned a vector value that is not in the PostgreSQL \\\"[x,y,z]\\\" text format.\",\n\t\tmeta: {\n\t\t\tcodecId: VECTOR_CODEC_ID,\n\t\t\twirePreview: value\n\t\t}\n\t});\n\tconst content = value.slice(1, -1).trim();\n\treturn content === \"\" ? [] : content.split(\",\").map((entry) => {\n\t\tconst number = Number.parseFloat(entry.trim());\n\t\tif (Number.isNaN(number)) throw pgVectorError(\"RUNTIME.DECODE_FAILED\", `Invalid vector value: \"${entry}\" is not a number`, {\n\t\t\twhy: \"A vector entry returned by the database could not be parsed as a number.\",\n\t\t\tmeta: {\n\t\t\t\tcodecId: VECTOR_CODEC_ID,\n\t\t\t\twirePreview: value\n\t\t\t}\n\t\t});\n\t\treturn number;\n\t});\n}\nvar PgVectorCodec = class extends CodecImpl {\n\tlength;\n\tconstructor(descriptor, length) {\n\t\tsuper(descriptor);\n\t\tthis.length = length;\n\t}\n\tassertVector(value, code) {\n\t\tconst meta = {\n\t\t\tcodecId: VECTOR_CODEC_ID,\n\t\t\texpectedLength: this.length\n\t\t};\n\t\tif (!Array.isArray(value)) throw pgVectorError(code, \"Vector value must be an array of numbers\", { meta });\n\t\tfor (const element of value) {\n\t\t\tif (typeof element !== \"number\") throw pgVectorError(code, \"Vector value must contain only numbers\", { meta });\n\t\t\tif (!Number.isFinite(element)) throw pgVectorError(code, \"Vector value must contain only finite numbers\", { meta });\n\t\t}\n\t\tif (value.length !== this.length) throw pgVectorError(code, `Vector length mismatch: expected ${this.length}, got ${value.length}`, {\n\t\t\twhy: `This column is declared as vector(${this.length}); every value must have exactly that many dimensions.`,\n\t\t\tmeta: {\n\t\t\t\t...meta,\n\t\t\t\treceivedLength: value.length\n\t\t\t}\n\t\t});\n\t}\n\tasync encode(value, _ctx) {\n\t\tthis.assertVector(value, \"RUNTIME.ENCODE_FAILED\");\n\t\treturn `[${value.join(\",\")}]`;\n\t}\n\tasync decode(wire, _ctx) {\n\t\tif (typeof wire !== \"string\") throw pgVectorError(\"RUNTIME.DECODE_FAILED\", \"Vector wire value must be a string\", { meta: { codecId: VECTOR_CODEC_ID } });\n\t\tconst value = parseVector(wire);\n\t\tthis.assertVector(value, \"RUNTIME.DECODE_FAILED\");\n\t\treturn value;\n\t}\n\tencodeJson(value) {\n\t\tthis.assertVector(value, \"RUNTIME.ENCODE_FAILED\");\n\t\treturn [...value];\n\t}\n\tdecodeJson(json) {\n\t\tif (!Array.isArray(json) || json.length !== this.length) return this.refuseJson(json);\n\t\tconst numbers = [];\n\t\tfor (const element of json) {\n\t\t\tif (typeof element !== \"number\" || !Number.isFinite(element)) return this.refuseJson(json);\n\t\t\tnumbers.push(element);\n\t\t}\n\t\treturn numbers;\n\t}\n\trefuseJson(json) {\n\t\treturn refuseJsonValue(VECTOR_CODEC_ID, `an array of ${counted(this.length, \"finite number\")}`, json);\n\t}\n};\n/**\n* Projects a `vector` as a JSON numeric array.\n*\n* A `vector` handed straight to a JSON constructor is rendered through its text\n* output function, so it arrives as the *string* `\"[1,2,3]\"` rather than as an\n* array.\n*\n* The route matters as much as the destination. A vector's elements are `real`,\n* and its text form prints the shortest decimal that round-trips *as a `real`* —\n* `0.1` for a value the application holds as `0.10000000149011612`. Reading that\n* text back as a double therefore lands on a different number, so casting the\n* text to `json` would lose precision the value still had. Widening each element\n* to `float8` first keeps the exact value the `real` denotes, which is what\n* `encodeJson` returns.\n*/\nconst jsonArrayFromVectorElements = (expression) => FunctionCallExpr.of(\"array_to_json\", [CastExpr.as(CastExpr.as(expression, \"real[]\"), \"float8[]\")]);\nvar PgVectorDescriptor = class extends PostgresCodecDescriptor {\n\tjsonProjection(expression) {\n\t\treturn jsonArrayFromVectorElements(expression);\n\t}\n\tdataType = pgvectorVector.id;\n\tcodecId = VECTOR_CODEC_ID;\n\ttraits = [\"equality\"];\n\tparamsSchema = pgvectorVectorParams;\n\tfactory(params) {\n\t\treturn () => new PgVectorCodec(this, params.length);\n\t}\n};\nconst codecDescriptorMap = { vector: new PgVectorDescriptor() };\n//#endregion\n//#region src/core/registry.ts\n/**\n* Registry of every codec descriptor shipped by `@internal/extension-pgvector`.\n*\n* Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.\n*/\nconst pgvectorCodecRegistry = buildCodecDescriptorRegistry(definePostgresCodecs(Object.values(codecDescriptorMap)));\n//#endregion\n//#region src/core/descriptor-meta.ts\nconst pgvectorTypeId = \"pg/vector@1\";\nfunction pgvectorQueryOperations() {\n\treturn {\n\t\tcosineDistance: {\n\t\t\tself: { codecId: pgvectorTypeId },\n\t\t\timpl: (self, other) => {\n\t\t\t\tconst selfCodec = codecOf(self);\n\t\t\t\treturn buildOperation({\n\t\t\t\t\tmethod: \"cosineDistance\",\n\t\t\t\t\targs: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n\t\t\t\t\treturns: {\n\t\t\t\t\t\tcodecId: \"pg/float8@1\",\n\t\t\t\t\t\tnullable: false\n\t\t\t\t\t},\n\t\t\t\t\tlowering: {\n\t\t\t\t\t\ttargetFamily: \"sql\",\n\t\t\t\t\t\ttemplate: \"{{self}} <=> {{arg0}}\"\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcosineSimilarity: {\n\t\t\tself: { codecId: pgvectorTypeId },\n\t\t\timpl: (self, other) => {\n\t\t\t\tconst selfCodec = codecOf(self);\n\t\t\t\treturn buildOperation({\n\t\t\t\t\tmethod: \"cosineSimilarity\",\n\t\t\t\t\targs: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n\t\t\t\t\treturns: {\n\t\t\t\t\t\tcodecId: \"pg/float8@1\",\n\t\t\t\t\t\tnullable: false\n\t\t\t\t\t},\n\t\t\t\t\tlowering: {\n\t\t\t\t\t\ttargetFamily: \"sql\",\n\t\t\t\t\t\ttemplate: \"1 - ({{self}} <=> {{arg0}})\"\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n}\nconst pgvectorPackMeta = {\n\tkind: \"extension\",\n\tid: \"pgvector\",\n\tfamilyId: \"sql\",\n\ttargetId: \"postgres\",\n\tversion: \"0.0.1\",\n\tcapabilities: { postgres: { \"pgvector.cosine\": true } },\n\tauthoring: { type: pgvectorAuthoringTypes },\n\tdataTypes: pgvectorDataTypes,\n\ttypes: {\n\t\tcodecTypes: {\n\t\t\tcodecDescriptors: Array.from(pgvectorCodecRegistry.values()),\n\t\t\timport: {\n\t\t\t\tpackage: \"@internal/extension-pgvector/codec-types\",\n\t\t\t\tnamed: \"CodecTypes\",\n\t\t\t\talias: \"PgVectorTypes\"\n\t\t\t},\n\t\t\tparameterizedOutputTypes: {\n\t\t\t\tpackage: \"@internal/extension-pgvector/codec-types\",\n\t\t\t\tnamed: \"ParameterizedOutputTypesForTypeParams\",\n\t\t\t\talias: \"PgVectorParameterizedOutputTypes\"\n\t\t\t}\n\t\t},\n\t\toperationTypes: { import: {\n\t\t\tpackage: \"@internal/extension-pgvector/operation-types\",\n\t\t\tnamed: \"OperationTypes\",\n\t\t\talias: \"PgVectorOperationTypes\"\n\t\t} },\n\t\tqueryOperationTypes: { import: {\n\t\t\tpackage: \"@internal/extension-pgvector/operation-types\",\n\t\t\tnamed: \"QueryOperationTypes\",\n\t\t\talias: \"PgVectorQueryOperationTypes\"\n\t\t} }\n\t}\n};\n//#endregion\nexport { pgvectorQueryOperations as n, pgvectorCodecRegistry as r, pgvectorPackMeta as t };\n\n//# sourceMappingURL=descriptor-meta-VztEZTmZ.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,MAAM,yBAAyB,EAAE,UAAU,EAAE,QAAQ;CACpD,MAAM;CACN,UAAU;CACV,MAAM,CAAC;EACN,MAAM;EACN,MAAM;EACN,SAAS;CACV,CAAC;CACD,QAAQ;EACP,SAAS;EACT,YAAY,EAAE,QAAQ;GACrB,MAAM;GACN,OAAO;EACR,EAAE;CACH;AACD,EAAE,EAAE;AAGJ,SAAS,cAAc,SAAS;CAC/B,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,IAAI,OAAO,YAAY,YAAY,CAAC,gBAAgB,OAAO,GAAG;EAC7D,MAAM,YAAY,OAAO,OAAO;EAChC,IAAI,OAAO,SAAS,SAAS,GAAG,OAAO;CACxC;CACA,MAAM,gBAAg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