Skip to main content

AI & Knowledge Base

Overview

This domain is what lets a LINE OA answer customer questions with AI. It has two halves.

  • Model configuration — the ai_config table stores the provider, the model name and the API key, with Gemini as the default.
  • A RAG knowledge base — the knowledge_base, knowledge_document and knowledge_chunk tables store documents and split them into chunks so they can be retrieved by embedding search.

Whether the AI actually gets to answer a message is decided by line_oa.message_handling_config, which arbitrates priority between AI, auto-responses and trigger rules.

Core Data Structure

ai_config — model settings

  • provider (defaults to gemini) and model (defaults to gemini-2.0-flash)
  • api_key as TEXT, plus a settings JSONB column for additional parameters
  • The unique constraint (organization_id, line_oa_id, provider), named uq_ai_config_org_lineoa_provider, allows one configuration per channel per provider

knowledge_base

  • name, description and system_instruction, the system prompt for that particular base
  • stats as JSONB summarising document and chunk counts, plus status
  • Scoped by line_oa_id and organization_id, with soft deletes via deleted_date
  • Has a one-to-many relationship with both knowledge_document and knowledge_chunk

knowledge_document — a single document

  • type describes the shape of the entry: free text, a question-and-answer pair, or an uploaded file
  • Content columns: title, content, question, answer
  • File columns: file_url, file_name, file_type, file_size
  • Indexing state: index_status (defaults to pending) and index_error
  • The knowledge_base_id foreign key points back to the owning base

knowledge_chunk — the unit that is actually searched

  • content and chunk_index, which records the position of the chunk within its document
  • embedding_id holds only a reference into an external vector store; the vector itself is never stored in PostgreSQL
  • metadata as JSONB for retrieval-time context
  • Carries foreign keys to both knowledge_document_id and knowledge_base_id. The latter is denormalised deliberately so that every chunk of a base can be queried in one statement.
  • prisma/schema.prisma:1539 — the AiConfig model
  • prisma/schema.prisma:1607 — the KnowledgeBase model
  • prisma/schema.prisma:1629 — the KnowledgeDocument model
  • prisma/schema.prisma:1657 — the KnowledgeChunk model
  • schema-dumps/2026-07-24/schema.sql:823, :2027, :2104, :2068

Connections to Other Services

  • cms-api-go lets administrators configure the AI, upload documents into a base, and trigger a re-index.
  • worker-go performs the indexing job: it splits the document into chunks, generates the embeddings, and writes index_status back.
  • webhook-go is the consumer at runtime. When a user sends a message and the priority rules hand it to the AI, it retrieves the relevant chunks and calls the model together with the base's system_instruction.
  • Connects to LINE OA Channels through message_handling_config, and to Auto Responses.