Skip to content

Commit 5becaf3

Browse files
Merge pull request #1 from sveltejs/copy-tables-from-current-mcp
2 parents 6b5588c + 7f85892 commit 5becaf3

File tree

4 files changed

+78
-75
lines changed

4 files changed

+78
-75
lines changed

src/lib/server/db/schema.ts

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,80 @@ import { float_32_array } from './utils';
1212
* to the generated migration file
1313
*/
1414

15-
// this is just an example of a vector table...we can change this with the docs table later
16-
export const vector_table = sqliteTable('vector_table', {
15+
export const distillations = sqliteTable('distillations', {
1716
id: integer('id').primaryKey(),
18-
text: text('text'),
19-
vector: float_32_array('vector', { dimensions: 3 }),
17+
preset_name: text('preset_name').notNull(),
18+
version: text('version').notNull(),
19+
content: text('content').notNull(),
20+
size_kb: integer('size_kb').notNull(),
21+
document_count: integer('document_count').notNull(),
22+
distillation_job_id: integer('distillation_job_id').references(() => distillation_jobs.id),
23+
created_at: integer('created_at', { mode: 'timestamp' })
24+
.notNull()
25+
.$defaultFn(() => new Date()),
26+
});
27+
28+
export const distillation_jobs = sqliteTable('distillation_jobs', {
29+
id: integer('id').primaryKey(),
30+
preset_name: text('preset_name').notNull(),
31+
batch_id: text('batch_id'),
32+
status: text('status', { enum: ['pending', 'processing', 'completed', 'failed'] }).notNull(),
33+
model_used: text('model_used').notNull(),
34+
total_files: integer('total_files').notNull(),
35+
processed_files: integer('processed_files').notNull().default(0),
36+
successful_files: integer('successful_files').notNull().default(0),
37+
minimize_applied: integer('minimize_applied', { mode: 'boolean' }).notNull().default(false),
38+
total_input_tokens: integer('total_input_tokens').notNull().default(0),
39+
total_output_tokens: integer('total_output_tokens').notNull().default(0),
40+
started_at: integer('started_at', { mode: 'timestamp' }),
41+
completed_at: integer('completed_at', { mode: 'timestamp' }),
42+
error_message: text('error_message'),
43+
metadata: text('metadata', { mode: 'json' })
44+
.$type<Record<string, unknown>>()
45+
.notNull()
46+
.default({}),
47+
created_at: integer('created_at', { mode: 'timestamp' })
48+
.notNull()
49+
.$defaultFn(() => new Date()),
50+
updated_at: integer('updated_at', { mode: 'timestamp' })
51+
.notNull()
52+
.$defaultFn(() => new Date()),
53+
});
54+
55+
export const content = sqliteTable('content', {
56+
id: integer('id').primaryKey(),
57+
path: text('path').notNull(),
58+
filename: text('filename').notNull(),
59+
content: text('content').notNull(),
60+
size_bytes: integer('size_bytes').notNull(),
61+
embeddings: float_32_array('embeddings', { dimensions: 1024 }),
62+
metadata: text('metadata', { mode: 'json' })
63+
.$type<Record<string, unknown>>()
64+
.notNull()
65+
.default({}),
66+
created_at: integer('created_at', { mode: 'timestamp' })
67+
.notNull()
68+
.$defaultFn(() => new Date()),
69+
updated_at: integer('updated_at', { mode: 'timestamp' })
70+
.notNull()
71+
.$defaultFn(() => new Date()),
72+
});
73+
74+
export const content_distilled = sqliteTable('content_distilled', {
75+
id: integer('id').primaryKey(),
76+
path: text('path').notNull(),
77+
filename: text('filename').notNull(),
78+
content: text('content').notNull(),
79+
size_bytes: integer('size_bytes').notNull(),
80+
embeddings: float_32_array('embeddings', { dimensions: 1024 }),
81+
metadata: text('metadata', { mode: 'json' })
82+
.$type<Record<string, unknown>>()
83+
.notNull()
84+
.default({}),
85+
created_at: integer('created_at', { mode: 'timestamp' })
86+
.notNull()
87+
.$defaultFn(() => new Date()),
88+
updated_at: integer('updated_at', { mode: 'timestamp' })
89+
.notNull()
90+
.$defaultFn(() => new Date()),
2091
});

src/lib/server/db/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export function vector(arr: number[]) {
2626
* .execute();
2727
*/
2828
export function distance(column: Column, arr: number[], as = 'distance') {
29-
return sql<number>`vector_distance_cos(${column}, vector32(${JSON.stringify(arr)}))`.as(as);
29+
return sql<number>`CASE ${column} ISNULL WHEN 1 THEN 1 ELSE vector_distance_cos(${column}, vector32(${JSON.stringify(arr)})) END`.as(
30+
as,
31+
);
3032
}
3133

3234
/**

src/routes/+page.server.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/routes/+page.svelte

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
<script lang="ts">
2-
import { enhance } from '$app/forms';
3-
4-
let { data } = $props();
5-
</script>
6-
71
<h1>Official Svelte MCP</h1>
8-
9-
<form method="POST" use:enhance>
10-
<textarea name="text" rows="4" cols="50" placeholder="Enter text to store in the vector database"
11-
></textarea>
12-
<br />
13-
<button>Submit</button>
14-
</form>
15-
16-
Comparing with
17-
<pre>{data.sentence}</pre>
18-
19-
{#each data.top as item (item.id)}
20-
<p>{item.text} - {item.distance}</p>
21-
{/each}

0 commit comments

Comments
 (0)