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_configtable stores the provider, the model name and the API key, with Gemini as the default. - A RAG knowledge base — the
knowledge_base,knowledge_documentandknowledge_chunktables 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 togemini) andmodel(defaults togemini-2.0-flash)api_keyas TEXT, plus asettingsJSONB column for additional parameters- The unique constraint
(organization_id, line_oa_id, provider), nameduq_ai_config_org_lineoa_provider, allows one configuration per channel per provider
knowledge_base
name,descriptionandsystem_instruction, the system prompt for that particular basestatsas JSONB summarising document and chunk counts, plusstatus- Scoped by
line_oa_idandorganization_id, with soft deletes viadeleted_date - Has a one-to-many relationship with both
knowledge_documentandknowledge_chunk
knowledge_document — a single document
typedescribes 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 topending) andindex_error - The
knowledge_base_idforeign key points back to the owning base
knowledge_chunk — the unit that is actually searched
contentandchunk_index, which records the position of the chunk within its documentembedding_idholds only a reference into an external vector store; the vector itself is never stored in PostgreSQLmetadataas JSONB for retrieval-time context- Carries foreign keys to both
knowledge_document_idandknowledge_base_id. The latter is denormalised deliberately so that every chunk of a base can be queried in one statement.
Related Files
prisma/schema.prisma:1539— theAiConfigmodelprisma/schema.prisma:1607— theKnowledgeBasemodelprisma/schema.prisma:1629— theKnowledgeDocumentmodelprisma/schema.prisma:1657— theKnowledgeChunkmodelschema-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_statusback. - 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.