@prisma-next/extension-pgvector 0.1.0-dev.3 → 0.1.0-dev.30
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 +15 -4
- package/dist/exports/chunk-QZXQPESZ.js +60 -0
- package/dist/exports/chunk-QZXQPESZ.js.map +1 -0
- package/dist/exports/control.d.ts +4 -3
- package/dist/exports/control.js +54 -41
- package/dist/exports/control.js.map +1 -1
- package/dist/exports/pack.d.ts +52 -0
- package/dist/exports/pack.js +11 -0
- package/dist/exports/pack.js.map +1 -0
- package/dist/exports/runtime.d.ts +5 -5
- package/dist/exports/runtime.js +30 -26
- package/dist/exports/runtime.js.map +1 -1
- package/package.json +24 -14
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ This extension pack adds support for the `vector` data type and vector similarit
|
|
|
12
12
|
- **Vector Operations**: Registers vector similarity operations (e.g., `cosineDistance`) for use in queries
|
|
13
13
|
- **CLI Integration**: Provides extension descriptor for `prisma-next.config.ts` configuration
|
|
14
14
|
- **Runtime Extension**: Registers codecs and operations at runtime for vector column operations
|
|
15
|
+
- **Pack Ref Export**: Ships a pure `/pack` entrypoint for TypeScript contract authoring without runtime filesystem access
|
|
16
|
+
- **Database Dependencies**: Declares the `vector` Postgres extension as a database dependency, which the migration planner emits as a `CREATE EXTENSION IF NOT EXISTS vector` operation and the verifier checks against the schema IR
|
|
15
17
|
|
|
16
18
|
## Dependencies
|
|
17
19
|
|
|
@@ -28,12 +30,16 @@ pnpm add @prisma-next/extension-pgvector
|
|
|
28
30
|
|
|
29
31
|
## Database Setup
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
The pgvector extension declares its database requirements as component-owned database dependencies. When using the `prisma-next db init` command, the migration planner automatically includes a `CREATE EXTENSION IF NOT EXISTS vector` operation.
|
|
34
|
+
|
|
35
|
+
For manual database setup, ensure the pgvector extension is installed:
|
|
32
36
|
|
|
33
37
|
```sql
|
|
34
38
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
35
39
|
```
|
|
36
40
|
|
|
41
|
+
The verifier will check for the presence of the `vector` extension in your database schema and report an error if it's missing.
|
|
42
|
+
|
|
37
43
|
## Configuration
|
|
38
44
|
|
|
39
45
|
Add the extension to your `prisma-next.config.ts`:
|
|
@@ -42,7 +48,7 @@ Add the extension to your `prisma-next.config.ts`:
|
|
|
42
48
|
import { defineConfig } from '@prisma-next/cli/config-types';
|
|
43
49
|
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
44
50
|
import sql from '@prisma-next/family-sql/cli';
|
|
45
|
-
import postgres from '@prisma-next/
|
|
51
|
+
import postgres from '@prisma-next/target-postgres/control';
|
|
46
52
|
import pgvector from '@prisma-next/extension-pgvector/control';
|
|
47
53
|
|
|
48
54
|
export default defineConfig({
|
|
@@ -57,7 +63,7 @@ export default defineConfig({
|
|
|
57
63
|
|
|
58
64
|
### Contract Definition
|
|
59
65
|
|
|
60
|
-
Add vector columns to your contract:
|
|
66
|
+
Add vector columns to your contract and enable the namespace via pack refs:
|
|
61
67
|
|
|
62
68
|
```typescript
|
|
63
69
|
import { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
@@ -65,11 +71,14 @@ import type { CodecTypes } from '@prisma-next/adapter-postgres/codec-types';
|
|
|
65
71
|
import { int4Column, textColumn } from '@prisma-next/adapter-postgres/column-types';
|
|
66
72
|
import type { CodecTypes as PgVectorCodecTypes } from '@prisma-next/extension-pgvector/codec-types';
|
|
67
73
|
import { vectorColumn } from '@prisma-next/extension-pgvector/column-types';
|
|
74
|
+
import pgvector from '@prisma-next/extension-pgvector/pack';
|
|
75
|
+
import postgres from '@prisma-next/target-postgres/pack';
|
|
68
76
|
|
|
69
77
|
type AllCodecTypes = CodecTypes & PgVectorCodecTypes;
|
|
70
78
|
|
|
71
79
|
export const contract = defineContract<AllCodecTypes>()
|
|
72
|
-
.target(
|
|
80
|
+
.target(postgres)
|
|
81
|
+
.extensionPacks({ pgvector })
|
|
73
82
|
.table('post', (t) =>
|
|
74
83
|
t
|
|
75
84
|
.column('id', { type: int4Column, nullable: false })
|
|
@@ -171,3 +180,5 @@ The extension declares the following capabilities:
|
|
|
171
180
|
- [Prisma Next Architecture Overview](../../../docs/Architecture%20Overview.md)
|
|
172
181
|
- [Extension Packs Guide](../../../docs/reference/Extension-Packs-Naming-and-Layout.md)
|
|
173
182
|
|
|
183
|
+
Pack refs (`@prisma-next/extension-pgvector/pack`) are pure data objects generated from the hydrated manifest (`src/core/manifest.ts`), so TypeScript contract builders can enable the pgvector namespace in both emit and no-emit workflows without touching the filesystem.
|
|
184
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SqlControlExtensionDescriptor } from '@prisma-next/family-sql/control';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* pgvector extension descriptor for CLI config.
|
|
5
|
+
* Declares database dependencies for the 'vector' Postgres extension.
|
|
5
6
|
*/
|
|
6
|
-
declare const pgvectorExtensionDescriptor:
|
|
7
|
+
declare const pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'>;
|
|
7
8
|
|
|
8
|
-
export { pgvectorExtensionDescriptor as default };
|
|
9
|
+
export { pgvectorExtensionDescriptor as default, pgvectorExtensionDescriptor };
|
package/dist/exports/control.js
CHANGED
|
@@ -1,47 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pgvectorPackMeta
|
|
3
|
+
} from "./chunk-QZXQPESZ.js";
|
|
4
|
+
|
|
1
5
|
// src/exports/control.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
alias: "string"
|
|
12
|
-
});
|
|
13
|
-
var ExtensionPackManifestSchema = type({
|
|
14
|
-
id: "string",
|
|
15
|
-
version: "string",
|
|
16
|
-
"targets?": type({ "[string]": type({ "minVersion?": "string" }) }),
|
|
17
|
-
"capabilities?": "Record<string, unknown>",
|
|
18
|
-
"types?": type({
|
|
19
|
-
"codecTypes?": type({
|
|
20
|
-
import: TypesImportSpecSchema
|
|
21
|
-
}),
|
|
22
|
-
"operationTypes?": type({
|
|
23
|
-
import: TypesImportSpecSchema
|
|
24
|
-
})
|
|
25
|
-
}),
|
|
26
|
-
"operations?": "unknown[]"
|
|
27
|
-
});
|
|
28
|
-
function loadExtensionManifest() {
|
|
29
|
-
const manifestPath = join(__dirname, "../../packs/manifest.json");
|
|
30
|
-
const manifestJson = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
31
|
-
const result = ExtensionPackManifestSchema(manifestJson);
|
|
32
|
-
if (result instanceof type.errors) {
|
|
33
|
-
const messages = result.map((p) => p.message).join("; ");
|
|
34
|
-
throw new Error(`Invalid extension manifest structure at ${manifestPath}: ${messages}`);
|
|
6
|
+
function verifyVectorExtensionInstalled(schema) {
|
|
7
|
+
if (!schema.extensions.includes("vector")) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
kind: "extension_missing",
|
|
11
|
+
table: "",
|
|
12
|
+
message: 'Extension "vector" is missing from database (required by pgvector)'
|
|
13
|
+
}
|
|
14
|
+
];
|
|
35
15
|
}
|
|
36
|
-
return
|
|
16
|
+
return [];
|
|
37
17
|
}
|
|
18
|
+
var pgvectorDatabaseDependencies = {
|
|
19
|
+
init: [
|
|
20
|
+
{
|
|
21
|
+
id: "postgres.extension.vector",
|
|
22
|
+
label: "Enable vector extension",
|
|
23
|
+
install: [
|
|
24
|
+
{
|
|
25
|
+
id: "extension.vector",
|
|
26
|
+
label: 'Enable extension "vector"',
|
|
27
|
+
summary: "Ensures the vector extension is available for pgvector operations",
|
|
28
|
+
operationClass: "additive",
|
|
29
|
+
target: { id: "postgres" },
|
|
30
|
+
precheck: [
|
|
31
|
+
{
|
|
32
|
+
description: 'verify extension "vector" is not already enabled',
|
|
33
|
+
sql: "SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
execute: [
|
|
37
|
+
{
|
|
38
|
+
description: 'create extension "vector"',
|
|
39
|
+
sql: "CREATE EXTENSION IF NOT EXISTS vector"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
postcheck: [
|
|
43
|
+
{
|
|
44
|
+
description: 'confirm extension "vector" is enabled',
|
|
45
|
+
sql: "SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
verifyDatabaseDependencyInstalled: verifyVectorExtensionInstalled
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
38
54
|
var pgvectorExtensionDescriptor = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
targetId: "postgres",
|
|
42
|
-
// pgvector is postgres-specific
|
|
43
|
-
id: "pgvector",
|
|
44
|
-
manifest: loadExtensionManifest(),
|
|
55
|
+
...pgvectorPackMeta,
|
|
56
|
+
databaseDependencies: pgvectorDatabaseDependencies,
|
|
45
57
|
create: () => ({
|
|
46
58
|
familyId: "sql",
|
|
47
59
|
targetId: "postgres"
|
|
@@ -49,6 +61,7 @@ var pgvectorExtensionDescriptor = {
|
|
|
49
61
|
};
|
|
50
62
|
var control_default = pgvectorExtensionDescriptor;
|
|
51
63
|
export {
|
|
52
|
-
control_default as default
|
|
64
|
+
control_default as default,
|
|
65
|
+
pgvectorExtensionDescriptor
|
|
53
66
|
};
|
|
54
67
|
//# sourceMappingURL=control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/control.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/exports/control.ts"],"sourcesContent":["import type { SchemaIssue } from '@prisma-next/core-control-plane/types';\nimport type {\n ComponentDatabaseDependencies,\n SqlControlExtensionDescriptor,\n} from '@prisma-next/family-sql/control';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { pgvectorPackMeta } from '../core/descriptor-meta';\n\n/**\n * Pure verification hook: checks whether the 'vector' extension is installed\n * based on the in-memory schema IR (no DB I/O).\n */\nfunction verifyVectorExtensionInstalled(schema: SqlSchemaIR): readonly SchemaIssue[] {\n if (!schema.extensions.includes('vector')) {\n return [\n {\n kind: 'extension_missing',\n table: '',\n message: 'Extension \"vector\" is missing from database (required by pgvector)',\n },\n ];\n }\n return [];\n}\n\n/**\n * Database dependencies for the pgvector extension.\n * Declares the 'vector' Postgres extension as a required dependency.\n */\nconst pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {\n init: [\n {\n id: 'postgres.extension.vector',\n label: 'Enable vector extension',\n install: [\n {\n id: 'extension.vector',\n label: 'Enable extension \"vector\"',\n summary: 'Ensures the vector extension is available for pgvector operations',\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: 'verify extension \"vector\" is not already enabled',\n sql: \"SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n execute: [\n {\n description: 'create extension \"vector\"',\n sql: 'CREATE EXTENSION IF NOT EXISTS vector',\n },\n ],\n postcheck: [\n {\n description: 'confirm extension \"vector\" is enabled',\n sql: \"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n },\n ],\n verifyDatabaseDependencyInstalled: verifyVectorExtensionInstalled,\n },\n ],\n};\n\n/**\n * pgvector extension descriptor for CLI config.\n * Declares database dependencies for the 'vector' Postgres extension.\n */\nconst pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {\n ...pgvectorPackMeta,\n databaseDependencies: pgvectorDatabaseDependencies,\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n};\n\nexport { pgvectorExtensionDescriptor };\nexport default pgvectorExtensionDescriptor;\n"],"mappings":";;;;;AAYA,SAAS,+BAA+B,QAA6C;AACnF,MAAI,CAAC,OAAO,WAAW,SAAS,QAAQ,GAAG;AACzC,WAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,QACN,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACA,SAAO,CAAC;AACV;AAMA,IAAM,+BAAuE;AAAA,EAC3E,MAAM;AAAA,IACJ;AAAA,MACE,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,QACP;AAAA,UACE,IAAI;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,UACT,gBAAgB;AAAA,UAChB,QAAQ,EAAE,IAAI,WAAW;AAAA,UACzB,UAAU;AAAA,YACR;AAAA,cACE,aAAa;AAAA,cACb,KAAK;AAAA,YACP;AAAA,UACF;AAAA,UACA,SAAS;AAAA,YACP;AAAA,cACE,aAAa;AAAA,cACb,KAAK;AAAA,YACP;AAAA,UACF;AAAA,UACA,WAAW;AAAA,YACT;AAAA,cACE,aAAa;AAAA,cACb,KAAK;AAAA,YACP;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,mCAAmC;AAAA,IACrC;AAAA,EACF;AACF;AAMA,IAAM,8BAAyE;AAAA,EAC7E,GAAG;AAAA,EACH,sBAAsB;AAAA,EACtB,QAAQ,OAAO;AAAA,IACb,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AACF;AAGA,IAAO,kBAAQ;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare const pgvectorPack: {
|
|
2
|
+
readonly kind: "extension";
|
|
3
|
+
readonly id: "pgvector";
|
|
4
|
+
readonly familyId: "sql";
|
|
5
|
+
readonly targetId: "postgres";
|
|
6
|
+
readonly version: "0.0.1";
|
|
7
|
+
readonly capabilities: {
|
|
8
|
+
readonly postgres: {
|
|
9
|
+
readonly 'pgvector/cosine': true;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
readonly types: {
|
|
13
|
+
readonly codecTypes: {
|
|
14
|
+
readonly import: {
|
|
15
|
+
readonly package: "@prisma-next/extension-pgvector/codec-types";
|
|
16
|
+
readonly named: "CodecTypes";
|
|
17
|
+
readonly alias: "PgVectorTypes";
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
readonly operationTypes: {
|
|
21
|
+
readonly import: {
|
|
22
|
+
readonly package: "@prisma-next/extension-pgvector/operation-types";
|
|
23
|
+
readonly named: "OperationTypes";
|
|
24
|
+
readonly alias: "PgVectorOperationTypes";
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
readonly storage: readonly [{
|
|
28
|
+
readonly typeId: "pg/vector@1";
|
|
29
|
+
readonly familyId: "sql";
|
|
30
|
+
readonly targetId: "postgres";
|
|
31
|
+
readonly nativeType: "vector";
|
|
32
|
+
}];
|
|
33
|
+
};
|
|
34
|
+
readonly operations: readonly [{
|
|
35
|
+
readonly method: "cosineDistance";
|
|
36
|
+
readonly args: readonly [{
|
|
37
|
+
readonly kind: "param";
|
|
38
|
+
}];
|
|
39
|
+
readonly returns: {
|
|
40
|
+
readonly kind: "builtin";
|
|
41
|
+
readonly type: "number";
|
|
42
|
+
};
|
|
43
|
+
readonly lowering: {
|
|
44
|
+
readonly targetFamily: "sql";
|
|
45
|
+
readonly strategy: "function";
|
|
46
|
+
readonly template: "1 - ({{self}} <=> {{arg0}})";
|
|
47
|
+
};
|
|
48
|
+
readonly for: "pg/vector@1";
|
|
49
|
+
}];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { pgvectorPack as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/pack.ts"],"sourcesContent":["import { pgvectorPackMeta } from '../core/descriptor-meta';\n\nconst pgvectorPack = pgvectorPackMeta;\n\nexport default pgvectorPack;\n"],"mappings":";;;;;AAEA,IAAM,eAAe;AAErB,IAAO,eAAQ;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Provides
|
|
4
|
+
* pgvector SQL runtime extension descriptor.
|
|
5
|
+
* Provides metadata and factory for creating runtime extension instances.
|
|
6
6
|
*/
|
|
7
|
-
declare
|
|
7
|
+
declare const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export { pgvectorRuntimeDescriptor as default };
|
package/dist/exports/runtime.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pgvectorPackMeta,
|
|
3
|
+
pgvectorRuntimeOperation
|
|
4
|
+
} from "./chunk-QZXQPESZ.js";
|
|
5
|
+
|
|
1
6
|
// src/exports/runtime.ts
|
|
2
7
|
import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
|
|
3
8
|
|
|
@@ -50,33 +55,32 @@ var codecDefinitions = codecs.codecDefinitions;
|
|
|
50
55
|
var dataTypes = codecs.dataTypes;
|
|
51
56
|
|
|
52
57
|
// src/exports/runtime.ts
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return registry;
|
|
61
|
-
},
|
|
62
|
-
operations() {
|
|
63
|
-
return [
|
|
64
|
-
{
|
|
65
|
-
forTypeId: "pg/vector@1",
|
|
66
|
-
method: "cosineDistance",
|
|
67
|
-
args: [{ kind: "param" }],
|
|
68
|
-
returns: { kind: "builtin", type: "number" },
|
|
69
|
-
lowering: {
|
|
70
|
-
targetFamily: "sql",
|
|
71
|
-
strategy: "function",
|
|
72
|
-
template: "1 - ({{self}} <=> {{arg0}})"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
];
|
|
58
|
+
var PgVectorRuntimeExtensionInstance = class {
|
|
59
|
+
familyId = "sql";
|
|
60
|
+
targetId = "postgres";
|
|
61
|
+
codecs() {
|
|
62
|
+
const registry = createCodecRegistry();
|
|
63
|
+
for (const def of Object.values(codecDefinitions)) {
|
|
64
|
+
registry.register(def.codec);
|
|
76
65
|
}
|
|
77
|
-
|
|
78
|
-
}
|
|
66
|
+
return registry;
|
|
67
|
+
}
|
|
68
|
+
operations() {
|
|
69
|
+
return [pgvectorRuntimeOperation];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var pgvectorRuntimeDescriptor = {
|
|
73
|
+
kind: "extension",
|
|
74
|
+
id: pgvectorPackMeta.id,
|
|
75
|
+
version: pgvectorPackMeta.version,
|
|
76
|
+
familyId: "sql",
|
|
77
|
+
targetId: "postgres",
|
|
78
|
+
create() {
|
|
79
|
+
return new PgVectorRuntimeExtensionInstance();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var runtime_default = pgvectorRuntimeDescriptor;
|
|
79
83
|
export {
|
|
80
|
-
|
|
84
|
+
runtime_default as default
|
|
81
85
|
};
|
|
82
86
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/runtime.ts","../../src/core/codecs.ts"],"sourcesContent":["import type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/runtime.ts","../../src/core/codecs.ts"],"sourcesContent":["import type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n SqlRuntimeExtensionDescriptor,\n SqlRuntimeExtensionInstance,\n} from '@prisma-next/sql-runtime';\nimport { codecDefinitions } from '../core/codecs';\nimport { pgvectorPackMeta, pgvectorRuntimeOperation } from '../core/descriptor-meta';\n\n/**\n * pgvector SQL runtime extension instance.\n * Provides codecs and operations for vector data type and similarity operations.\n */\nclass PgVectorRuntimeExtensionInstance implements SqlRuntimeExtensionInstance<'postgres'> {\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n codecs(): CodecRegistry {\n const registry = createCodecRegistry();\n // Register all codecs from codecDefinitions\n for (const def of Object.values(codecDefinitions)) {\n registry.register(def.codec);\n }\n return registry;\n }\n\n operations(): ReadonlyArray<SqlOperationSignature> {\n return [pgvectorRuntimeOperation];\n }\n}\n\n/**\n * pgvector SQL runtime extension descriptor.\n * Provides metadata and factory for creating runtime extension instances.\n */\nconst pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: pgvectorPackMeta.id,\n version: pgvectorPackMeta.version,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n create(): SqlRuntimeExtensionInstance<'postgres'> {\n return new PgVectorRuntimeExtensionInstance();\n },\n};\n\nexport default pgvectorRuntimeDescriptor;\n","/**\n * Vector codec implementation for pgvector extension.\n *\n * Provides encoding/decoding for the `vector` PostgreSQL type.\n * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).\n */\n\nimport { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';\n\nconst pgVectorCodec = codec<'pg/vector@1', string, number[]>({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\n encode: (value: number[]): string => {\n // Validate that value is an array of numbers\n if (!Array.isArray(value)) {\n throw new Error('Vector value must be an array of numbers');\n }\n if (!value.every((v) => typeof v === 'number')) {\n throw new Error('Vector value must contain only numbers');\n }\n // Format as PostgreSQL vector text format: [1,2,3]\n // PostgreSQL's pg library requires the vector format string\n return `[${value.join(',')}]`;\n },\n decode: (wire: string): number[] => {\n // Handle string format from PostgreSQL: [1,2,3]\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n // Parse PostgreSQL vector format: [1,2,3]\n if (!wire.startsWith('[') || !wire.endsWith(']')) {\n throw new Error(`Invalid vector format: expected \"[...]\", got \"${wire}\"`);\n }\n const content = wire.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n const values = content.split(',').map((v) => {\n const num = Number.parseFloat(v.trim());\n if (Number.isNaN(num)) {\n throw new Error(`Invalid vector value: \"${v}\" is not a number`);\n }\n return num;\n });\n return values;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'vector',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs().add('vector', pgVectorCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\n// Export types derived from codecs builder\nexport type CodecTypes = typeof codecs.CodecTypes;\n"],"mappings":";;;;;;AAEA,SAAS,2BAA2B;;;ACKpC,SAAS,OAAO,oBAAoB;AAEpC,IAAM,gBAAgB,MAAuC;AAAA,EAC3D,QAAQ;AAAA,EACR,aAAa,CAAC,QAAQ;AAAA,EACtB,QAAQ,CAAC,UAA4B;AAEnC,QAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,YAAM,IAAI,MAAM,0CAA0C;AAAA,IAC5D;AACA,QAAI,CAAC,MAAM,MAAM,CAAC,MAAM,OAAO,MAAM,QAAQ,GAAG;AAC9C,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAGA,WAAO,IAAI,MAAM,KAAK,GAAG,CAAC;AAAA,EAC5B;AAAA,EACA,QAAQ,CAAC,SAA2B;AAElC,QAAI,OAAO,SAAS,UAAU;AAC5B,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AAEA,QAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,GAAG,GAAG;AAChD,YAAM,IAAI,MAAM,iDAAiD,IAAI,GAAG;AAAA,IAC1E;AACA,UAAM,UAAU,KAAK,MAAM,GAAG,EAAE,EAAE,KAAK;AACvC,QAAI,YAAY,IAAI;AAClB,aAAO,CAAC;AAAA,IACV;AACA,UAAM,SAAS,QAAQ,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM;AAC3C,YAAM,MAAM,OAAO,WAAW,EAAE,KAAK,CAAC;AACtC,UAAI,OAAO,MAAM,GAAG,GAAG;AACrB,cAAM,IAAI,MAAM,0BAA0B,CAAC,mBAAmB;AAAA,MAChE;AACA,aAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EACA,MAAM;AAAA,IACJ,IAAI;AAAA,MACF,KAAK;AAAA,QACH,UAAU;AAAA,UACR,YAAY;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAGD,IAAM,SAAS,aAAa,EAAE,IAAI,UAAU,aAAa;AAGlD,IAAM,mBAAmB,OAAO;AAChC,IAAM,YAAY,OAAO;;;ADhDhC,IAAM,mCAAN,MAA0F;AAAA,EAC/E,WAAW;AAAA,EACX,WAAW;AAAA,EAEpB,SAAwB;AACtB,UAAM,WAAW,oBAAoB;AAErC,eAAW,OAAO,OAAO,OAAO,gBAAgB,GAAG;AACjD,eAAS,SAAS,IAAI,KAAK;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,aAAmD;AACjD,WAAO,CAAC,wBAAwB;AAAA,EAClC;AACF;AAMA,IAAM,4BAAuE;AAAA,EAC3E,MAAM;AAAA,EACN,IAAI,iBAAiB;AAAA,EACrB,SAAS,iBAAiB;AAAA,EAC1B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAkD;AAChD,WAAO,IAAI,iCAAiC;AAAA,EAC9C;AACF;AAEA,IAAO,kBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
|
-
"@prisma-next/cli": "0.1.0-dev.
|
|
9
|
-
"@prisma-next/contract": "0.1.0-dev.
|
|
10
|
-
"@prisma-next/contract-authoring": "0.1.0-dev.
|
|
11
|
-
"@prisma-next/core-control-plane": "0.1.0-dev.
|
|
12
|
-
"@prisma-next/sql
|
|
13
|
-
"@prisma-next/sql-
|
|
14
|
-
"@prisma-next/sql-
|
|
8
|
+
"@prisma-next/cli": "0.1.0-dev.30",
|
|
9
|
+
"@prisma-next/contract": "0.1.0-dev.30",
|
|
10
|
+
"@prisma-next/contract-authoring": "0.1.0-dev.30",
|
|
11
|
+
"@prisma-next/core-control-plane": "0.1.0-dev.30",
|
|
12
|
+
"@prisma-next/family-sql": "0.1.0-dev.30",
|
|
13
|
+
"@prisma-next/sql-operations": "0.1.0-dev.30",
|
|
14
|
+
"@prisma-next/sql-relational-core": "0.1.0-dev.30",
|
|
15
|
+
"@prisma-next/sql-schema-ir": "0.1.0-dev.30",
|
|
16
|
+
"@prisma-next/sql-runtime": "0.1.0-dev.30"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|
|
19
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
17
20
|
"tsup": "^8.3.0",
|
|
18
21
|
"typescript": "^5.9.3",
|
|
19
22
|
"vite-tsconfig-paths": "^5.1.4",
|
|
20
|
-
"vitest": "^
|
|
21
|
-
"@prisma-next/adapter-postgres": "0.1.0-dev.
|
|
22
|
-
"@prisma-next/
|
|
23
|
-
"@prisma-next/
|
|
24
|
-
"@prisma-next/sql-contract-ts": "0.1.0-dev.
|
|
25
|
-
"@prisma-next/sql-lane": "0.1.0-dev.
|
|
23
|
+
"vitest": "^4.0.16",
|
|
24
|
+
"@prisma-next/adapter-postgres": "0.1.0-dev.30",
|
|
25
|
+
"@prisma-next/sql-contract": "0.1.0-dev.30",
|
|
26
|
+
"@prisma-next/operations": "0.1.0-dev.30",
|
|
27
|
+
"@prisma-next/sql-contract-ts": "0.1.0-dev.30",
|
|
28
|
+
"@prisma-next/sql-lane": "0.1.0-dev.30",
|
|
26
29
|
"@prisma-next/test-utils": "0.0.1"
|
|
27
30
|
},
|
|
28
31
|
"files": [
|
|
29
32
|
"dist"
|
|
30
33
|
],
|
|
31
34
|
"exports": {
|
|
35
|
+
"./package.json": "./package.json",
|
|
32
36
|
"./control": {
|
|
33
37
|
"types": "./dist/exports/control.d.ts",
|
|
34
38
|
"import": "./dist/exports/control.js"
|
|
@@ -37,6 +41,10 @@
|
|
|
37
41
|
"types": "./dist/exports/runtime.d.ts",
|
|
38
42
|
"import": "./dist/exports/runtime.js"
|
|
39
43
|
},
|
|
44
|
+
"./pack": {
|
|
45
|
+
"types": "./dist/exports/pack.d.ts",
|
|
46
|
+
"import": "./dist/exports/pack.js"
|
|
47
|
+
},
|
|
40
48
|
"./codec-types": {
|
|
41
49
|
"types": "./dist/exports/codec-types.d.ts",
|
|
42
50
|
"import": "./dist/exports/codec-types.js"
|
|
@@ -56,6 +64,8 @@
|
|
|
56
64
|
"test:coverage": "vitest run --coverage",
|
|
57
65
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
58
66
|
"lint": "biome check . --config-path ../../../biome.json --error-on-warnings",
|
|
67
|
+
"lint:fix": "biome check --write . --config-path ../../../biome.json",
|
|
68
|
+
"lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../biome.json",
|
|
59
69
|
"clean": "node ../../../scripts/clean.mjs"
|
|
60
70
|
}
|
|
61
71
|
}
|