# == Schema Information # # Table name: knowledge_base_faqs # # id :bigint not null, primary key # account_id :bigint not null # title :string not null # content :text not null # topic_tags :jsonb default: [] not null # source_filename :string # embedding :vector(1536) # created_at :datetime not null # updated_at :datetime not null # class KnowledgeBaseFaq < ApplicationRecord belongs_to :account # pgvector KNN support (matches repo pattern: has_neighbors + nearest_neighbors) has_neighbors :embedding, normalize: true validates :title, presence: true validates :content, presence: true # topic_tags stored as jsonb array; expose string-list helpers for import/retrieval. def topic_tag_list Array(topic_tags) end def topic_tag_list=(value) self.topic_tags = Array(value).map(&:strip).reject(&:blank?) end scope :for_account, ->(account) { where(account_id: account.id) } scope :with_embedding, -> { where.not(embedding: nil) } end