All files / web/src/db/schema flowchart-embeddings.ts

100% Statements 33/33
100% Branches 0/0
100% Functions 0/0
100% Lines 33/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 342x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x  
import { blob, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
 
/**
 * Flowchart Embeddings table - Stores embeddings for hardcoded flowcharts
 *
 * This table stores semantic embeddings for the hardcoded flowcharts (those defined
 * in src/lib/flowcharts/definitions/index.ts). User-created flowcharts store their
 * embeddings in the teacher_flowcharts table instead.
 *
 * The embeddings enable:
 * - Suggesting existing flowcharts when user enters a topic
 * - Finding related flowcharts on browse/detail pages
 * - Avoiding duplicate work by surfacing similar content
 */
export const flowchartEmbeddings = sqliteTable('flowchart_embeddings', {
  /** Primary key - matches the hardcoded flowchart ID (e.g., 'subtraction-regrouping') */
  id: text('id').primaryKey(),
 
  /** Semantic embedding vector (1536 floats stored as binary buffer) */
  embedding: blob('embedding', { mode: 'buffer' }).notNull(),
 
  /** Version of the embedding model used (e.g., '1.0.0') for cache invalidation */
  embeddingVersion: text('embedding_version').notNull(),
 
  /** Hash of the content used to generate the embedding (for cache invalidation) */
  contentHash: text('content_hash').notNull(),
 
  /** When this embedding was created */
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})
 
export type FlowchartEmbedding = typeof flowchartEmbeddings.$inferSelect
export type NewFlowchartEmbedding = typeof flowchartEmbeddings.$inferInsert