feat: add semantic fact search and embeddings
This commit is contained in:
@@ -2,6 +2,7 @@ import type { Kysely } from 'kysely';
|
||||
|
||||
import {
|
||||
FACTS_TABLE,
|
||||
FACT_EMBEDDINGS_TABLE,
|
||||
FACT_TOPICS_TABLE,
|
||||
TOPIC_ALIASES_TABLE,
|
||||
TOPIC_RELATIONS_TABLE,
|
||||
@@ -39,6 +40,21 @@ export async function initializeSchema(
|
||||
.addColumn('updated_at', 'text', (column) => column.notNull())
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable(FACT_EMBEDDINGS_TABLE)
|
||||
.ifNotExists()
|
||||
.addColumn('fact_id', 'text', (column) =>
|
||||
column.notNull().references(`${FACTS_TABLE}.id`).onDelete('cascade'),
|
||||
)
|
||||
.addColumn('model', 'text', (column) => column.notNull())
|
||||
.addColumn('dimensions', 'integer', (column) => column.notNull())
|
||||
.addColumn('embedding', 'text', (column) => column.notNull())
|
||||
.addColumn('content_hash', 'text', (column) => column.notNull())
|
||||
.addColumn('created_at', 'text', (column) => column.notNull())
|
||||
.addColumn('updated_at', 'text', (column) => column.notNull())
|
||||
.addPrimaryKeyConstraint('fact_embeddings_pk', ['fact_id', 'model'])
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable(FACT_TOPICS_TABLE)
|
||||
.ifNotExists()
|
||||
@@ -96,6 +112,13 @@ export async function initializeSchema(
|
||||
.column('fact_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('fact_embeddings_model_idx')
|
||||
.ifNotExists()
|
||||
.on(FACT_EMBEDDINGS_TABLE)
|
||||
.column('model')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('topic_relations_parent_topic_id_idx')
|
||||
.ifNotExists()
|
||||
|
||||
Reference in New Issue
Block a user