All files / web/src/db/schema topic-taxonomy.ts

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

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 34 35 36 37 38 39 40 41 422x 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 2x 2x 2x 2x 2x 2x 2x 2x  
import { blob, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
 
/**
 * Topic Taxonomy table - Stores labels and embeddings for cluster labeling
 *
 * This table stores the topic taxonomy used to assign meaningful labels to
 * flowchart clusters on the browse page. Labels range from broad ("Mathematics")
 * to specific ("Fraction Addition") to support both diverse and homogeneous clusters.
 *
 * The taxonomy is generated by an LLM based on:
 * - Common educational standards (K through post-grad)
 * - Word frequencies from existing flowcharts
 *
 * Regeneration is triggered via the admin panel.
 */
export const topicTaxonomy = sqliteTable('topic_taxonomy', {
  /** Auto-incrementing primary key */
  id: integer('id').primaryKey({ autoIncrement: true }),
 
  /** The topic label text (e.g., "Fraction Addition", "Mathematics") */
  label: text('label').notNull().unique(),
 
  /** Semantic embedding vector (1536 floats stored as binary buffer) */
  embedding: blob('embedding', { mode: 'buffer' }).notNull(),
 
  /** Version of the embedding model used (e.g., 'text-embedding-3-small') */
  embeddingModel: text('embedding_model').notNull(),
 
  /** When this label was created */
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
 
  /**
   * Breadth score: number of other labels within embedding distance threshold.
   * Higher = broader label (e.g., "Mathematics" ~25), lower = specific (e.g., "Fraction Addition" ~2).
   * Computed at taxonomy generation time from label-to-label distances.
   */
  breadth: integer('breadth'),
})
 
export type TopicTaxonomyLabel = typeof topicTaxonomy.$inferSelect
export type NewTopicTaxonomyLabel = typeof topicTaxonomy.$inferInsert