-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.ts
More file actions
46 lines (44 loc) · 1.62 KB
/
Copy pathcontract.ts
File metadata and controls
46 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { int4Column, textColumn } from '@prisma-next/adapter-postgres/column-types';
import { vectorColumn } from '@prisma-next/extension-paradedb/column-types';
import paradedb from '@prisma-next/extension-paradedb/pack';
import sqlFamily from '@prisma-next/family-sql/pack';
import { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';
import postgresPack from '@prisma-next/target-postgres/pack';
import { postgresCreateNamespace } from '@prisma-next/target-postgres/types';
export const contract = defineContract(
{
family: sqlFamily,
target: postgresPack,
extensionPacks: { paradedb },
createNamespace: postgresCreateNamespace,
},
({ field, model }) => {
const Item = model('Item', {
fields: {
id: field.column(int4Column).id(),
description: field.column(textColumn),
category: field.column(textColumn),
rating: field.column(int4Column),
embedding: field.column(vectorColumn(3)),
},
});
return {
models: {
Item: Item.sql(({ cols, constraints }) => ({
table: 'item',
indexes: [
// Listing `cols.embedding` here requires vector-in-index support
// (pg_search 0.25.0+ has it, but the docker image may lag), so the
// demo indexes text fields only and vector Top-K falls back to an
// unaccelerated sort.
constraints.index([cols.category, cols.description, cols.id, cols.rating], {
type: 'paradedb',
options: { key_field: 'id' },
name: 'item_bm25_idx',
}),
],
})),
},
};
},
);