Skip to main content

Bot Knowledge Base

Overview

The Knowledge Base is the document store that Workflow bots draw on when answering questions, using a RAG (Retrieval-Augmented Generation) approach. The data model has three layers.

LayerTableMeaning
Baseknowledge_baseA LINE OA can own several knowledge bases
Documentknowledge_documentA document that belongs to a base
Chunkknowledge_chunkA document split into pieces with embeddings for semantic search

Indexing and embedding are expensive operations, so they never run inside a request. They are handed off to the worker through the RabbitMQ queue knowledge_index.

Business Flow

Managing Bases

  1. GET /api/knowledge-base lists every base belonging to the LINE OA.
  2. GET /api/knowledge-base/select-options returns a dropdown-shaped payload so the workflow settings screen can pick a base before the token is bound to an OA. That is why this endpoint sits on the public group alongside JwtLoginAuth.
  3. POST /api/knowledge-base creates a new base.
  4. GET /api/knowledge-base/:id returns details and PUT /api/knowledge-base/:id edits them.
  5. DELETE /api/knowledge-base/:id performs a two-stage soft delete: the status is set to delete first, then deleted_date is stamped, mirroring the order used in the original TypeScript implementation.

Managing Documents

  1. GET /api/knowledge-base/:id/documents lists the documents in a base.
  2. POST /api/knowledge-base/:id/documents adds a document via CreateDocumentDto and publishes an indexing job to the knowledge_index queue.
  3. PUT /api/knowledge-base/:id/documents/:docId edits a document and triggers a re-index.
  4. DELETE /api/knowledge-base/:id/documents/:docId removes a document by setting its status to delete and then soft-deleting it.

Reindexing an Entire Base

  1. POST /api/knowledge-base/:id/reindex re-indexes the whole base. This is used after changing the embedding model or when chunk data has become corrupted.
  2. The worker computes embeddings, writes them to knowledge_chunk, and indexes them into Meilisearch.
  3. When the bot answers a question, the workflow sandbox and executor query Meilisearch together with the embedding API.

The published payload is kept byte-for-byte identical to the original, including key ordering from the source object literal, because the existing worker still consumes it. The routing key equals the queue name on the line_exchange exchange.

Key Files & Functions

The code lives in internal/modules/knowledgebase/, made up of controller.go, service.go, and dto.go.

MethodRouteHandlerGuard / Policy
GET/api/knowledge-base/select-optionsct.getSelectOptionspublic + JwtLoginAuth
GET/api/knowledge-basect.findAllauthed + readAll line-oa
GET/api/knowledge-base/:idct.findByIdauthed + read line-oa
GET/api/knowledge-base/:id/documentsct.listDocumentsauthed + read line-oa
POST/api/knowledge-basect.createauthed + create line-oa
POST/api/knowledge-base/:id/documentsct.addDocumentauthed + create line-oa
POST/api/knowledge-base/:id/reindexct.reindexAllauthed + update line-oa
PUT/api/knowledge-base/:idct.updateauthed + update line-oa
PUT/api/knowledge-base/:id/documents/:docIdct.updateDocumentauthed + update line-oa
DELETE/api/knowledge-base/:idct.softDeleteauthed + delete line-oa
DELETE/api/knowledge-base/:id/documents/:docIdct.deleteDocumentauthed + delete line-oa

Connections to Other Services

  • Access control — The main routes sit on the authed group, which enforces JWT globally. Policy metadata references PolicyModuleLineOa but is not enforced, and there is no ModuleGate wrapper.
  • Tablesknowledge_base, knowledge_document, knowledge_chunk, line_oa
  • RabbitMQ — The knowledge_index queue on the line_exchange exchange
  • External services — The embedding API and Meilisearch, used at query time (see Workflow for details)
  • Error handlingthrowInstanceofError passes HttpExceptions through unchanged; any other database error becomes an HTTP 500 with code APP_000.
  • Related modulesWorkflow and AI Configuration