setup postgres and kyseley for most data instead of milvus

This commit is contained in:
Avraham Sakal
2025-07-13 20:14:53 -04:00
parent 511f05af83
commit 7a9f0c956c
27 changed files with 1338 additions and 169 deletions
+8
View File
@@ -0,0 +1,8 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { default as PublicSchema } from './public/PublicSchema';
type Database = PublicSchema;
export default Database;
@@ -0,0 +1,25 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
/** Identifier type for public.conversations */
export type ConversationsId = number & { __brand: 'public.conversations' };
/** Represents the table public.conversations */
export default interface ConversationsTable {
id: ColumnType<ConversationsId, never, never>;
title: ColumnType<string | null, string | null, string | null>;
created_at: ColumnType<string | null, string | null, string | null>;
user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>;
}
export type Conversations = Selectable<ConversationsTable>;
export type NewConversations = Insertable<ConversationsTable>;
export type ConversationsUpdate = Updateable<ConversationsTable>;
+32
View File
@@ -0,0 +1,32 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { FactsId } from './Facts';
import type { ConversationsId } from './Conversations';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
/** Identifier type for public.fact_triggers */
export type FactTriggersId = number & { __brand: 'public.fact_triggers' };
/** Represents the table public.fact_triggers */
export default interface FactTriggersTable {
id: ColumnType<FactTriggersId, never, never>;
fact_id: ColumnType<FactsId | null, FactsId | null, FactsId | null>;
trigger_phrase: ColumnType<string | null, string | null, string | null>;
priority_multiplier: ColumnType<number | null, number | null, number | null>;
priority_multiplier_reason: ColumnType<string | null, string | null, string | null>;
scope_conversation_id: ColumnType<ConversationsId | null, ConversationsId | null, ConversationsId | null>;
created_at: ColumnType<string | null, string | null, string | null>;
}
export type FactTriggers = Selectable<FactTriggersTable>;
export type NewFactTriggers = Insertable<FactTriggersTable>;
export type FactTriggersUpdate = Updateable<FactTriggersTable>;
+28
View File
@@ -0,0 +1,28 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { UsersId } from './Users';
import type { MessagesId } from './Messages';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
/** Identifier type for public.facts */
export type FactsId = number & { __brand: 'public.facts' };
/** Represents the table public.facts */
export default interface FactsTable {
id: ColumnType<FactsId, never, never>;
user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>;
source_message_id: ColumnType<MessagesId | null, MessagesId | null, MessagesId | null>;
content: ColumnType<string | null, string | null, string | null>;
created_at: ColumnType<string | null, string | null, string | null>;
}
export type Facts = Selectable<FactsTable>;
export type NewFacts = Insertable<FactsTable>;
export type FactsUpdate = Updateable<FactsTable>;
+32
View File
@@ -0,0 +1,32 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { ConversationsId } from './Conversations';
import type { default as Role } from './Role';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
/** Identifier type for public.messages */
export type MessagesId = number & { __brand: 'public.messages' };
/** Represents the table public.messages */
export default interface MessagesTable {
id: ColumnType<MessagesId, never, never>;
conversation_id: ColumnType<ConversationsId | null, ConversationsId | null, ConversationsId | null>;
index: ColumnType<number | null, number | null, number | null>;
content: ColumnType<string | null, string | null, string | null>;
running_summary: ColumnType<string | null, string | null, string | null>;
created_at: ColumnType<string | null, string | null, string | null>;
role: ColumnType<Role | null, Role | null, Role | null>;
}
export type Messages = Selectable<MessagesTable>;
export type NewMessages = Insertable<MessagesTable>;
export type MessagesUpdate = Updateable<MessagesTable>;
+23
View File
@@ -0,0 +1,23 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { default as UsersTable } from './Users';
import type { default as MessagesTable } from './Messages';
import type { default as ToolsTable } from './Tools';
import type { default as FactTriggersTable } from './FactTriggers';
import type { default as FactsTable } from './Facts';
import type { default as ConversationsTable } from './Conversations';
export default interface PublicSchema {
users: UsersTable;
messages: MessagesTable;
tools: ToolsTable;
fact_triggers: FactTriggersTable;
facts: FactsTable;
conversations: ConversationsTable;
}
+10
View File
@@ -0,0 +1,10 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
/** Represents the enum public.role */
type Role =
| 'user'
| 'assistant'
| 'system';
export default Role;
+36
View File
@@ -0,0 +1,36 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { UsersId } from './Users';
import type { MessagesId } from './Messages';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
/** Identifier type for public.tools */
export type ToolsId = number & { __brand: 'public.tools' };
/** Represents the table public.tools */
export default interface ToolsTable {
id: ColumnType<ToolsId, never, never>;
user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>;
source_message_id: ColumnType<MessagesId | null, MessagesId | null, MessagesId | null>;
name: ColumnType<string | null, string | null, string | null>;
description: ColumnType<string | null, string | null, string | null>;
parameter_schema: ColumnType<unknown | null, unknown | null, unknown | null>;
implementation_language: ColumnType<string | null, string | null, string | null>;
implementation_code: ColumnType<string | null, string | null, string | null>;
created_at: ColumnType<string | null, string | null, string | null>;
}
export type Tools = Selectable<ToolsTable>;
export type NewTools = Insertable<ToolsTable>;
export type ToolsUpdate = Updateable<ToolsTable>;
+28
View File
@@ -0,0 +1,28 @@
// @generated
// This file is automatically generated by Kanel. Do not modify manually.
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
/** Identifier type for public.users */
export type UsersId = number & { __brand: 'public.users' };
/** Represents the table public.users */
export default interface UsersTable {
id: ColumnType<UsersId, never, never>;
username: ColumnType<string | null, string | null, string | null>;
password: ColumnType<string | null, string | null, string | null>;
email: ColumnType<string | null, string | null, string | null>;
last_login: ColumnType<string | null, string | null, string | null>;
created_at: ColumnType<string | null, string | null, string | null>;
}
export type Users = Selectable<UsersTable>;
export type NewUsers = Insertable<UsersTable>;
export type UsersUpdate = Updateable<UsersTable>;
+11 -11
View File
@@ -24,16 +24,16 @@ async function initialize() {
console.log("Creating collection: facts");
await client.createCollection({
collection_name: "facts",
auto_id: true,
fields: [
{
name: "id",
data_type: DataType.Int64,
is_primary_key: true,
autoID: true,
},
{
name: "user_id",
data_type: DataType.Int64,
data_type: DataType.Int32,
description:
"Foreign key linking to the Users Collection. Crucial if you have multiple users.",
},
@@ -78,12 +78,12 @@ async function initialize() {
console.log("Creating collection: fact_triggers");
await client.createCollection({
collection_name: "fact_triggers",
auto_id: true,
fields: [
{
name: "id",
data_type: DataType.Int64,
is_primary_key: true,
autoID: true,
},
{
name: "fact_id",
@@ -140,16 +140,16 @@ async function initialize() {
console.log("Creating collection: conversations");
await client.createCollection({
collection_name: "conversations",
auto_id: true,
fields: [
{
name: "id",
data_type: DataType.Int64,
is_primary_key: true,
autoID: true,
},
{
name: "user_id",
data_type: DataType.Int64,
data_type: DataType.Int32,
description:
"Foreign key linking to the Users Collection. This is the user who sent this message.",
},
@@ -186,16 +186,16 @@ async function initialize() {
console.log("Creating collection: conversation_messages");
await client.createCollection({
collection_name: "conversation_messages",
auto_id: true,
fields: [
{
name: "id",
data_type: DataType.Int64,
is_primary_key: true,
autoID: true,
},
{
name: "user_id",
data_type: DataType.Int64,
data_type: DataType.Int32,
description:
"Foreign key linking to the Users Collection. This is the user who sent this message.",
},
@@ -268,19 +268,19 @@ async function initialize() {
console.log("Creating collection: tools");
await client.createCollection({
collection_name: "tools",
auto_id: true,
fields: [
/** Primary key, unique identifier for each fact. */
{
name: "id",
data_type: DataType.Int64,
is_primary_key: true,
autoID: true,
},
/** Foreign key linking to the Users Collection.
* Crucial if you have multiple users. */
{
name: "user_id",
data_type: DataType.Int64,
data_type: DataType.Int32,
description:
"Foreign key linking to the Users Collection. Crucial if you have multiple users.",
},
@@ -362,12 +362,12 @@ async function initialize() {
// console.log("Creating collection: users");
// await client.createCollection({
// collection_name: "users",
// auto_id: true,
// fields: [
// {
// name: "id",
// data_type: DataType.Int64,
// data_type: DataType.Int32,
// is_primary_key: true,
// autoID: true,
// },
// {
// name: "username",
+21
View File
@@ -0,0 +1,21 @@
import { Pool } from "pg";
import { Kysely, PostgresDialect } from "kysely";
import type Database from "./generated/Database";
export const pool = new Pool({
connectionString:
"postgres://neondb_owner:npg_sOVmj8vWq2zG@ep-withered-king-adiz9gpi-pooler.c-2.us-east-1.aws.neon.tech:5432/neondb?sslmode=require&channel_binding=true",
// channelBinding: require ?
});
const dialect = new PostgresDialect({
pool,
});
// Database interface is passed to Kysely's constructor, and from now on, Kysely
// knows your database structure.
// Dialect is passed to Kysely's constructor, and from now on, Kysely knows how
// to communicate with your database.
export const db = new Kysely<Database>({
dialect,
});