@prisma/orm-extension-pgvector 8.0.0-rc.18-dev.4 → 8.0.0-rc.18-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime.d.mts +34 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +25 -0
- package/dist/runtime.mjs.map +1 -1
- package/package.json +9 -9
package/dist/runtime.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { t as VECTOR_CODEC_ID } from "./constants-BjLQgqqq-CMdE2ode.mjs";
|
|
2
|
+
import { n as Vector } from "./codec-types-DRADMdid-CfbNjCYL.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,5 +1,29 @@
|
|
|
1
1
|
import { n as pgvectorPackMeta, r as pgvectorQueryOperations, t as pgvectorCodecRegistry } from "./descriptor-meta-CTD2p1Ov-mxKdNuqt.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,
|
|
@@ -10,6 +34,7 @@ const pgvectorRuntimeDescriptor = {
|
|
|
10
34
|
types: { codecTypes: { codecDescriptors: Array.from(pgvectorCodecRegistry.values()) } },
|
|
11
35
|
codecs: () => Array.from(pgvectorCodecRegistry.values()),
|
|
12
36
|
queryOperations: () => pgvectorQueryOperations(),
|
|
37
|
+
collectionMethods: () => [pgvectorNearestMethods],
|
|
13
38
|
create() {
|
|
14
39
|
return {
|
|
15
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-CTD2p1Ov.mjs\";\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\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":";;AAEA,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,SAAS;EACR,OAAO;GACN,UAAU;GACV,UAAU;EACX;CACD;AACD"}
|
|
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-CTD2p1Ov.mjs\";\nimport \"./constants-D8Ccy-f4.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { InternalError } from \"@internal/utils/internal-error\";\n//#region src/core/nearest-collection-method.ts\nfunction distanceTo(model, field, vector) {\n\tconst accessor = blindCast(model)[field];\n\tif (accessor === void 0) throw new InternalError(`The model accessor has no vector field \"${field}\".`);\n\treturn accessor.cosineDistance(vector);\n}\nfunction nearestMethod(field) {\n\treturn (collection, ...args) => {\n\t\tconst [vector, maxDistance] = blindCast(args);\n\t\tlet shared;\n\t\tconst distance = (model) => {\n\t\t\tshared ??= distanceTo(model, field, vector);\n\t\t\treturn shared;\n\t\t};\n\t\tconst ordered = collection.orderBy((model) => distance(model).asc());\n\t\treturn maxDistance === void 0 ? ordered : ordered.where((model) => distance(model).lt(maxDistance));\n\t};\n}\n/** The run-time half of `PgvectorNearestMethods`. */\nconst pgvectorNearestMethods = {\n\tid: \"pgvector/nearest\",\n\tmethodsFor: (model) => Object.fromEntries(Object.entries(model.fields).flatMap(([name, field]) => !field.many && field.type.kind === \"scalar\" && field.type.codecId === \"pg/vector@1\" ? [[`${name}_nearest`, nearestMethod(name)]] : []))\n};\n//#endregion\n//#region src/exports/runtime.ts\nconst pgvectorRuntimeDescriptor = {\n\tkind: \"extension\",\n\tid: pgvectorPackMeta.id,\n\tversion: pgvectorPackMeta.version,\n\tdataTypes: pgvectorPackMeta.dataTypes,\n\tfamilyId: \"sql\",\n\ttargetId: \"postgres\",\n\ttypes: { codecTypes: { codecDescriptors: Array.from(pgvectorCodecRegistry.values()) } },\n\tcodecs: () => Array.from(pgvectorCodecRegistry.values()),\n\tqueryOperations: () => pgvectorQueryOperations(),\n\tcollectionMethods: () => [pgvectorNearestMethods],\n\tcreate() {\n\t\treturn {\n\t\t\tfamilyId: \"sql\",\n\t\t\ttargetId: \"postgres\"\n\t\t};\n\t}\n};\n//#endregion\nexport { pgvectorRuntimeDescriptor as default, pgvectorCodecRegistry };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;AAKA,SAAS,WAAW,OAAO,OAAO,QAAQ;CACzC,MAAM,WAAW,UAAU,KAAK,CAAC,CAAC;CAClC,IAAI,aAAa,KAAK,GAAG,MAAM,IAAI,cAAc,2CAA2C,MAAM,GAAG;CACrG,OAAO,SAAS,eAAe,MAAM;AACtC;AACA,SAAS,cAAc,OAAO;CAC7B,QAAQ,YAAY,GAAG,SAAS;EAC/B,MAAM,CAAC,QAAQ,eAAe,UAAU,IAAI;EAC5C,IAAI;EACJ,MAAM,YAAY,UAAU;GAC3B,WAAW,WAAW,OAAO,OAAO,MAAM;GAC1C,OAAO;EACR;EACA,MAAM,UAAU,WAAW,SAAS,UAAU,SAAS,KAAK,CAAC,CAAC,IAAI,CAAC;EACnE,OAAO,gBAAgB,KAAK,IAAI,UAAU,QAAQ,OAAO,UAAU,SAAS,KAAK,CAAC,CAAC,GAAG,WAAW,CAAC;CACnG;AACD;;AAEA,MAAM,yBAAyB;CAC9B,IAAI;CACJ,aAAa,UAAU,OAAO,YAAY,OAAO,QAAQ,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,WAAW,CAAC,MAAM,QAAQ,MAAM,KAAK,SAAS,YAAY,MAAM,KAAK,YAAY,gBAAgB,CAAC,CAAC,GAAG,KAAK,WAAW,cAAc,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACzO;AAGA,MAAM,4BAA4B;CACjC,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,WAAW,iBAAiB;CAC5B,UAAU;CACV,UAAU;CACV,OAAO,EAAE,YAAY,EAAE,kBAAkB,MAAM,KAAK,sBAAsB,OAAO,CAAC,EAAE,EAAE;CACtF,cAAc,MAAM,KAAK,sBAAsB,OAAO,CAAC;CACvD,uBAAuB,wBAAwB;CAC/C,yBAAyB,CAAC,sBAAsB;CAChD,SAAS;EACR,OAAO;GACN,UAAU;GACV,UAAU;EACX;CACD;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-extension-pgvector",
|
|
3
|
-
"version": "8.0.0-rc.18-dev.
|
|
3
|
+
"version": "8.0.0-rc.18-dev.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@prisma/orm-family-sql": "8.0.0-rc.18-dev.
|
|
13
|
-
"@prisma/orm-framework": "8.0.0-rc.18-dev.
|
|
14
|
-
"@prisma/orm-toolchain": "8.0.0-rc.18-dev.
|
|
12
|
+
"@prisma/orm-family-sql": "8.0.0-rc.18-dev.6",
|
|
13
|
+
"@prisma/orm-framework": "8.0.0-rc.18-dev.6",
|
|
14
|
+
"@prisma/orm-toolchain": "8.0.0-rc.18-dev.6",
|
|
15
15
|
"@standard-schema/spec": "^1.1.0",
|
|
16
16
|
"arktype": "^2.2.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@internal/extension-pgvector": "8.0.0-rc.18-dev.
|
|
20
|
-
"@repo/tsconfig": "8.0.0-rc.18-dev.
|
|
21
|
-
"@repo/tsdown": "8.0.0-rc.18-dev.
|
|
22
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.
|
|
19
|
+
"@internal/extension-pgvector": "8.0.0-rc.18-dev.6",
|
|
20
|
+
"@repo/tsconfig": "8.0.0-rc.18-dev.6",
|
|
21
|
+
"@repo/tsdown": "8.0.0-rc.18-dev.6",
|
|
22
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.6",
|
|
23
23
|
"tsdown": "0.22.14",
|
|
24
24
|
"typescript": "5.9.3"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.
|
|
27
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.6",
|
|
28
28
|
"typescript": ">=5.9"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|