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.
| Layer | Table | Meaning |
|---|---|---|
| Base | knowledge_base | A LINE OA can own several knowledge bases |
| Document | knowledge_document | A document that belongs to a base |
| Chunk | knowledge_chunk | A 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
GET /api/knowledge-baselists every base belonging to the LINE OA.GET /api/knowledge-base/select-optionsreturns 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 thepublicgroup alongsideJwtLoginAuth.POST /api/knowledge-basecreates a new base.GET /api/knowledge-base/:idreturns details andPUT /api/knowledge-base/:idedits them.DELETE /api/knowledge-base/:idperforms a two-stage soft delete: the status is set todeletefirst, thendeleted_dateis stamped, mirroring the order used in the original TypeScript implementation.
Managing Documents
GET /api/knowledge-base/:id/documentslists the documents in a base.POST /api/knowledge-base/:id/documentsadds a document viaCreateDocumentDtoand publishes an indexing job to theknowledge_indexqueue.PUT /api/knowledge-base/:id/documents/:docIdedits a document and triggers a re-index.DELETE /api/knowledge-base/:id/documents/:docIdremoves a document by setting its status todeleteand then soft-deleting it.
Reindexing an Entire Base
POST /api/knowledge-base/:id/reindexre-indexes the whole base. This is used after changing the embedding model or when chunk data has become corrupted.- The worker computes embeddings, writes them to
knowledge_chunk, and indexes them into Meilisearch. - 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.
| Method | Route | Handler | Guard / Policy |
|---|---|---|---|
| GET | /api/knowledge-base/select-options | ct.getSelectOptions | public + JwtLoginAuth |
| GET | /api/knowledge-base | ct.findAll | authed + readAll line-oa |
| GET | /api/knowledge-base/:id | ct.findById | authed + read line-oa |
| GET | /api/knowledge-base/:id/documents | ct.listDocuments | authed + read line-oa |
| POST | /api/knowledge-base | ct.create | authed + create line-oa |
| POST | /api/knowledge-base/:id/documents | ct.addDocument | authed + create line-oa |
| POST | /api/knowledge-base/:id/reindex | ct.reindexAll | authed + update line-oa |
| PUT | /api/knowledge-base/:id | ct.update | authed + update line-oa |
| PUT | /api/knowledge-base/:id/documents/:docId | ct.updateDocument | authed + update line-oa |
| DELETE | /api/knowledge-base/:id | ct.softDelete | authed + delete line-oa |
| DELETE | /api/knowledge-base/:id/documents/:docId | ct.deleteDocument | authed + delete line-oa |
Connections to Other Services
- Access control — The main routes sit on the
authedgroup, which enforces JWT globally. Policy metadata referencesPolicyModuleLineOabut is not enforced, and there is noModuleGatewrapper. - Tables —
knowledge_base,knowledge_document,knowledge_chunk,line_oa - RabbitMQ — The
knowledge_indexqueue on theline_exchangeexchange - External services — The embedding API and Meilisearch, used at query time (see Workflow for details)
- Error handling —
throwInstanceofErrorpasses HttpExceptions through unchanged; any other database error becomes an HTTP 500 with codeAPP_000. - Related modules — Workflow and AI Configuration