@prisma-next/extension-pgvector 0.3.0-dev.4 → 0.3.0-dev.41
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 +18 -11
- package/dist/codec-types.d.mts +41 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +1 -0
- package/dist/column-types.d.mts +33 -0
- package/dist/column-types.d.mts.map +1 -0
- package/dist/column-types.mjs +36 -0
- package/dist/column-types.mjs.map +1 -0
- package/dist/constants-BmZpaev5.mjs +13 -0
- package/dist/constants-BmZpaev5.mjs.map +1 -0
- package/dist/control.d.mts +7 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +49 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-BADTQp0u.mjs +57 -0
- package/dist/descriptor-meta-BADTQp0u.mjs.map +1 -0
- package/dist/operation-types.d.mts +32 -0
- package/dist/operation-types.d.mts.map +1 -0
- package/dist/operation-types.mjs +1 -0
- package/dist/pack.d.mts +46 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +9 -0
- package/dist/pack.mjs.map +1 -0
- package/dist/runtime.d.mts +7 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +74 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +39 -50
- package/src/core/codecs.ts +66 -0
- package/src/core/constants.ts +9 -0
- package/src/core/descriptor-meta.ts +63 -0
- package/src/exports/codec-types.ts +7 -0
- package/src/exports/column-types.ts +46 -0
- package/src/exports/control.ts +70 -0
- package/src/exports/operation-types.ts +7 -0
- package/src/exports/pack.ts +5 -0
- package/src/exports/runtime.ts +58 -0
- package/src/types/codec-types.ts +32 -0
- package/src/types/operation-types.ts +31 -0
- package/dist/exports/chunk-QZXQPESZ.js +0 -60
- package/dist/exports/chunk-QZXQPESZ.js.map +0 -1
- package/dist/exports/codec-types.d.ts +0 -12
- package/dist/exports/codec-types.js +0 -1
- package/dist/exports/codec-types.js.map +0 -1
- package/dist/exports/column-types.d.ts +0 -12
- package/dist/exports/column-types.js +0 -9
- package/dist/exports/column-types.js.map +0 -1
- package/dist/exports/control.d.ts +0 -9
- package/dist/exports/control.js +0 -67
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/operation-types.d.ts +0 -32
- package/dist/exports/operation-types.js +0 -1
- package/dist/exports/operation-types.js.map +0 -1
- package/dist/exports/pack.d.ts +0 -52
- package/dist/exports/pack.js +0 -11
- package/dist/exports/pack.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -9
- package/dist/exports/runtime.js +0 -86
- package/dist/exports/runtime.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,70 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
|
-
"@prisma-next/cli": "0.3.0-dev.
|
|
9
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
10
|
-
"@prisma-next/contract-authoring": "0.3.0-dev.
|
|
11
|
-
"@prisma-next/core-control-plane": "0.3.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.3.0-dev.
|
|
13
|
-
"@prisma-next/sql-operations": "0.3.0-dev.
|
|
14
|
-
"@prisma-next/sql-relational-core": "0.3.0-dev.
|
|
15
|
-
"@prisma-next/sql-runtime": "0.3.0-dev.
|
|
16
|
-
"@prisma-next/sql-schema-ir": "0.3.0-dev.
|
|
8
|
+
"@prisma-next/cli": "0.3.0-dev.41",
|
|
9
|
+
"@prisma-next/contract": "0.3.0-dev.41",
|
|
10
|
+
"@prisma-next/contract-authoring": "0.3.0-dev.41",
|
|
11
|
+
"@prisma-next/core-control-plane": "0.3.0-dev.41",
|
|
12
|
+
"@prisma-next/family-sql": "0.3.0-dev.41",
|
|
13
|
+
"@prisma-next/sql-operations": "0.3.0-dev.41",
|
|
14
|
+
"@prisma-next/sql-relational-core": "0.3.0-dev.41",
|
|
15
|
+
"@prisma-next/sql-runtime": "0.3.0-dev.41",
|
|
16
|
+
"@prisma-next/sql-schema-ir": "0.3.0-dev.41"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"
|
|
20
|
-
"tsup": "8.5.1",
|
|
19
|
+
"tsdown": "0.18.4",
|
|
21
20
|
"typescript": "5.9.3",
|
|
22
|
-
"vitest": "4.0.
|
|
23
|
-
"@prisma-next/adapter-postgres": "0.3.0-dev.
|
|
24
|
-
"@prisma-next/operations": "0.3.0-dev.
|
|
25
|
-
"@prisma-next/sql-contract": "0.3.0-dev.
|
|
26
|
-
"@prisma-next/sql-contract-ts": "0.3.0-dev.
|
|
27
|
-
"@prisma-next/sql-lane": "0.3.0-dev.
|
|
28
|
-
"@prisma-next/test-utils": "0.0.1"
|
|
21
|
+
"vitest": "4.0.17",
|
|
22
|
+
"@prisma-next/adapter-postgres": "0.3.0-dev.41",
|
|
23
|
+
"@prisma-next/operations": "0.3.0-dev.41",
|
|
24
|
+
"@prisma-next/sql-contract": "0.3.0-dev.41",
|
|
25
|
+
"@prisma-next/sql-contract-ts": "0.3.0-dev.41",
|
|
26
|
+
"@prisma-next/sql-lane": "0.3.0-dev.41",
|
|
27
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
28
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
29
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
32
34
|
],
|
|
33
35
|
"exports": {
|
|
34
|
-
"./
|
|
35
|
-
"./
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"./runtime":
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
"./codec-types": {
|
|
48
|
-
"types": "./dist/exports/codec-types.d.ts",
|
|
49
|
-
"import": "./dist/exports/codec-types.js"
|
|
50
|
-
},
|
|
51
|
-
"./column-types": {
|
|
52
|
-
"types": "./dist/exports/column-types.d.ts",
|
|
53
|
-
"import": "./dist/exports/column-types.js"
|
|
54
|
-
},
|
|
55
|
-
"./operation-types": {
|
|
56
|
-
"types": "./dist/exports/operation-types.d.ts",
|
|
57
|
-
"import": "./dist/exports/operation-types.js"
|
|
58
|
-
}
|
|
36
|
+
"./codec-types": "./dist/codec-types.mjs",
|
|
37
|
+
"./column-types": "./dist/column-types.mjs",
|
|
38
|
+
"./control": "./dist/control.mjs",
|
|
39
|
+
"./operation-types": "./dist/operation-types.mjs",
|
|
40
|
+
"./pack": "./dist/pack.mjs",
|
|
41
|
+
"./runtime": "./dist/runtime.mjs",
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
47
|
+
"directory": "packages/3-extensions/pgvector"
|
|
59
48
|
},
|
|
60
49
|
"scripts": {
|
|
61
|
-
"build": "
|
|
50
|
+
"build": "tsdown",
|
|
62
51
|
"test": "vitest run",
|
|
63
52
|
"test:coverage": "vitest run --coverage",
|
|
64
53
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
65
|
-
"lint": "biome check . --
|
|
66
|
-
"lint:fix": "biome check --write .
|
|
67
|
-
"lint:fix:unsafe": "biome check --write --unsafe .
|
|
68
|
-
"clean": "
|
|
54
|
+
"lint": "biome check . --error-on-warnings",
|
|
55
|
+
"lint:fix": "biome check --write .",
|
|
56
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
57
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
69
58
|
}
|
|
70
59
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector codec implementation for pgvector extension.
|
|
3
|
+
*
|
|
4
|
+
* Provides encoding/decoding for the `vector` PostgreSQL type.
|
|
5
|
+
* Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';
|
|
9
|
+
|
|
10
|
+
const pgVectorCodec = codec<'pg/vector@1', string, number[]>({
|
|
11
|
+
typeId: 'pg/vector@1',
|
|
12
|
+
targetTypes: ['vector'],
|
|
13
|
+
encode: (value: number[]): string => {
|
|
14
|
+
// Validate that value is an array of numbers
|
|
15
|
+
if (!Array.isArray(value)) {
|
|
16
|
+
throw new Error('Vector value must be an array of numbers');
|
|
17
|
+
}
|
|
18
|
+
if (!value.every((v) => typeof v === 'number')) {
|
|
19
|
+
throw new Error('Vector value must contain only numbers');
|
|
20
|
+
}
|
|
21
|
+
// Format as PostgreSQL vector text format: [1,2,3]
|
|
22
|
+
// PostgreSQL's pg library requires the vector format string
|
|
23
|
+
return `[${value.join(',')}]`;
|
|
24
|
+
},
|
|
25
|
+
decode: (wire: string): number[] => {
|
|
26
|
+
// Handle string format from PostgreSQL: [1,2,3]
|
|
27
|
+
if (typeof wire !== 'string') {
|
|
28
|
+
throw new Error('Vector wire value must be a string');
|
|
29
|
+
}
|
|
30
|
+
// Parse PostgreSQL vector format: [1,2,3]
|
|
31
|
+
if (!wire.startsWith('[') || !wire.endsWith(']')) {
|
|
32
|
+
throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
|
|
33
|
+
}
|
|
34
|
+
const content = wire.slice(1, -1).trim();
|
|
35
|
+
if (content === '') {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const values = content.split(',').map((v) => {
|
|
39
|
+
const num = Number.parseFloat(v.trim());
|
|
40
|
+
if (Number.isNaN(num)) {
|
|
41
|
+
throw new Error(`Invalid vector value: "${v}" is not a number`);
|
|
42
|
+
}
|
|
43
|
+
return num;
|
|
44
|
+
});
|
|
45
|
+
return values;
|
|
46
|
+
},
|
|
47
|
+
meta: {
|
|
48
|
+
db: {
|
|
49
|
+
sql: {
|
|
50
|
+
postgres: {
|
|
51
|
+
nativeType: 'vector',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Build codec definitions using the builder DSL
|
|
59
|
+
const codecs = defineCodecs().add('vector', pgVectorCodec);
|
|
60
|
+
|
|
61
|
+
// Export derived structures directly from codecs builder
|
|
62
|
+
export const codecDefinitions = codecs.codecDefinitions;
|
|
63
|
+
export const dataTypes = codecs.dataTypes;
|
|
64
|
+
|
|
65
|
+
// Export types derived from codecs builder
|
|
66
|
+
export type CodecTypes = typeof codecs.CodecTypes;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { SqlOperationSignature } from '@prisma-next/sql-operations';
|
|
2
|
+
|
|
3
|
+
const pgvectorTypeId = 'pg/vector@1' as const;
|
|
4
|
+
|
|
5
|
+
const cosineLowering = {
|
|
6
|
+
targetFamily: 'sql',
|
|
7
|
+
strategy: 'function',
|
|
8
|
+
template: '1 - ({{self}} <=> {{arg0}})',
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
const cosineDistanceOperation = Object.freeze({
|
|
12
|
+
method: 'cosineDistance',
|
|
13
|
+
args: [{ kind: 'param' }],
|
|
14
|
+
returns: { kind: 'builtin', type: 'number' },
|
|
15
|
+
lowering: cosineLowering,
|
|
16
|
+
} as const);
|
|
17
|
+
|
|
18
|
+
export const pgvectorOperationSignature: SqlOperationSignature = {
|
|
19
|
+
forTypeId: pgvectorTypeId,
|
|
20
|
+
...cosineDistanceOperation,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const pgvectorPackMeta = {
|
|
24
|
+
kind: 'extension',
|
|
25
|
+
id: 'pgvector',
|
|
26
|
+
familyId: 'sql',
|
|
27
|
+
targetId: 'postgres',
|
|
28
|
+
version: '0.0.1',
|
|
29
|
+
capabilities: {
|
|
30
|
+
postgres: {
|
|
31
|
+
'pgvector/cosine': true,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
types: {
|
|
35
|
+
codecTypes: {
|
|
36
|
+
import: {
|
|
37
|
+
package: '@prisma-next/extension-pgvector/codec-types',
|
|
38
|
+
named: 'CodecTypes',
|
|
39
|
+
alias: 'PgVectorTypes',
|
|
40
|
+
},
|
|
41
|
+
typeImports: [
|
|
42
|
+
{
|
|
43
|
+
package: '@prisma-next/extension-pgvector/codec-types',
|
|
44
|
+
named: 'Vector',
|
|
45
|
+
alias: 'Vector',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
parameterized: {
|
|
49
|
+
[pgvectorTypeId]: 'Vector<{{length}}>',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
operationTypes: {
|
|
53
|
+
import: {
|
|
54
|
+
package: '@prisma-next/extension-pgvector/operation-types',
|
|
55
|
+
named: 'OperationTypes',
|
|
56
|
+
alias: 'PgVectorOperationTypes',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
storage: [
|
|
60
|
+
{ typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
} as const;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column type descriptors for pgvector extension.
|
|
3
|
+
*
|
|
4
|
+
* These descriptors provide both codecId and nativeType for use in contract authoring.
|
|
5
|
+
* They are derived from the same source of truth as codec definitions and manifests.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';
|
|
9
|
+
import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Static vector column descriptor without dimension.
|
|
13
|
+
* Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
|
|
14
|
+
*/
|
|
15
|
+
export const vectorColumn = {
|
|
16
|
+
codecId: VECTOR_CODEC_ID,
|
|
17
|
+
nativeType: 'vector',
|
|
18
|
+
} as const satisfies ColumnTypeDescriptor;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Factory for creating dimensioned vector column descriptors.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* .column('embedding', { type: vector(1536), nullable: false })
|
|
26
|
+
* // Produces: nativeType: 'vector(1536)', typeParams: { length: 1536 }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
30
|
+
* @returns A column type descriptor with `typeParams.length` set
|
|
31
|
+
* @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
32
|
+
*/
|
|
33
|
+
export function vector<N extends number>(
|
|
34
|
+
length: N,
|
|
35
|
+
): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {
|
|
36
|
+
if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {
|
|
37
|
+
throw new RangeError(
|
|
38
|
+
`pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
codecId: VECTOR_CODEC_ID,
|
|
43
|
+
nativeType: `vector(${length})`,
|
|
44
|
+
typeParams: { length },
|
|
45
|
+
} as const;
|
|
46
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { SchemaIssue } from '@prisma-next/core-control-plane/types';
|
|
2
|
+
import type {
|
|
3
|
+
ComponentDatabaseDependencies,
|
|
4
|
+
SqlControlExtensionDescriptor,
|
|
5
|
+
} from '@prisma-next/family-sql/control';
|
|
6
|
+
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
7
|
+
import { pgvectorOperationSignature, pgvectorPackMeta } from '../core/descriptor-meta';
|
|
8
|
+
|
|
9
|
+
function verifyVectorExtensionInstalled(schema: SqlSchemaIR): readonly SchemaIssue[] {
|
|
10
|
+
if (!schema.extensions.includes('vector')) {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
kind: 'extension_missing',
|
|
14
|
+
table: '',
|
|
15
|
+
message: 'Extension "vector" is missing from database (required by pgvector)',
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {
|
|
23
|
+
init: [
|
|
24
|
+
{
|
|
25
|
+
id: 'postgres.extension.vector',
|
|
26
|
+
label: 'Enable vector extension',
|
|
27
|
+
install: [
|
|
28
|
+
{
|
|
29
|
+
id: 'extension.vector',
|
|
30
|
+
label: 'Enable extension "vector"',
|
|
31
|
+
summary: 'Ensures the vector extension is available for pgvector operations',
|
|
32
|
+
operationClass: 'additive',
|
|
33
|
+
target: { id: 'postgres' },
|
|
34
|
+
precheck: [
|
|
35
|
+
{
|
|
36
|
+
description: 'verify extension "vector" is not already enabled',
|
|
37
|
+
sql: "SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
execute: [
|
|
41
|
+
{
|
|
42
|
+
description: 'create extension "vector"',
|
|
43
|
+
sql: 'CREATE EXTENSION IF NOT EXISTS vector',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
postcheck: [
|
|
47
|
+
{
|
|
48
|
+
description: 'confirm extension "vector" is enabled',
|
|
49
|
+
sql: "SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
verifyDatabaseDependencyInstalled: verifyVectorExtensionInstalled,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {
|
|
60
|
+
...pgvectorPackMeta,
|
|
61
|
+
operationSignatures: () => [pgvectorOperationSignature],
|
|
62
|
+
databaseDependencies: pgvectorDatabaseDependencies,
|
|
63
|
+
create: () => ({
|
|
64
|
+
familyId: 'sql' as const,
|
|
65
|
+
targetId: 'postgres' as const,
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { pgvectorExtensionDescriptor };
|
|
70
|
+
export default pgvectorExtensionDescriptor;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
2
|
+
import type {
|
|
3
|
+
RuntimeParameterizedCodecDescriptor,
|
|
4
|
+
SqlRuntimeExtensionDescriptor,
|
|
5
|
+
} from '@prisma-next/sql-runtime';
|
|
6
|
+
import { type as arktype } from 'arktype';
|
|
7
|
+
import { codecDefinitions } from '../core/codecs';
|
|
8
|
+
import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';
|
|
9
|
+
import { pgvectorOperationSignature, pgvectorPackMeta } from '../core/descriptor-meta';
|
|
10
|
+
|
|
11
|
+
const vectorParamsSchema = arktype({
|
|
12
|
+
length: 'number',
|
|
13
|
+
}).narrow((params, ctx) => {
|
|
14
|
+
const { length } = params;
|
|
15
|
+
if (!Number.isInteger(length)) {
|
|
16
|
+
return ctx.mustBe('an integer');
|
|
17
|
+
}
|
|
18
|
+
if (length < 1 || length > VECTOR_MAX_DIM) {
|
|
19
|
+
return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const parameterizedCodecDescriptors = [
|
|
25
|
+
{
|
|
26
|
+
codecId: VECTOR_CODEC_ID,
|
|
27
|
+
paramsSchema: vectorParamsSchema,
|
|
28
|
+
},
|
|
29
|
+
] as const satisfies ReadonlyArray<
|
|
30
|
+
RuntimeParameterizedCodecDescriptor<{ readonly length: number }>
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
function createPgvectorCodecRegistry() {
|
|
34
|
+
const registry = createCodecRegistry();
|
|
35
|
+
for (const def of Object.values(codecDefinitions)) {
|
|
36
|
+
registry.register(def.codec);
|
|
37
|
+
}
|
|
38
|
+
return registry;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
|
|
42
|
+
kind: 'extension' as const,
|
|
43
|
+
id: pgvectorPackMeta.id,
|
|
44
|
+
version: pgvectorPackMeta.version,
|
|
45
|
+
familyId: 'sql' as const,
|
|
46
|
+
targetId: 'postgres' as const,
|
|
47
|
+
codecs: createPgvectorCodecRegistry,
|
|
48
|
+
operationSignatures: () => [pgvectorOperationSignature],
|
|
49
|
+
parameterizedCodecs: () => parameterizedCodecDescriptors,
|
|
50
|
+
create() {
|
|
51
|
+
return {
|
|
52
|
+
familyId: 'sql' as const,
|
|
53
|
+
targetId: 'postgres' as const,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default pgvectorRuntimeDescriptor;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codec type definitions for pgvector extension.
|
|
3
|
+
*
|
|
4
|
+
* This file exports type-only definitions for codec input/output types.
|
|
5
|
+
* These types are imported by contract.d.ts files for compile-time type inference.
|
|
6
|
+
*
|
|
7
|
+
* Runtime codec implementations are provided by the extension's codec registry.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CodecTypes as CoreCodecTypes } from '../core/codecs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Type-level branded vector.
|
|
14
|
+
*
|
|
15
|
+
* The runtime values are plain number arrays, but parameterized column typing can
|
|
16
|
+
* carry the dimension at the type level (e.g. Vector<1536>).
|
|
17
|
+
*/
|
|
18
|
+
export type Vector<N extends number = number> = number[] & { readonly __vectorLength?: N };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Codec types for pgvector.
|
|
22
|
+
*
|
|
23
|
+
* - Scalar output remains `number[]` (runtime representation).
|
|
24
|
+
* - `parameterizedOutput` enables lane typing to compute `Vector<N>` from column `typeParams`.
|
|
25
|
+
*/
|
|
26
|
+
export type CodecTypes = CoreCodecTypes & {
|
|
27
|
+
readonly 'pg/vector@1': CoreCodecTypes['pg/vector@1'] & {
|
|
28
|
+
readonly parameterizedOutput: <P extends { readonly length: number }>(
|
|
29
|
+
params: P,
|
|
30
|
+
) => P extends { readonly length: infer N extends number } ? Vector<N> : Vector<number>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation type definitions for pgvector extension.
|
|
3
|
+
*
|
|
4
|
+
* This file exports type-only definitions for operation method signatures.
|
|
5
|
+
* These types are imported by contract.d.ts files for compile-time type inference.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Operation types for pgvector extension.
|
|
10
|
+
* Maps typeId to operation methods.
|
|
11
|
+
*/
|
|
12
|
+
export type OperationTypes = {
|
|
13
|
+
readonly 'pg/vector@1': {
|
|
14
|
+
readonly cosineDistance: {
|
|
15
|
+
readonly args: readonly [
|
|
16
|
+
{
|
|
17
|
+
readonly kind: 'param';
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
readonly returns: {
|
|
21
|
+
readonly kind: 'builtin';
|
|
22
|
+
readonly type: 'number';
|
|
23
|
+
};
|
|
24
|
+
readonly lowering: {
|
|
25
|
+
readonly targetFamily: 'sql';
|
|
26
|
+
readonly strategy: 'function';
|
|
27
|
+
readonly template: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/core/descriptor-meta.ts
|
|
2
|
-
var pgvectorTypeId = "pg/vector@1";
|
|
3
|
-
var cosineLowering = {
|
|
4
|
-
targetFamily: "sql",
|
|
5
|
-
strategy: "function",
|
|
6
|
-
template: "1 - ({{self}} <=> {{arg0}})"
|
|
7
|
-
};
|
|
8
|
-
var cosineDistanceOperation = Object.freeze({
|
|
9
|
-
method: "cosineDistance",
|
|
10
|
-
args: [{ kind: "param" }],
|
|
11
|
-
returns: { kind: "builtin", type: "number" },
|
|
12
|
-
lowering: cosineLowering
|
|
13
|
-
});
|
|
14
|
-
var pgvectorPackMeta = {
|
|
15
|
-
kind: "extension",
|
|
16
|
-
id: "pgvector",
|
|
17
|
-
familyId: "sql",
|
|
18
|
-
targetId: "postgres",
|
|
19
|
-
version: "0.0.1",
|
|
20
|
-
capabilities: {
|
|
21
|
-
postgres: {
|
|
22
|
-
"pgvector/cosine": true
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
types: {
|
|
26
|
-
codecTypes: {
|
|
27
|
-
import: {
|
|
28
|
-
package: "@prisma-next/extension-pgvector/codec-types",
|
|
29
|
-
named: "CodecTypes",
|
|
30
|
-
alias: "PgVectorTypes"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
operationTypes: {
|
|
34
|
-
import: {
|
|
35
|
-
package: "@prisma-next/extension-pgvector/operation-types",
|
|
36
|
-
named: "OperationTypes",
|
|
37
|
-
alias: "PgVectorOperationTypes"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
storage: [
|
|
41
|
-
{ typeId: pgvectorTypeId, familyId: "sql", targetId: "postgres", nativeType: "vector" }
|
|
42
|
-
]
|
|
43
|
-
},
|
|
44
|
-
operations: [
|
|
45
|
-
{
|
|
46
|
-
for: pgvectorTypeId,
|
|
47
|
-
...cosineDistanceOperation
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
};
|
|
51
|
-
var pgvectorRuntimeOperation = {
|
|
52
|
-
forTypeId: pgvectorTypeId,
|
|
53
|
-
...cosineDistanceOperation
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
pgvectorPackMeta,
|
|
58
|
-
pgvectorRuntimeOperation
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=chunk-QZXQPESZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/descriptor-meta.ts"],"sourcesContent":["import type { ExtensionPackRef } from '@prisma-next/contract/framework-components';\nimport type { SqlOperationSignature } from '@prisma-next/sql-operations';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\nconst cosineLowering = {\n targetFamily: 'sql',\n strategy: 'function',\n template: '1 - ({{self}} <=> {{arg0}})',\n} as const;\n\n/**\n * Shared operation definition used by both pack metadata and runtime descriptor.\n * Frozen to prevent accidental mutation.\n */\nconst cosineDistanceOperation = Object.freeze({\n method: 'cosineDistance',\n args: [{ kind: 'param' }],\n returns: { kind: 'builtin', type: 'number' },\n lowering: cosineLowering,\n} as const);\n\nexport const pgvectorPackMeta = {\n kind: 'extension',\n id: 'pgvector',\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'pgvector/cosine': true,\n },\n },\n types: {\n codecTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'CodecTypes',\n alias: 'PgVectorTypes',\n },\n },\n operationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'OperationTypes',\n alias: 'PgVectorOperationTypes',\n },\n },\n storage: [\n { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },\n ],\n },\n operations: [\n {\n for: pgvectorTypeId,\n ...cosineDistanceOperation,\n },\n ],\n} as const satisfies ExtensionPackRef<'sql', 'postgres'>;\n\nexport const pgvectorRuntimeOperation: SqlOperationSignature = {\n forTypeId: pgvectorTypeId,\n ...cosineDistanceOperation,\n};\n"],"mappings":";AAGA,IAAM,iBAAiB;AAEvB,IAAM,iBAAiB;AAAA,EACrB,cAAc;AAAA,EACd,UAAU;AAAA,EACV,UAAU;AACZ;AAMA,IAAM,0BAA0B,OAAO,OAAO;AAAA,EAC5C,QAAQ;AAAA,EACR,MAAM,CAAC,EAAE,MAAM,QAAQ,CAAC;AAAA,EACxB,SAAS,EAAE,MAAM,WAAW,MAAM,SAAS;AAAA,EAC3C,UAAU;AACZ,CAAU;AAEH,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAS;AAAA,EACT,cAAc;AAAA,IACZ,UAAU;AAAA,MACR,mBAAmB;AAAA,IACrB;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,YAAY;AAAA,MACV,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,gBAAgB;AAAA,MACd,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,EAAE,QAAQ,gBAAgB,UAAU,OAAO,UAAU,YAAY,YAAY,SAAS;AAAA,IACxF;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV;AAAA,MACE,KAAK;AAAA,MACL,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,IAAM,2BAAkD;AAAA,EAC7D,WAAW;AAAA,EACX,GAAG;AACL;","names":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as _prisma_next_sql_relational_core_ast from '@prisma-next/sql-relational-core/ast';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Vector codec implementation for pgvector extension.
|
|
5
|
-
*
|
|
6
|
-
* Provides encoding/decoding for the `vector` PostgreSQL type.
|
|
7
|
-
* Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
|
|
8
|
-
*/
|
|
9
|
-
declare const codecs: _prisma_next_sql_relational_core_ast.CodecDefBuilder<{} & Record<"vector", _prisma_next_sql_relational_core_ast.Codec<"pg/vector@1", string, number[]>>>;
|
|
10
|
-
type CodecTypes = typeof codecs.CodecTypes;
|
|
11
|
-
|
|
12
|
-
export type { CodecTypes };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=codec-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Column type descriptors for pgvector extension.
|
|
3
|
-
*
|
|
4
|
-
* These descriptors provide both codecId and nativeType for use in contract authoring.
|
|
5
|
-
* They are derived from the same source of truth as codec definitions and manifests.
|
|
6
|
-
*/
|
|
7
|
-
declare const vectorColumn: {
|
|
8
|
-
readonly codecId: "pg/vector@1";
|
|
9
|
-
readonly nativeType: "vector";
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { vectorColumn };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for pgvector extension.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring.\n * They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';\n\nexport const vectorColumn = {\n codecId: 'pg/vector@1',\n nativeType: 'vector',\n} as const satisfies ColumnTypeDescriptor;\n"],"mappings":";AASO,IAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,EACT,YAAY;AACd;","names":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SqlControlExtensionDescriptor } from '@prisma-next/family-sql/control';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* pgvector extension descriptor for CLI config.
|
|
5
|
-
* Declares database dependencies for the 'vector' Postgres extension.
|
|
6
|
-
*/
|
|
7
|
-
declare const pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'>;
|
|
8
|
-
|
|
9
|
-
export { pgvectorExtensionDescriptor as default, pgvectorExtensionDescriptor };
|