@prisma/orm-extension-pgvector 8.0.0-rc.2-dev.3 → 8.0.0-rc.20-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/dist/{codec-types-BFcjjrT--s4MwG0qH.d.mts → codec-types-CD1S71YG-CpCnyq6p.d.mts} +23 -18
- package/dist/codec-types-CD1S71YG-CpCnyq6p.d.mts.map +1 -0
- package/dist/codec-types.d.mts +2 -2
- package/dist/column-types.d.mts +3 -3
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs +2 -12
- package/dist/column-types.mjs.map +1 -1
- package/dist/constants-BjLQgqqq-CMdE2ode.d.mts +9 -0
- package/dist/constants-BjLQgqqq-CMdE2ode.d.mts.map +1 -0
- package/dist/constants-D8Ccy-f4-BNIWMdMO.mjs +13 -0
- package/dist/constants-D8Ccy-f4-BNIWMdMO.mjs.map +1 -0
- package/dist/control.mjs +19 -17
- package/dist/control.mjs.map +1 -1
- package/dist/descriptor-meta-CMFaBE3y-3XzFcH_O.mjs +272 -0
- package/dist/descriptor-meta-CMFaBE3y-3XzFcH_O.mjs.map +1 -0
- package/dist/{operation-types-D37jCdyS-ClyVMplO.d.mts → operation-types-SKTIzyy9-DXQ_bE1A.d.mts} +8 -4
- package/dist/operation-types-SKTIzyy9-DXQ_bE1A.d.mts.map +1 -0
- package/dist/operation-types.d.mts +2 -2
- package/dist/pack.d.mts +13 -18
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/runtime.d.mts +34 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +27 -1
- package/dist/runtime.mjs.map +1 -1
- package/package.json +13 -16
- package/dist/codec-types-BFcjjrT--s4MwG0qH.d.mts.map +0 -1
- package/dist/descriptor-meta-Dk8eTHcA-DeyZ_87T.mjs +0 -227
- package/dist/descriptor-meta-Dk8eTHcA-DeyZ_87T.mjs.map +0 -1
- package/dist/errors-9-gSu3kD-Vg4apMXQ.mjs +0 -17
- package/dist/errors-9-gSu3kD-Vg4apMXQ.mjs.map +0 -1
- package/dist/operation-types-D37jCdyS-ClyVMplO.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @prisma/orm-extension-pgvector
|
|
2
2
|
|
|
3
|
-
Embedding columns and vector similarity search for Prisma
|
|
3
|
+
Embedding columns and vector similarity search for Prisma 8 on PostgreSQL, powered by [pgvector](https://github.com/pgvector/pgvector).
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
pnpm add @prisma/orm-extension-pgvector
|
|
@@ -19,9 +19,3 @@ pnpm add @prisma/orm-extension-pgvector
|
|
|
19
19
|
## Responsibilities
|
|
20
20
|
|
|
21
21
|
Dimensioned vector storage and search: the `pg/vector@1` codec (`number[]` at runtime, `Vector<N>` in `contract.d.ts`), similarity operations such as `cosineDistance`, and a baseline migration that runs `CREATE EXTENSION IF NOT EXISTS vector` when the pack is composed into an application.
|
|
22
|
-
|
|
23
|
-
## Dependencies
|
|
24
|
-
|
|
25
|
-
`@prisma/orm-framework`, `@prisma/orm-family-sql`, and `@prisma/orm-toolchain` at exact lockstep versions, plus `arktype` and `@standard-schema/spec`.
|
|
26
|
-
|
|
27
|
-
`@prisma/orm-target-postgres` is an exact-pinned **peer** dependency: the application supplies it, directly or through a facade, and everyone shares that one copy. A hard dependency would let an application upgrade the facade without upgrading this pack and end up with two target copies whose codec and operation registries have quietly diverged; as a peer that combination fails to install instead.
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as VECTOR_CODEC_ID } from "./constants-BjLQgqqq-CMdE2ode.mjs";
|
|
2
|
+
import { AnyCodecDescriptor, CodecCallContext, CodecImpl, CodecInstanceContext, DataTypeValue } from "@prisma/orm-framework/components/codec";
|
|
2
3
|
import { ExtractCodecTypes, ProjectionExpr } from "@prisma/orm-family-sql/relational-core/ast";
|
|
3
4
|
import { PostgresCodecDescriptor } from "@prisma/orm-target-postgres/target/codec-descriptor";
|
|
4
|
-
import {
|
|
5
|
+
import { ParameterizedOutputTypesFunction } from "@prisma/orm-framework/contract/types";
|
|
5
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
-
//#region ../../../3-extensions/pgvector/dist/codec-types-
|
|
7
|
-
//#region src/core/constants.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Codec ID for pgvector's vector type.
|
|
10
|
-
*/
|
|
11
|
-
declare const VECTOR_CODEC_ID: "pg/vector@1";
|
|
12
|
-
//#endregion
|
|
7
|
+
//#region ../../../3-extensions/pgvector/dist/codec-types-CD1S71YG.d.mts
|
|
13
8
|
//#region src/core/codecs.d.ts
|
|
14
9
|
type VectorConversionCode = 'RUNTIME.ENCODE_FAILED' | 'RUNTIME.DECODE_FAILED';
|
|
15
10
|
type VectorParams = {
|
|
@@ -19,19 +14,18 @@ declare class PgVectorCodec extends CodecImpl<typeof VECTOR_CODEC_ID, readonly [
|
|
|
19
14
|
readonly length: number;
|
|
20
15
|
constructor(descriptor: AnyCodecDescriptor, length: number);
|
|
21
16
|
assertVector(value: unknown, code: VectorConversionCode): asserts value is number[];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
21
|
}
|
|
27
22
|
declare class PgVectorDescriptor extends PostgresCodecDescriptor<VectorParams> {
|
|
28
|
-
protected nativeType(): string;
|
|
29
23
|
protected jsonProjection(expression: ProjectionExpr): ProjectionExpr;
|
|
24
|
+
readonly dataType: import("@prisma/orm-framework/components/codec").DataTypeId;
|
|
30
25
|
readonly codecId: "pg/vector@1";
|
|
31
26
|
readonly traits: readonly ["equality"];
|
|
32
|
-
readonly
|
|
27
|
+
readonly enumRefusal = "The contract stores a vector member as an array of numbers, which no CHECK can list. No enum can use a vector codec; use a text enum instead.";
|
|
33
28
|
readonly paramsSchema: StandardSchemaV1<VectorParams>;
|
|
34
|
-
renderOutputType(params: VectorParams): string;
|
|
35
29
|
factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec;
|
|
36
30
|
}
|
|
37
31
|
declare const codecDescriptorMap: {
|
|
@@ -50,6 +44,17 @@ type Vector<N extends number = number> = number[] & {
|
|
|
50
44
|
readonly __vectorLength?: N;
|
|
51
45
|
};
|
|
52
46
|
type CodecTypes = CodecTypes$1;
|
|
47
|
+
type OutputTypeMap<TypeParams> = {
|
|
48
|
+
readonly 'pg/vector@1': TypeParams extends {
|
|
49
|
+
readonly length: infer N extends number;
|
|
50
|
+
} ? Vector<N> : never;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The output type of a `vector(N)` column, `Vector<N>`: the only declaration of it, which a contract written with `defineContract` and the `contract.d.ts` that `prisma contract emit` writes both apply.
|
|
54
|
+
*/
|
|
55
|
+
interface ParameterizedOutputTypesForTypeParams extends ParameterizedOutputTypesFunction {
|
|
56
|
+
readonly outputTypes: OutputTypeMap<this['typeParams']>;
|
|
57
|
+
}
|
|
53
58
|
//#endregion
|
|
54
|
-
export {
|
|
55
|
-
//# sourceMappingURL=codec-types-
|
|
59
|
+
export { ParameterizedOutputTypesForTypeParams as n, Vector as r, CodecTypes as t };
|
|
60
|
+
//# sourceMappingURL=codec-types-CD1S71YG-CpCnyq6p.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-types-CD1S71YG-CpCnyq6p.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/codec-types-CD1S71YG.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;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 Vector, t as CodecTypes } from "./codec-types-
|
|
2
|
-
export type { CodecTypes, Vector };
|
|
1
|
+
import { n as ParameterizedOutputTypesForTypeParams, r as Vector, t as CodecTypes } from "./codec-types-CD1S71YG-CpCnyq6p.mjs";
|
|
2
|
+
export type { CodecTypes, ParameterizedOutputTypesForTypeParams, Vector };
|
package/dist/column-types.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as VECTOR_CODEC_ID } from "./constants-BjLQgqqq-CMdE2ode.mjs";
|
|
1
2
|
import { ColumnTypeDescriptor } from "@prisma/orm-framework/components/codec";
|
|
2
3
|
//#region ../../../3-extensions/pgvector/dist/column-types.d.mts
|
|
3
4
|
//#region src/exports/column-types.d.ts
|
|
@@ -7,13 +8,12 @@ import { ColumnTypeDescriptor } from "@prisma/orm-framework/components/codec";
|
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
9
10
|
* .column('embedding', { type: vector(1536), nullable: false })
|
|
10
|
-
* // Produces:
|
|
11
|
+
* // Produces: codecId: 'pg/vector@1', typeParams: { length: 1536 }
|
|
11
12
|
* ```
|
|
12
13
|
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
13
14
|
* @returns A column type descriptor with `typeParams.length` set
|
|
14
|
-
* @throws `CONTRACT.ARGUMENT_INVALID` if length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
15
15
|
*/
|
|
16
|
-
declare function vector<N extends number>(length: N): ColumnTypeDescriptor & {
|
|
16
|
+
declare function vector<N extends number>(length: N): ColumnTypeDescriptor<typeof VECTOR_CODEC_ID> & {
|
|
17
17
|
readonly typeParams: {
|
|
18
18
|
readonly length: N;
|
|
19
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/column-types.d.mts"],"mappings":";;;;;;;;;;;;;;;iBAciB,OAAO,kBAAkB,QAAQ,IAAI;
|
|
1
|
+
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/column-types.d.mts"],"mappings":";;;;;;;;;;;;;;;iBAciB,OAAO,kBAAkB,QAAQ,IAAI,4BAA4B;WACvE;aACE,QAAQ"}
|
package/dist/column-types.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as VECTOR_CODEC_ID } from "./constants-D8Ccy-f4-BNIWMdMO.mjs";
|
|
2
2
|
//#region ../../../3-extensions/pgvector/dist/column-types.mjs
|
|
3
3
|
/**
|
|
4
4
|
* Factory for creating dimensioned vector column descriptors.
|
|
@@ -6,24 +6,14 @@ import { n as VECTOR_MAX_DIM, r as pgVectorError, t as VECTOR_CODEC_ID } from ".
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```typescript
|
|
8
8
|
* .column('embedding', { type: vector(1536), nullable: false })
|
|
9
|
-
* // Produces:
|
|
9
|
+
* // Produces: codecId: 'pg/vector@1', typeParams: { length: 1536 }
|
|
10
10
|
* ```
|
|
11
11
|
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
12
12
|
* @returns A column type descriptor with `typeParams.length` set
|
|
13
|
-
* @throws `CONTRACT.ARGUMENT_INVALID` if length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
14
13
|
*/
|
|
15
14
|
function vector(length) {
|
|
16
|
-
if (!Number.isInteger(length) || length < 1 || length > 16e3) throw pgVectorError("CONTRACT.ARGUMENT_INVALID", `pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`, {
|
|
17
|
-
fix: `Pass an integer dimension between 1 and ${VECTOR_MAX_DIM}, e.g. vector(1536).`,
|
|
18
|
-
meta: {
|
|
19
|
-
helperPath: "vector",
|
|
20
|
-
expected: `an integer in [1, ${VECTOR_MAX_DIM}]`,
|
|
21
|
-
received: length
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
15
|
return {
|
|
25
16
|
codecId: VECTOR_CODEC_ID,
|
|
26
|
-
nativeType: "vector",
|
|
27
17
|
typeParams: { length }
|
|
28
18
|
};
|
|
29
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/column-types.mjs"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"column-types.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/column-types.mjs"],"sourcesContent":["import { t as VECTOR_CODEC_ID } from \"./constants-D8Ccy-f4.mjs\";\n//#region src/exports/column-types.ts\n/**\n* Factory for creating dimensioned vector column descriptors.\n*\n* @example\n* ```typescript\n* .column('embedding', { type: vector(1536), nullable: false })\n* // Produces: codecId: 'pg/vector@1', typeParams: { length: 1536 }\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*/\nfunction vector(length) {\n\treturn {\n\t\tcodecId: VECTOR_CODEC_ID,\n\t\ttypeParams: { length }\n\t};\n}\n//#endregion\nexport { vector };\n\n//# sourceMappingURL=column-types.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,OAAO,QAAQ;CACvB,OAAO;EACN,SAAS;EACT,YAAY,EAAE,OAAO;CACtB;AACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region ../../../3-extensions/pgvector/dist/constants-BjLQgqqq.d.mts
|
|
2
|
+
//#region src/core/constants.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Codec ID for pgvector's vector type.
|
|
5
|
+
*/
|
|
6
|
+
declare const VECTOR_CODEC_ID: "pg/vector@1";
|
|
7
|
+
//#endregion
|
|
8
|
+
export { VECTOR_CODEC_ID as t };
|
|
9
|
+
//# sourceMappingURL=constants-BjLQgqqq-CMdE2ode.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-BjLQgqqq-CMdE2ode.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/constants-BjLQgqqq.d.mts"],"mappings":";;;;;cAIc"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region ../../../3-extensions/pgvector/dist/constants-D8Ccy-f4.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Codec ID for pgvector's vector type.
|
|
4
|
+
*/
|
|
5
|
+
const VECTOR_CODEC_ID = "pg/vector@1";
|
|
6
|
+
/**
|
|
7
|
+
* Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).
|
|
8
|
+
*/
|
|
9
|
+
const VECTOR_MAX_DIM = 16e3;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { VECTOR_MAX_DIM as n, VECTOR_CODEC_ID as t };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=constants-D8Ccy-f4-BNIWMdMO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-D8Ccy-f4-BNIWMdMO.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/constants-D8Ccy-f4.mjs"],"sourcesContent":["//#region src/core/constants.ts\n/**\n* Codec ID for pgvector's vector type.\n*/\nconst VECTOR_CODEC_ID = \"pg/vector@1\";\n/**\n* Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).\n*/\nconst VECTOR_MAX_DIM = 16e3;\n//#endregion\nexport { VECTOR_MAX_DIM as n, VECTOR_CODEC_ID as t };\n\n//# sourceMappingURL=constants-D8Ccy-f4.mjs.map"],"mappings":";;;;AAIA,MAAM,kBAAkB;;;;AAIxB,MAAM,iBAAiB"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { n as pgvectorPackMeta, r as pgvectorQueryOperations } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorPackMeta, r as pgvectorQueryOperations } from "./descriptor-meta-CMFaBE3y-3XzFcH_O.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 = {
|
|
5
5
|
from: null,
|
|
6
|
-
to: "
|
|
6
|
+
to: "4a96b488a4ce92b434e5f7d6607b6435c0955f0d36b0018077045787764240e6",
|
|
7
7
|
providedInvariants: ["pgvector:install-vector-v1"],
|
|
8
8
|
createdAt: "2026-06-01T00:00:00.000Z",
|
|
9
|
-
migrationHash: "
|
|
9
|
+
migrationHash: "ae458aa8c484439df5d79fdfbbe907a3ab7e53b25c79259a95909ab3c61d9a66"
|
|
10
10
|
};
|
|
11
11
|
var ops_default = [{
|
|
12
12
|
"id": "pgvector.install-vector-extension",
|
|
@@ -37,7 +37,7 @@ var ops_default = [{
|
|
|
37
37
|
}]
|
|
38
38
|
}];
|
|
39
39
|
var head_default = {
|
|
40
|
-
hash: "
|
|
40
|
+
hash: "4a96b488a4ce92b434e5f7d6607b6435c0955f0d36b0018077045787764240e6",
|
|
41
41
|
invariants: ["pgvector:install-vector-v1"]
|
|
42
42
|
};
|
|
43
43
|
var contract_default = {
|
|
@@ -53,16 +53,18 @@ var contract_default = {
|
|
|
53
53
|
"id": "public",
|
|
54
54
|
"kind": "postgres-schema"
|
|
55
55
|
} },
|
|
56
|
-
"storageHash": "
|
|
56
|
+
"storageHash": "4a96b488a4ce92b434e5f7d6607b6435c0955f0d36b0018077045787764240e6",
|
|
57
57
|
"types": { "vector": {
|
|
58
58
|
"codecId": "pg/vector@1",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
59
|
+
"dataType": "pgvector/vector",
|
|
60
|
+
"kind": "codec-instance"
|
|
61
61
|
} }
|
|
62
62
|
},
|
|
63
63
|
capabilities: {
|
|
64
64
|
"postgres": {
|
|
65
65
|
"distinctOn": true,
|
|
66
|
+
"forKeyShare": true,
|
|
67
|
+
"forNoKeyUpdate": true,
|
|
66
68
|
"jsonAgg": true,
|
|
67
69
|
"lateral": true,
|
|
68
70
|
"limit": true,
|
|
@@ -73,7 +75,14 @@ var contract_default = {
|
|
|
73
75
|
"checkConstraint": true,
|
|
74
76
|
"defaultInInsert": true,
|
|
75
77
|
"enums": true,
|
|
78
|
+
"forShare": true,
|
|
79
|
+
"forUpdate": true,
|
|
80
|
+
"insertOnConflictSkip": true,
|
|
81
|
+
"insertOnConflictWithoutTarget": true,
|
|
76
82
|
"lateral": true,
|
|
83
|
+
"lockNowait": true,
|
|
84
|
+
"lockOf": true,
|
|
85
|
+
"lockSkipLocked": true,
|
|
77
86
|
"returning": true,
|
|
78
87
|
"scalarList": true
|
|
79
88
|
}
|
|
@@ -82,8 +91,8 @@ var contract_default = {
|
|
|
82
91
|
meta: {},
|
|
83
92
|
_generated: {
|
|
84
93
|
"warning": "⚠️ GENERATED FILE - DO NOT EDIT",
|
|
85
|
-
"message": "This file is automatically generated by \"prisma
|
|
86
|
-
"regenerate": "To regenerate, run: prisma
|
|
94
|
+
"message": "This file is automatically generated by \"prisma contract emit\".",
|
|
95
|
+
"regenerate": "To regenerate, run: prisma contract emit"
|
|
87
96
|
}
|
|
88
97
|
};
|
|
89
98
|
/**
|
|
@@ -109,14 +118,7 @@ function buildVectorIdentityValue(typeParams) {
|
|
|
109
118
|
if (typeof length !== "number" || !Number.isInteger(length) || length <= 0) return null;
|
|
110
119
|
return `'${`[${new Array(length).fill("0").join(",")}]`}'::vector`;
|
|
111
120
|
}
|
|
112
|
-
const vectorControlPlaneHooks = {
|
|
113
|
-
expandNativeType: ({ nativeType, typeParams }) => {
|
|
114
|
-
const length = typeParams?.["length"];
|
|
115
|
-
if (typeof length === "number" && Number.isInteger(length) && length > 0) return `${nativeType}(${length})`;
|
|
116
|
-
return nativeType;
|
|
117
|
-
},
|
|
118
|
-
resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams)
|
|
119
|
-
};
|
|
121
|
+
const vectorControlPlaneHooks = { resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams) };
|
|
120
122
|
const pgvectorContractSpace = contractSpaceFromJson({
|
|
121
123
|
contractJson: contract_default,
|
|
122
124
|
migrations: [{
|
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-CMFaBE3y.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,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MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;AACzD;AACA,MAAM,0BAA0B,EAAE,uBAAuB,EAAE,iBAAiB,yBAAyB,UAAU,EAAE;AACjH,MAAM,wBAAwB,sBAAsB;CACnD,cAAc;CACd,YAAY,CAAC;EACZ,SAAS;EACT,UAAU;EACV,KAAK;CACN,CAAC;CACD,SAAS;AACV,CAAC;AACD,MAAM,8BAA8B;CACnC,GAAG;CACH,IAAI;CACJ,eAAe;CACf,OAAO;EACN,GAAG,iBAAiB;EACpB,YAAY;GACX,GAAG,iBAAiB,MAAM;GAC1B,mBAAmB,GAAG,oBAAoB,wBAAwB;EACnE;CACD;CACA,uBAAuB,wBAAwB;CAC/C,eAAe;EACd,UAAU;EACV,UAAU;CACX;AACD"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-D8Ccy-f4-BNIWMdMO.mjs";
|
|
2
|
+
import { buildOperation, codecOf, toExpr } from "@prisma/orm-family-sql/relational-core/expression";
|
|
3
|
+
import { CodecImpl, isNonFiniteText, refuseJsonValue } from "@prisma/orm-framework/components/codec";
|
|
4
|
+
import { sqlDataType } from "@prisma/orm-family-sql/contract/data-type";
|
|
5
|
+
import { pgInt2, pgInt4, pgInt8, pgNumeric } from "@prisma/orm-target-postgres/target/data-types";
|
|
6
|
+
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
7
|
+
import { counted } from "@prisma/orm-framework/utils/text";
|
|
8
|
+
import { type } from "arktype";
|
|
9
|
+
import { buildCodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/codec-descriptor-registry";
|
|
10
|
+
import { CastExpr } from "@prisma/orm-family-sql/relational-core/ast";
|
|
11
|
+
import { PostgresCodecDescriptor, definePostgresCodecs } from "@prisma/orm-target-postgres/target/codec-descriptor";
|
|
12
|
+
//#region ../../../3-extensions/pgvector/dist/descriptor-meta-CMFaBE3y.mjs
|
|
13
|
+
const pgvectorAuthoringTypes = { pgvector: { Vector: {
|
|
14
|
+
kind: "typeConstructor",
|
|
15
|
+
inferred: true,
|
|
16
|
+
args: [{
|
|
17
|
+
kind: "value",
|
|
18
|
+
dataType: "pg/int4",
|
|
19
|
+
name: "length"
|
|
20
|
+
}],
|
|
21
|
+
output: {
|
|
22
|
+
codecId: "pg/vector@1",
|
|
23
|
+
typeParams: { length: {
|
|
24
|
+
kind: "arg",
|
|
25
|
+
index: 0
|
|
26
|
+
} }
|
|
27
|
+
}
|
|
28
|
+
} } };
|
|
29
|
+
function elementNumber(element) {
|
|
30
|
+
if (typeof element === "number") return element;
|
|
31
|
+
if (typeof element === "string" && !isNonFiniteText(element)) {
|
|
32
|
+
const converted = Number(element);
|
|
33
|
+
if (Number.isFinite(converted)) return converted;
|
|
34
|
+
}
|
|
35
|
+
throw structuredError("CONTRACT.CAST_REFUSED", `A vector holds finite numbers, and ${JSON.stringify(element)} is not one.`, {
|
|
36
|
+
why: "A vector element is a finite number; NaN and the two infinities have no place in one.",
|
|
37
|
+
fix: "Use a finite number for every element."
|
|
38
|
+
});
|
|
39
|
+
}
|
|
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
|
+
function isFiniteNumber(element) {
|
|
43
|
+
return typeof element === "number" && Number.isFinite(element);
|
|
44
|
+
}
|
|
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;
|
|
57
|
+
};
|
|
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
|
+
}
|
|
69
|
+
const pgvectorVector = sqlDataType("pgvector/vector", {
|
|
70
|
+
params: pgvectorVectorParams,
|
|
71
|
+
read: readVector,
|
|
72
|
+
texts: [{
|
|
73
|
+
text: "vector({length})",
|
|
74
|
+
written: true,
|
|
75
|
+
catalog: true
|
|
76
|
+
}],
|
|
77
|
+
listCast: {
|
|
78
|
+
of: [
|
|
79
|
+
pgInt2.id,
|
|
80
|
+
pgInt4.id,
|
|
81
|
+
pgInt8.id,
|
|
82
|
+
pgNumeric.id
|
|
83
|
+
],
|
|
84
|
+
cast: (elements) => elements.map(elementNumber)
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const pgvectorDataTypes = [pgvectorVector];
|
|
88
|
+
function pgVectorError(code, message, options) {
|
|
89
|
+
return structuredError(code, message, options);
|
|
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
|
+
*/
|
|
102
|
+
function parseVector(value) {
|
|
103
|
+
if (!value.startsWith("[") || !value.endsWith("]")) throw pgVectorError("RUNTIME.DECODE_FAILED", `Invalid vector format: expected "[...]", got "${value}"`, {
|
|
104
|
+
why: "The database returned a vector value that is not in the PostgreSQL \"[x,y,z]\" text format.",
|
|
105
|
+
meta: {
|
|
106
|
+
codecId: VECTOR_CODEC_ID,
|
|
107
|
+
wirePreview: value
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const content = value.slice(1, -1).trim();
|
|
111
|
+
return content === "" ? [] : content.split(",").map((entry) => {
|
|
112
|
+
const number = Number.parseFloat(entry.trim());
|
|
113
|
+
if (Number.isNaN(number)) throw pgVectorError("RUNTIME.DECODE_FAILED", `Invalid vector value: "${entry}" is not a number`, {
|
|
114
|
+
why: "A vector entry returned by the database could not be parsed as a number.",
|
|
115
|
+
meta: {
|
|
116
|
+
codecId: VECTOR_CODEC_ID,
|
|
117
|
+
wirePreview: value
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return number;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
var PgVectorCodec = class extends CodecImpl {
|
|
124
|
+
length;
|
|
125
|
+
constructor(descriptor, length) {
|
|
126
|
+
super(descriptor, pgvectorVector, { length });
|
|
127
|
+
this.length = length;
|
|
128
|
+
}
|
|
129
|
+
assertVector(value, code) {
|
|
130
|
+
const meta = {
|
|
131
|
+
codecId: VECTOR_CODEC_ID,
|
|
132
|
+
expectedLength: this.length
|
|
133
|
+
};
|
|
134
|
+
if (!Array.isArray(value)) throw pgVectorError(code, "Vector value must be an array of numbers", { meta });
|
|
135
|
+
for (const element of value) {
|
|
136
|
+
if (typeof element !== "number") throw pgVectorError(code, "Vector value must contain only numbers", { meta });
|
|
137
|
+
if (!Number.isFinite(element)) throw pgVectorError(code, "Vector value must contain only finite numbers", { meta });
|
|
138
|
+
}
|
|
139
|
+
if (value.length !== this.length) throw pgVectorError(code, `Vector length mismatch: expected ${this.length}, got ${value.length}`, {
|
|
140
|
+
why: `This column is declared as vector(${this.length}); every value must have exactly that many dimensions.`,
|
|
141
|
+
meta: {
|
|
142
|
+
...meta,
|
|
143
|
+
receivedLength: value.length
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async toWire(value, _ctx) {
|
|
148
|
+
this.assertVector(value, "RUNTIME.ENCODE_FAILED");
|
|
149
|
+
return `[${value.join(",")}]`;
|
|
150
|
+
}
|
|
151
|
+
async fromWire(wire, _ctx) {
|
|
152
|
+
if (typeof wire !== "string") throw pgVectorError("RUNTIME.DECODE_FAILED", "Vector wire value must be a string", { meta: { codecId: VECTOR_CODEC_ID } });
|
|
153
|
+
const value = parseVector(wire);
|
|
154
|
+
this.assertVector(value, "RUNTIME.DECODE_FAILED");
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
fromDataTypeValue(value) {
|
|
158
|
+
return [...value.value];
|
|
159
|
+
}
|
|
160
|
+
toDataTypeValue(input) {
|
|
161
|
+
this.assertVector(input, "RUNTIME.ENCODE_FAILED");
|
|
162
|
+
return this.dataTypeValueOf([...input]);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
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`.
|
|
171
|
+
*/
|
|
172
|
+
const vectorTextJsonProjection = (expression) => CastExpr.as(expression, "text");
|
|
173
|
+
var PgVectorDescriptor = class extends PostgresCodecDescriptor {
|
|
174
|
+
jsonProjection(expression) {
|
|
175
|
+
return vectorTextJsonProjection(expression);
|
|
176
|
+
}
|
|
177
|
+
dataType = pgvectorVector.id;
|
|
178
|
+
codecId = VECTOR_CODEC_ID;
|
|
179
|
+
traits = ["equality"];
|
|
180
|
+
enumRefusal = "The contract stores a vector member as an array of numbers, which no CHECK can list. No enum can use a vector codec; use a text enum instead.";
|
|
181
|
+
paramsSchema = pgvectorVectorParams;
|
|
182
|
+
factory(params) {
|
|
183
|
+
return () => new PgVectorCodec(this, params.length);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const codecDescriptorMap = { vector: new PgVectorDescriptor() };
|
|
187
|
+
/**
|
|
188
|
+
* Registry of every codec descriptor shipped by `@internal/extension-pgvector`.
|
|
189
|
+
*
|
|
190
|
+
* 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.
|
|
191
|
+
*/
|
|
192
|
+
const pgvectorCodecRegistry = buildCodecDescriptorRegistry(definePostgresCodecs(Object.values(codecDescriptorMap)));
|
|
193
|
+
const pgvectorTypeId = "pg/vector@1";
|
|
194
|
+
function pgvectorQueryOperations() {
|
|
195
|
+
return {
|
|
196
|
+
cosineDistance: {
|
|
197
|
+
self: { codecId: pgvectorTypeId },
|
|
198
|
+
impl: (self, other) => {
|
|
199
|
+
const selfCodec = codecOf(self);
|
|
200
|
+
return buildOperation({
|
|
201
|
+
method: "cosineDistance",
|
|
202
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
203
|
+
returns: {
|
|
204
|
+
codecId: "pg/float8@1",
|
|
205
|
+
nullable: false
|
|
206
|
+
},
|
|
207
|
+
lowering: {
|
|
208
|
+
targetFamily: "sql",
|
|
209
|
+
template: "{{self}} <=> {{arg0}}"
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
cosineSimilarity: {
|
|
215
|
+
self: { codecId: pgvectorTypeId },
|
|
216
|
+
impl: (self, other) => {
|
|
217
|
+
const selfCodec = codecOf(self);
|
|
218
|
+
return buildOperation({
|
|
219
|
+
method: "cosineSimilarity",
|
|
220
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
221
|
+
returns: {
|
|
222
|
+
codecId: "pg/float8@1",
|
|
223
|
+
nullable: false
|
|
224
|
+
},
|
|
225
|
+
lowering: {
|
|
226
|
+
targetFamily: "sql",
|
|
227
|
+
template: "1 - ({{self}} <=> {{arg0}})"
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const pgvectorPackMeta = {
|
|
235
|
+
kind: "extension",
|
|
236
|
+
id: "pgvector",
|
|
237
|
+
familyId: "sql",
|
|
238
|
+
targetId: "postgres",
|
|
239
|
+
version: "0.0.1",
|
|
240
|
+
capabilities: { postgres: { "pgvector.cosine": true } },
|
|
241
|
+
authoring: { type: pgvectorAuthoringTypes },
|
|
242
|
+
dataTypes: pgvectorDataTypes,
|
|
243
|
+
types: {
|
|
244
|
+
codecTypes: {
|
|
245
|
+
codecDescriptors: Array.from(pgvectorCodecRegistry.values()),
|
|
246
|
+
import: {
|
|
247
|
+
package: "@internal/extension-pgvector/codec-types",
|
|
248
|
+
named: "CodecTypes",
|
|
249
|
+
alias: "PgVectorTypes"
|
|
250
|
+
},
|
|
251
|
+
parameterizedOutputTypes: {
|
|
252
|
+
package: "@internal/extension-pgvector/codec-types",
|
|
253
|
+
named: "ParameterizedOutputTypesForTypeParams",
|
|
254
|
+
alias: "PgVectorParameterizedOutputTypes"
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
operationTypes: { import: {
|
|
258
|
+
package: "@internal/extension-pgvector/operation-types",
|
|
259
|
+
named: "OperationTypes",
|
|
260
|
+
alias: "PgVectorOperationTypes"
|
|
261
|
+
} },
|
|
262
|
+
queryOperationTypes: { import: {
|
|
263
|
+
package: "@internal/extension-pgvector/operation-types",
|
|
264
|
+
named: "QueryOperationTypes",
|
|
265
|
+
alias: "PgVectorQueryOperationTypes"
|
|
266
|
+
} }
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
//#endregion
|
|
270
|
+
export { pgvectorPackMeta as n, pgvectorQueryOperations as r, pgvectorCodecRegistry as t };
|
|
271
|
+
|
|
272
|
+
//# sourceMappingURL=descriptor-meta-CMFaBE3y-3XzFcH_O.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-CMFaBE3y-3XzFcH_O.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/descriptor-meta-CMFaBE3y.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: \"value\",\n\t\tdataType: \"pg/int4\",\n\t\tname: \"length\"\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\tenumRefusal = \"The contract stores a vector member as an array of numbers, which no CHECK can list. No enum can use a vector codec; use a text enum instead.\";\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-CMFaBE3y.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,MAAM,yBAAyB,EAAE,UAAU,EAAE,QAAQ;CACpD,MAAM;CACN,UAAU;CACV,MAAM,CAAC;EACN,MAAM;EACN,UAAU;EACV,MAAM;CACP,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;C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AS;GACT,OAAO;GACP,OAAO;EACR,EAAE;EACF,qBAAqB,EAAE,QAAQ;GAC9B,SAAS;GACT,OAAO;GACP,OAAO;EACR,EAAE;CACH;AACD"}
|
package/dist/{operation-types-D37jCdyS-ClyVMplO.d.mts → operation-types-SKTIzyy9-DXQ_bE1A.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CodecExpression, Expression } from "@prisma/orm-family-sql/relational-core/expression";
|
|
2
|
-
import { SqlQueryOperationTypes } from "@prisma/orm-family-sql/contract/types";
|
|
3
|
-
//#region ../../../3-extensions/pgvector/dist/operation-types-
|
|
2
|
+
import { QueryOperationTypesFunction, SqlQueryOperationTypes } from "@prisma/orm-family-sql/contract/types";
|
|
3
|
+
//#region ../../../3-extensions/pgvector/dist/operation-types-SKTIzyy9.d.mts
|
|
4
4
|
//#region src/types/operation-types.d.ts
|
|
5
5
|
type CodecTypesBase = Record<string, {
|
|
6
6
|
readonly input: unknown;
|
|
@@ -33,6 +33,10 @@ type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<CT,
|
|
|
33
33
|
}>;
|
|
34
34
|
};
|
|
35
35
|
}>;
|
|
36
|
+
/** {@link QueryOperationTypes} as a function of the contract's codec types, for a contract written in TypeScript. */
|
|
37
|
+
interface QueryOperationTypesForCodecs extends QueryOperationTypesFunction {
|
|
38
|
+
readonly queryOperationTypes: QueryOperationTypes<this['codecTypes']>;
|
|
39
|
+
}
|
|
36
40
|
//#endregion
|
|
37
|
-
export { QueryOperationTypes as t };
|
|
38
|
-
//# sourceMappingURL=operation-types-
|
|
41
|
+
export { QueryOperationTypesForCodecs as n, QueryOperationTypes as t };
|
|
42
|
+
//# sourceMappingURL=operation-types-SKTIzyy9-DXQ_bE1A.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-types-SKTIzyy9-DXQ_bE1A.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/operation-types-SKTIzyy9.d.mts"],"mappings":";;;;KAGK,iBAAiB;WACX;WACA;;;;;;;;;KASN,oBAAoB,WAAW,kBAAkB,uBAAuB;WAClE;aACE;eACE;;aAEF,OAAO,MAAM,wCAAwC,KAAK,OAAO,wCAAwC,QAAQ;MACxH;MACA;;;WAGK;aACE;eACE;;aAEF,OAAO,MAAM,wCAAwC,KAAK,OAAO,wCAAwC,QAAQ;MACxH;MACA;;;;;UAKI,qCAAqC;WACpC,qBAAqB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as QueryOperationTypes } from "./operation-types-
|
|
2
|
-
export type { QueryOperationTypes };
|
|
1
|
+
import { n as QueryOperationTypesForCodecs, t as QueryOperationTypes } from "./operation-types-SKTIzyy9-DXQ_bE1A.mjs";
|
|
2
|
+
export type { QueryOperationTypes, QueryOperationTypesForCodecs };
|
package/dist/pack.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as CodecTypes } from "./codec-types-
|
|
2
|
-
import "./operation-types-
|
|
1
|
+
import { n as ParameterizedOutputTypesForTypeParams, r as Vector, t as CodecTypes } from "./codec-types-CD1S71YG-CpCnyq6p.mjs";
|
|
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
|
|
5
5
|
declare const pgvectorPackMetaBase: {
|
|
@@ -18,16 +18,14 @@ declare const pgvectorPackMetaBase: {
|
|
|
18
18
|
readonly pgvector: {
|
|
19
19
|
readonly Vector: {
|
|
20
20
|
readonly kind: "typeConstructor";
|
|
21
|
+
readonly inferred: true;
|
|
21
22
|
readonly args: readonly [{
|
|
22
|
-
readonly kind: "
|
|
23
|
+
readonly kind: "value";
|
|
24
|
+
readonly dataType: "pg/int4";
|
|
23
25
|
readonly name: "length";
|
|
24
|
-
readonly integer: true;
|
|
25
|
-
readonly minimum: 1;
|
|
26
|
-
readonly maximum: 16000;
|
|
27
26
|
}];
|
|
28
27
|
readonly output: {
|
|
29
28
|
readonly codecId: "pg/vector@1";
|
|
30
|
-
readonly nativeType: "vector";
|
|
31
29
|
readonly typeParams: {
|
|
32
30
|
readonly length: {
|
|
33
31
|
readonly kind: "arg";
|
|
@@ -39,6 +37,7 @@ declare const pgvectorPackMetaBase: {
|
|
|
39
37
|
};
|
|
40
38
|
};
|
|
41
39
|
};
|
|
40
|
+
readonly dataTypes: readonly import("@prisma/orm-framework/components/codec").DataType[];
|
|
42
41
|
readonly types: {
|
|
43
42
|
readonly codecTypes: {
|
|
44
43
|
readonly codecDescriptors: import("@prisma/orm-framework/components/codec").CodecDescriptor<unknown>[];
|
|
@@ -47,11 +46,11 @@ declare const pgvectorPackMetaBase: {
|
|
|
47
46
|
readonly named: "CodecTypes";
|
|
48
47
|
readonly alias: "PgVectorTypes";
|
|
49
48
|
};
|
|
50
|
-
readonly
|
|
49
|
+
readonly parameterizedOutputTypes: {
|
|
51
50
|
readonly package: "@internal/extension-pgvector/codec-types";
|
|
52
|
-
readonly named: "
|
|
53
|
-
readonly alias: "
|
|
54
|
-
}
|
|
51
|
+
readonly named: "ParameterizedOutputTypesForTypeParams";
|
|
52
|
+
readonly alias: "PgVectorParameterizedOutputTypes";
|
|
53
|
+
};
|
|
55
54
|
};
|
|
56
55
|
readonly operationTypes: {
|
|
57
56
|
readonly import: {
|
|
@@ -67,17 +66,13 @@ declare const pgvectorPackMetaBase: {
|
|
|
67
66
|
readonly alias: "PgVectorQueryOperationTypes";
|
|
68
67
|
};
|
|
69
68
|
};
|
|
70
|
-
readonly storage: readonly [{
|
|
71
|
-
readonly typeId: "pg/vector@1";
|
|
72
|
-
readonly familyId: "sql";
|
|
73
|
-
readonly targetId: "postgres";
|
|
74
|
-
readonly nativeType: "vector";
|
|
75
|
-
}];
|
|
76
69
|
};
|
|
77
70
|
};
|
|
78
71
|
declare const pgvectorPackMeta: typeof pgvectorPackMetaBase & {
|
|
79
72
|
readonly __codecTypes?: CodecTypes;
|
|
73
|
+
readonly __queryOperationTypes?: QueryOperationTypesForCodecs;
|
|
74
|
+
readonly __parameterizedOutputTypes?: ParameterizedOutputTypesForTypeParams;
|
|
80
75
|
};
|
|
81
76
|
//#endregion
|
|
82
|
-
export { pgvectorPackMeta as default };
|
|
77
|
+
export { type CodecTypes, type ParameterizedOutputTypesForTypeParams, type QueryOperationTypesForCodecs, type Vector, pgvectorPackMeta as default };
|
|
83
78
|
//# sourceMappingURL=pack.d.mts.map
|
package/dist/pack.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/pack.d.mts"],"mappings":";;;;cAGc;WACH;WACA;WACA;WACA;WACA;WACA;aACE;eACE;;;WAGJ;aACE;eACE;iBACE;mBACE;mBACA;qBACE;qBACA;qBACA
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/pack.d.mts"],"mappings":";;;;cAGc;WACH;WACA;WACA;WACA;WACA;WACA;aACE;eACE;;;WAGJ;aACE;eACE;iBACE;mBACE;mBACA;mBACA;qBACE;qBACA;qBACA;;mBAEF;qBACE;qBACA;uBACE;yBACE;yBACA;;;;;;;;WAQd,mEAAmE;WACnE;aACE;eACE,iEAAiE;eACjE;iBACE;iBACA;iBACA;;eAEF;iBACE;iBACA;iBACA;;;aAGJ;eACE;iBACE;iBACA;iBACA;;;aAGJ;eACE;iBACE;iBACA;iBACA;;;;;cAKH,yBAAyB;WAC5B,eAAe;WACf,wBAAwB;WACxB,6BAA6B"}
|
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-CMFaBE3y-3XzFcH_O.mjs";
|
|
2
2
|
export { pgvectorPackMeta as default };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { t as VECTOR_CODEC_ID } from "./constants-BjLQgqqq-CMdE2ode.mjs";
|
|
2
|
+
import { r as Vector } from "./codec-types-CD1S71YG-CpCnyq6p.mjs";
|
|
1
3
|
import { SqlRuntimeExtensionDescriptor } from "@prisma/orm-family-sql/runtime";
|
|
2
4
|
import { CodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/query-lane-context";
|
|
5
|
+
import { CollectionMethodContributionType, CollectionMethodModelType } from "@prisma/orm-family-sql/relational-core/collection-methods";
|
|
3
6
|
//#region ../../../3-extensions/pgvector/dist/runtime.d.mts
|
|
4
7
|
//#region src/core/registry.d.ts
|
|
5
8
|
/**
|
|
@@ -9,8 +12,38 @@ import { CodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/
|
|
|
9
12
|
*/
|
|
10
13
|
declare const pgvectorCodecRegistry: CodecDescriptorRegistry;
|
|
11
14
|
//#endregion
|
|
15
|
+
//#region src/core/nearest-collection-method.d.ts
|
|
16
|
+
type VectorFieldNames<Fields> = { [Name in keyof Fields]: Fields[Name] extends {
|
|
17
|
+
readonly many: object;
|
|
18
|
+
} ? never : Fields[Name] extends {
|
|
19
|
+
readonly type: {
|
|
20
|
+
readonly codecId: typeof VECTOR_CODEC_ID;
|
|
21
|
+
};
|
|
22
|
+
} ? Name : never; }[keyof Fields];
|
|
23
|
+
type VectorLength<Field> = Field extends {
|
|
24
|
+
readonly type: {
|
|
25
|
+
readonly typeParams: {
|
|
26
|
+
readonly length: infer Length extends number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
} ? Length : number;
|
|
30
|
+
type NearestMethodTable<Model extends CollectionMethodModelType> = { readonly [Name in VectorFieldNames<Model['fields']> & string as `${Name}_nearest`]: {
|
|
31
|
+
readonly parameters: readonly [vector: Vector<VectorLength<Model['fields'][Name & keyof Model['fields']]>>, maxDistance?: number];
|
|
32
|
+
readonly filters: false;
|
|
33
|
+
readonly orders: true;
|
|
34
|
+
}; };
|
|
35
|
+
/** One method for each vector field of a model, named `<field>_nearest`: the rows nearest to a vector by cosine distance, nearest first, optionally only those within `maxDistance`. Without `maxDistance` it only orders, so rows whose field is null come back too, last. It declares no filter, because it filters only when `maxDistance` is given. */
|
|
36
|
+
interface PgvectorNearestMethods extends CollectionMethodContributionType {
|
|
37
|
+
readonly methods: NearestMethodTable<this['model']>;
|
|
38
|
+
}
|
|
39
|
+
declare module '@prisma/orm-family-sql/relational-core/collection-methods' {
|
|
40
|
+
interface CollectionMethodRegistry {
|
|
41
|
+
readonly 'pgvector/nearest': PgvectorNearestMethods;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
12
45
|
//#region src/exports/runtime.d.ts
|
|
13
46
|
declare const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
|
|
14
47
|
//#endregion
|
|
15
|
-
export { pgvectorRuntimeDescriptor as default, pgvectorCodecRegistry };
|
|
48
|
+
export { type PgvectorNearestMethods, pgvectorRuntimeDescriptor as default, pgvectorCodecRegistry };
|
|
16
49
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/runtime.d.mts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/runtime.d.mts"],"mappings":";;;;;;;;;;;;cAWc,uBAAuB;;;KAGhC,iBAAiB,aAAa,cAAc,SAAS,OAAO;WACtD;YACC,OAAO;WACR;aACE,gBAAgB;;IAEzB,sBAAsB;KACrB,aAAa,SAAS;WAChB;aACE;eACE,cAAc;;;IAGzB;KACC,mBAAmB,cAAc,yCAAyC,QAAQ,iBAAiB,gCAAgC;WAC7H,sBAAsB,QAAQ,OAAO,aAAa,gBAAgB,aAAa,oBAAoB;WACnG;WACA;;;UAGD,+BAA+B;WAC9B,SAAS;;;YAGR;aACC,oBAAoB;;;;;cAKnB,2BAA2B"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
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-CMFaBE3y-3XzFcH_O.mjs";
|
|
2
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
|
+
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
2
4
|
//#region ../../../3-extensions/pgvector/dist/runtime.mjs
|
|
5
|
+
function distanceTo(model, field, vector) {
|
|
6
|
+
const accessor = blindCast(model)[field];
|
|
7
|
+
if (accessor === void 0) throw new InternalError(`The model accessor has no vector field "${field}".`);
|
|
8
|
+
return accessor.cosineDistance(vector);
|
|
9
|
+
}
|
|
10
|
+
function nearestMethod(field) {
|
|
11
|
+
return (collection, ...args) => {
|
|
12
|
+
const [vector, maxDistance] = blindCast(args);
|
|
13
|
+
let shared;
|
|
14
|
+
const distance = (model) => {
|
|
15
|
+
shared ??= distanceTo(model, field, vector);
|
|
16
|
+
return shared;
|
|
17
|
+
};
|
|
18
|
+
const ordered = collection.orderBy((model) => distance(model).asc());
|
|
19
|
+
return maxDistance === void 0 ? ordered : ordered.where((model) => distance(model).lt(maxDistance));
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The run-time half of `PgvectorNearestMethods`. */
|
|
23
|
+
const pgvectorNearestMethods = {
|
|
24
|
+
id: "pgvector/nearest",
|
|
25
|
+
methodsFor: (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)]] : []))
|
|
26
|
+
};
|
|
3
27
|
const pgvectorRuntimeDescriptor = {
|
|
4
28
|
kind: "extension",
|
|
5
29
|
id: pgvectorPackMeta.id,
|
|
6
30
|
version: pgvectorPackMeta.version,
|
|
31
|
+
dataTypes: pgvectorPackMeta.dataTypes,
|
|
7
32
|
familyId: "sql",
|
|
8
33
|
targetId: "postgres",
|
|
9
34
|
types: { codecTypes: { codecDescriptors: Array.from(pgvectorCodecRegistry.values()) } },
|
|
10
35
|
codecs: () => Array.from(pgvectorCodecRegistry.values()),
|
|
11
36
|
queryOperations: () => pgvectorQueryOperations(),
|
|
37
|
+
collectionMethods: () => [pgvectorNearestMethods],
|
|
12
38
|
create() {
|
|
13
39
|
return {
|
|
14
40
|
familyId: "sql",
|
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-CMFaBE3y.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,32 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-extension-pgvector",
|
|
3
|
-
"version": "8.0.0-rc.
|
|
3
|
+
"version": "8.0.0-rc.20-dev.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"description": "pgvector embedding columns, distance operators, and indexes for Prisma
|
|
7
|
+
"description": "pgvector embedding columns, distance operators, and indexes for Prisma 8",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@prisma/orm-family-sql": "8.0.0-rc.
|
|
13
|
-
"@prisma/orm-framework": "8.0.0-rc.
|
|
14
|
-
"@prisma/orm-toolchain": "8.0.0-rc.
|
|
12
|
+
"@prisma/orm-family-sql": "8.0.0-rc.20-dev.1",
|
|
13
|
+
"@prisma/orm-framework": "8.0.0-rc.20-dev.1",
|
|
14
|
+
"@prisma/orm-toolchain": "8.0.0-rc.20-dev.1",
|
|
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.
|
|
20
|
-
"@repo/tsconfig": "8.0.0-rc.
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.2-dev.3",
|
|
19
|
+
"@internal/extension-pgvector": "8.0.0-rc.20-dev.1",
|
|
20
|
+
"@repo/tsconfig": "8.0.0-rc.20-dev.1",
|
|
21
|
+
"@repo/tsdown": "8.0.0-rc.20-dev.1",
|
|
22
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.20-dev.1",
|
|
24
23
|
"tsdown": "0.22.14",
|
|
25
|
-
"typescript": "5.9.3"
|
|
26
|
-
"vitest": "4.1.10"
|
|
24
|
+
"typescript": "5.9.3"
|
|
27
25
|
},
|
|
28
26
|
"peerDependencies": {
|
|
29
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.
|
|
27
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.20-dev.1",
|
|
30
28
|
"typescript": ">=5.9"
|
|
31
29
|
},
|
|
32
30
|
"peerDependenciesMeta": {
|
|
@@ -45,13 +43,12 @@
|
|
|
45
43
|
},
|
|
46
44
|
"repository": {
|
|
47
45
|
"type": "git",
|
|
48
|
-
"url": "https://github.com/prisma/
|
|
46
|
+
"url": "https://github.com/prisma/orm.git",
|
|
49
47
|
"directory": "packages/9-public/@prisma/orm-extension-pgvector"
|
|
50
48
|
},
|
|
51
49
|
"scripts": {
|
|
52
50
|
"build": "tsdown",
|
|
53
51
|
"lint": "biome check . --error-on-warnings",
|
|
54
|
-
"clean": "rm -rf dist src-gen"
|
|
55
|
-
"test": "vitest run"
|
|
52
|
+
"clean": "rm -rf dist src-gen"
|
|
56
53
|
}
|
|
57
54
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-BFcjjrT--s4MwG0qH.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/codec-types-BFcjjrT-.d.mts"],"mappings":";;;;;;;;;;cASc;;;KAGT;KACA;WACM;;cAEG,sBAAsB,iBAAiB;WAC1C;EACT,YAAY,YAAY,oBAAoB;EAC5C,aAAa,gBAAgB,MAAM,+BAA+B;EAClE,OAAO,iBAAiB,MAAM,mBAAmB;EACjD,OAAO,cAAc,MAAM,mBAAmB;EAC9C,WAAW,kBAAkB;EAC7B,WAAW,MAAM;;cAEL,2BAA2B,wBAAwB;YACrD;YACA,eAAe,YAAY,iBAAiB;WAC7C;WACA;WACA;WACA,cAAc,iBAAiB;EACxC,iBAAiB,QAAQ;EACzB,QAAQ,QAAQ,gBAAgB,KAAK,yBAAyB;;cAElD;WACH,QAAQ;;KAEd,eAAe,yBAAyB;;;;;;;;;KASxC,OAAO;WACD,iBAAiB;;KAEvB,aAAa"}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { n as VECTOR_MAX_DIM, r as pgVectorError, t as VECTOR_CODEC_ID } from "./errors-9-gSu3kD-Vg4apMXQ.mjs";
|
|
2
|
-
import { buildOperation, codecOf, toExpr } from "@prisma/orm-family-sql/relational-core/expression";
|
|
3
|
-
import { buildCodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/codec-descriptor-registry";
|
|
4
|
-
import { CodecImpl } from "@prisma/orm-framework/components/codec";
|
|
5
|
-
import { CastExpr, FunctionCallExpr } from "@prisma/orm-family-sql/relational-core/ast";
|
|
6
|
-
import { PostgresCodecDescriptor, definePostgresCodecs } from "@prisma/orm-target-postgres/target/codec-descriptor";
|
|
7
|
-
import { type } from "arktype";
|
|
8
|
-
//#region ../../../3-extensions/pgvector/dist/descriptor-meta-Dk8eTHcA.mjs
|
|
9
|
-
const pgvectorAuthoringTypes = { pgvector: { Vector: {
|
|
10
|
-
kind: "typeConstructor",
|
|
11
|
-
args: [{
|
|
12
|
-
kind: "number",
|
|
13
|
-
name: "length",
|
|
14
|
-
integer: true,
|
|
15
|
-
minimum: 1,
|
|
16
|
-
maximum: VECTOR_MAX_DIM
|
|
17
|
-
}],
|
|
18
|
-
output: {
|
|
19
|
-
codecId: "pg/vector@1",
|
|
20
|
-
nativeType: "vector",
|
|
21
|
-
typeParams: { length: {
|
|
22
|
-
kind: "arg",
|
|
23
|
-
index: 0
|
|
24
|
-
} }
|
|
25
|
-
}
|
|
26
|
-
} } };
|
|
27
|
-
const vectorParamsSchema = type({ length: "number" }).narrow((params, ctx) => {
|
|
28
|
-
const { length } = params;
|
|
29
|
-
if (!Number.isInteger(length)) return ctx.mustBe("an integer");
|
|
30
|
-
if (length < 1 || length > 16e3) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
|
|
31
|
-
return true;
|
|
32
|
-
});
|
|
33
|
-
const PG_VECTOR_NATIVE_TYPE = "vector";
|
|
34
|
-
function parseVector(value) {
|
|
35
|
-
if (!value.startsWith("[") || !value.endsWith("]")) throw pgVectorError("RUNTIME.DECODE_FAILED", `Invalid vector format: expected "[...]", got "${value}"`, {
|
|
36
|
-
why: "The database returned a vector value that is not in the PostgreSQL \"[x,y,z]\" text format.",
|
|
37
|
-
meta: {
|
|
38
|
-
codecId: VECTOR_CODEC_ID,
|
|
39
|
-
wirePreview: value
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
const content = value.slice(1, -1).trim();
|
|
43
|
-
return content === "" ? [] : content.split(",").map((entry) => {
|
|
44
|
-
const number = Number.parseFloat(entry.trim());
|
|
45
|
-
if (Number.isNaN(number)) throw pgVectorError("RUNTIME.DECODE_FAILED", `Invalid vector value: "${entry}" is not a number`, {
|
|
46
|
-
why: "A vector entry returned by the database could not be parsed as a number.",
|
|
47
|
-
meta: {
|
|
48
|
-
codecId: VECTOR_CODEC_ID,
|
|
49
|
-
wirePreview: value
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return number;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
var PgVectorCodec = class extends CodecImpl {
|
|
56
|
-
length;
|
|
57
|
-
constructor(descriptor, length) {
|
|
58
|
-
super(descriptor);
|
|
59
|
-
this.length = length;
|
|
60
|
-
}
|
|
61
|
-
assertVector(value, code) {
|
|
62
|
-
const meta = {
|
|
63
|
-
codecId: VECTOR_CODEC_ID,
|
|
64
|
-
expectedLength: this.length
|
|
65
|
-
};
|
|
66
|
-
if (!Array.isArray(value)) throw pgVectorError(code, "Vector value must be an array of numbers", { meta });
|
|
67
|
-
for (const element of value) {
|
|
68
|
-
if (typeof element !== "number") throw pgVectorError(code, "Vector value must contain only numbers", { meta });
|
|
69
|
-
if (!Number.isFinite(element)) throw pgVectorError(code, "Vector value must contain only finite numbers", { meta });
|
|
70
|
-
}
|
|
71
|
-
if (value.length !== this.length) throw pgVectorError(code, `Vector length mismatch: expected ${this.length}, got ${value.length}`, {
|
|
72
|
-
why: `This column is declared as vector(${this.length}); every value must have exactly that many dimensions.`,
|
|
73
|
-
meta: {
|
|
74
|
-
...meta,
|
|
75
|
-
receivedLength: value.length
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async encode(value, _ctx) {
|
|
80
|
-
this.assertVector(value, "RUNTIME.ENCODE_FAILED");
|
|
81
|
-
return `[${value.join(",")}]`;
|
|
82
|
-
}
|
|
83
|
-
async decode(wire, _ctx) {
|
|
84
|
-
if (typeof wire !== "string") throw pgVectorError("RUNTIME.DECODE_FAILED", "Vector wire value must be a string", { meta: { codecId: VECTOR_CODEC_ID } });
|
|
85
|
-
const value = parseVector(wire);
|
|
86
|
-
this.assertVector(value, "RUNTIME.DECODE_FAILED");
|
|
87
|
-
return value;
|
|
88
|
-
}
|
|
89
|
-
encodeJson(value) {
|
|
90
|
-
this.assertVector(value, "RUNTIME.ENCODE_FAILED");
|
|
91
|
-
return [...value];
|
|
92
|
-
}
|
|
93
|
-
decodeJson(json) {
|
|
94
|
-
if (!Array.isArray(json)) throw pgVectorError("RUNTIME.DECODE_FAILED", "Vector database JSON value must be an array", { meta: { codecId: VECTOR_CODEC_ID } });
|
|
95
|
-
const value = [...json];
|
|
96
|
-
this.assertVector(value, "RUNTIME.DECODE_FAILED");
|
|
97
|
-
return value;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Projects a `vector` as a JSON numeric array.
|
|
102
|
-
*
|
|
103
|
-
* A `vector` handed straight to a JSON constructor is rendered through its text
|
|
104
|
-
* output function, so it arrives as the *string* `"[1,2,3]"` rather than as an
|
|
105
|
-
* array.
|
|
106
|
-
*
|
|
107
|
-
* The route matters as much as the destination. A vector's elements are `real`,
|
|
108
|
-
* and its text form prints the shortest decimal that round-trips *as a `real`* —
|
|
109
|
-
* `0.1` for a value the application holds as `0.10000000149011612`. Reading that
|
|
110
|
-
* text back as a double therefore lands on a different number, so casting the
|
|
111
|
-
* text to `json` would lose precision the value still had. Widening each element
|
|
112
|
-
* to `float8` first keeps the exact value the `real` denotes, which is what
|
|
113
|
-
* `encodeJson` returns.
|
|
114
|
-
*/
|
|
115
|
-
const jsonArrayFromVectorElements = (expression) => FunctionCallExpr.of("array_to_json", [CastExpr.as(CastExpr.as(expression, "real[]"), "float8[]")]);
|
|
116
|
-
var PgVectorDescriptor = class extends PostgresCodecDescriptor {
|
|
117
|
-
nativeType() {
|
|
118
|
-
return PG_VECTOR_NATIVE_TYPE;
|
|
119
|
-
}
|
|
120
|
-
jsonProjection(expression) {
|
|
121
|
-
return jsonArrayFromVectorElements(expression);
|
|
122
|
-
}
|
|
123
|
-
codecId = VECTOR_CODEC_ID;
|
|
124
|
-
traits = ["equality"];
|
|
125
|
-
targetTypes = ["vector"];
|
|
126
|
-
paramsSchema = vectorParamsSchema;
|
|
127
|
-
renderOutputType(params) {
|
|
128
|
-
return `Vector<${params.length}>`;
|
|
129
|
-
}
|
|
130
|
-
factory(params) {
|
|
131
|
-
return () => new PgVectorCodec(this, params.length);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const codecDescriptorMap = { vector: new PgVectorDescriptor() };
|
|
135
|
-
/**
|
|
136
|
-
* Registry of every codec descriptor shipped by `@internal/extension-pgvector`.
|
|
137
|
-
*
|
|
138
|
-
* 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.
|
|
139
|
-
*/
|
|
140
|
-
const pgvectorCodecRegistry = buildCodecDescriptorRegistry(definePostgresCodecs(Object.values(codecDescriptorMap)));
|
|
141
|
-
const pgvectorTypeId = "pg/vector@1";
|
|
142
|
-
function pgvectorQueryOperations() {
|
|
143
|
-
return {
|
|
144
|
-
cosineDistance: {
|
|
145
|
-
self: { codecId: pgvectorTypeId },
|
|
146
|
-
impl: (self, other) => {
|
|
147
|
-
const selfCodec = codecOf(self);
|
|
148
|
-
return buildOperation({
|
|
149
|
-
method: "cosineDistance",
|
|
150
|
-
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
151
|
-
returns: {
|
|
152
|
-
codecId: "pg/float8@1",
|
|
153
|
-
nullable: false
|
|
154
|
-
},
|
|
155
|
-
lowering: {
|
|
156
|
-
targetFamily: "sql",
|
|
157
|
-
strategy: "function",
|
|
158
|
-
template: "{{self}} <=> {{arg0}}"
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
cosineSimilarity: {
|
|
164
|
-
self: { codecId: pgvectorTypeId },
|
|
165
|
-
impl: (self, other) => {
|
|
166
|
-
const selfCodec = codecOf(self);
|
|
167
|
-
return buildOperation({
|
|
168
|
-
method: "cosineSimilarity",
|
|
169
|
-
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
170
|
-
returns: {
|
|
171
|
-
codecId: "pg/float8@1",
|
|
172
|
-
nullable: false
|
|
173
|
-
},
|
|
174
|
-
lowering: {
|
|
175
|
-
targetFamily: "sql",
|
|
176
|
-
strategy: "function",
|
|
177
|
-
template: "1 - ({{self}} <=> {{arg0}})"
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
const pgvectorPackMeta = {
|
|
185
|
-
kind: "extension",
|
|
186
|
-
id: "pgvector",
|
|
187
|
-
familyId: "sql",
|
|
188
|
-
targetId: "postgres",
|
|
189
|
-
version: "0.0.1",
|
|
190
|
-
capabilities: { postgres: { "pgvector.cosine": true } },
|
|
191
|
-
authoring: { type: pgvectorAuthoringTypes },
|
|
192
|
-
types: {
|
|
193
|
-
codecTypes: {
|
|
194
|
-
codecDescriptors: Array.from(pgvectorCodecRegistry.values()),
|
|
195
|
-
import: {
|
|
196
|
-
package: "@internal/extension-pgvector/codec-types",
|
|
197
|
-
named: "CodecTypes",
|
|
198
|
-
alias: "PgVectorTypes"
|
|
199
|
-
},
|
|
200
|
-
typeImports: [{
|
|
201
|
-
package: "@internal/extension-pgvector/codec-types",
|
|
202
|
-
named: "Vector",
|
|
203
|
-
alias: "Vector"
|
|
204
|
-
}]
|
|
205
|
-
},
|
|
206
|
-
operationTypes: { import: {
|
|
207
|
-
package: "@internal/extension-pgvector/operation-types",
|
|
208
|
-
named: "OperationTypes",
|
|
209
|
-
alias: "PgVectorOperationTypes"
|
|
210
|
-
} },
|
|
211
|
-
queryOperationTypes: { import: {
|
|
212
|
-
package: "@internal/extension-pgvector/operation-types",
|
|
213
|
-
named: "QueryOperationTypes",
|
|
214
|
-
alias: "PgVectorQueryOperationTypes"
|
|
215
|
-
} },
|
|
216
|
-
storage: [{
|
|
217
|
-
typeId: pgvectorTypeId,
|
|
218
|
-
familyId: "sql",
|
|
219
|
-
targetId: "postgres",
|
|
220
|
-
nativeType: "vector"
|
|
221
|
-
}]
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
//#endregion
|
|
225
|
-
export { pgvectorPackMeta as n, pgvectorQueryOperations as r, pgvectorCodecRegistry as t };
|
|
226
|
-
|
|
227
|
-
//# sourceMappingURL=descriptor-meta-Dk8eTHcA-DeyZ_87T.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-Dk8eTHcA-DeyZ_87T.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/descriptor-meta-Dk8eTHcA.mjs"],"sourcesContent":["import { n as VECTOR_CODEC_ID, r as VECTOR_MAX_DIM, t as pgVectorError } from \"./errors-9-gSu3kD.mjs\";\nimport { buildOperation, codecOf, toExpr } from \"@internal/sql-relational-core/expression\";\nimport { buildCodecDescriptorRegistry } from \"@internal/sql-relational-core/codec-descriptor-registry\";\nimport { CodecImpl } from \"@internal/framework-components/codec\";\nimport { CastExpr, FunctionCallExpr } from \"@internal/sql-relational-core/ast\";\nimport { PostgresCodecDescriptor, definePostgresCodecs } from \"@internal/target-postgres/codec-descriptor\";\nimport { type } from \"arktype\";\n//#region src/core/authoring.ts\nconst pgvectorAuthoringTypes = { pgvector: { Vector: {\n\tkind: \"typeConstructor\",\n\targs: [{\n\t\tkind: \"number\",\n\t\tname: \"length\",\n\t\tinteger: true,\n\t\tminimum: 1,\n\t\tmaximum: VECTOR_MAX_DIM\n\t}],\n\toutput: {\n\t\tcodecId: \"pg/vector@1\",\n\t\tnativeType: \"vector\",\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/codecs.ts\nconst vectorParamsSchema = type({ length: \"number\" }).narrow((params, ctx) => {\n\tconst { length } = params;\n\tif (!Number.isInteger(length)) return ctx.mustBe(\"an integer\");\n\tif (length < 1 || length > 16e3) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);\n\treturn true;\n});\nconst PG_VECTOR_NATIVE_TYPE = \"vector\";\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)) throw pgVectorError(\"RUNTIME.DECODE_FAILED\", \"Vector database JSON value must be an array\", { meta: { codecId: VECTOR_CODEC_ID } });\n\t\tconst value = [...json];\n\t\tthis.assertVector(value, \"RUNTIME.DECODE_FAILED\");\n\t\treturn value;\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\tnativeType() {\n\t\treturn PG_VECTOR_NATIVE_TYPE;\n\t}\n\tjsonProjection(expression) {\n\t\treturn jsonArrayFromVectorElements(expression);\n\t}\n\tcodecId = VECTOR_CODEC_ID;\n\ttraits = [\"equality\"];\n\ttargetTypes = [\"vector\"];\n\tparamsSchema = vectorParamsSchema;\n\trenderOutputType(params) {\n\t\treturn `Vector<${params.length}>`;\n\t}\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\tstrategy: \"function\",\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\tstrategy: \"function\",\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\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\ttypeImports: [{\n\t\t\t\tpackage: \"@internal/extension-pgvector/codec-types\",\n\t\t\t\tnamed: \"Vector\",\n\t\t\t\talias: \"Vector\"\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\tstorage: [{\n\t\t\ttypeId: pgvectorTypeId,\n\t\t\tfamilyId: \"sql\",\n\t\t\ttargetId: \"postgres\",\n\t\t\tnativeType: \"vector\"\n\t\t}]\n\t}\n};\n//#endregion\nexport { pgvectorQueryOperations as n,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;MACd,UAAU;MACV,UAAU;KACX;IACD,CAAC;GACF;EACD;CACD;AACD;AACA,MAAM,mBAAmB;CACxB,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,cAAc,EAAE,UAAU,EAAE,mBAAmB,KAAK,EAAE;CACtD,WAAW,EAAE,MAAM,uBAAuB;CAC1C,OAAO;EACN,YAAY;GACX,kBAAkB,MAAM,KAAK,sBAAsB,OAAO,CAAC;GAC3D,QAAQ;IACP,SAAS;IACT,OAAO;IACP,OAAO;GACR;GACA,aAAa,CAAC;IACb,SAAS;IACT,OAAO;IACP,OAAO;GACR,CAAC;EACF;EACA,gBAAgB,EAAE,QAAQ;GACzB,SAAS;GACT,OAAO;GACP,OAAO;EACR,EAAE;EACF,qBAAqB,EAAE,QAAQ;GAC9B,SAAS;GACT,OAAO;GACP,OAAO;EACR,EAAE;EACF,SAAS,CAAC;GACT,QAAQ;GACR,UAAU;GACV,UAAU;GACV,YAAY;EACb,CAAC;CACF;AACD"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
2
|
-
//#region ../../../3-extensions/pgvector/dist/errors-9-gSu3kD.mjs
|
|
3
|
-
/**
|
|
4
|
-
* Codec ID for pgvector's vector type.
|
|
5
|
-
*/
|
|
6
|
-
const VECTOR_CODEC_ID = "pg/vector@1";
|
|
7
|
-
/**
|
|
8
|
-
* Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).
|
|
9
|
-
*/
|
|
10
|
-
const VECTOR_MAX_DIM = 16e3;
|
|
11
|
-
function pgVectorError(code, message, options) {
|
|
12
|
-
return structuredError(code, message, options);
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
export { VECTOR_MAX_DIM as n, pgVectorError as r, VECTOR_CODEC_ID as t };
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=errors-9-gSu3kD-Vg4apMXQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors-9-gSu3kD-Vg4apMXQ.mjs","names":[],"sources":["../../../../3-extensions/pgvector/dist/errors-9-gSu3kD.mjs"],"sourcesContent":["import { structuredError } from \"@internal/utils/structured-error\";\n//#region src/core/constants.ts\n/**\n* Codec ID for pgvector's vector type.\n*/\nconst VECTOR_CODEC_ID = \"pg/vector@1\";\n/**\n* Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).\n*/\nconst VECTOR_MAX_DIM = 16e3;\n//#endregion\n//#region src/core/errors.ts\nfunction pgVectorError(code, message, options) {\n\treturn structuredError(code, message, options);\n}\n//#endregion\nexport { VECTOR_CODEC_ID as n, VECTOR_MAX_DIM as r, pgVectorError as t };\n\n//# sourceMappingURL=errors-9-gSu3kD.mjs.map"],"mappings":";;;;;AAKA,MAAM,kBAAkB;;;;AAIxB,MAAM,iBAAiB;AAGvB,SAAS,cAAc,MAAM,SAAS,SAAS;CAC9C,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC9C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-types-D37jCdyS-ClyVMplO.d.mts","names":[],"sources":["../../../../3-extensions/pgvector/dist/operation-types-D37jCdyS.d.mts"],"mappings":";;;;KAGK,iBAAiB;WACX;WACA;;;;;;;;;KASN,oBAAoB,WAAW,kBAAkB,uBAAuB;WAClE;aACE;eACE;;aAEF,OAAO,MAAM,wCAAwC,KAAK,OAAO,wCAAwC,QAAQ;MACxH;MACA;;;WAGK;aACE;eACE;;aAEF,OAAO,MAAM,wCAAwC,KAAK,OAAO,wCAAwC,QAAQ;MACxH;MACA"}
|