Compilation Template Management#
Overview#
Compilation Template Groups are user-created collections of compilation templates that configure which knowledge artifacts (knowledge graphs, RAPTOR trees, timelines, mind maps, etc.) are produced from a dataset. They form the backbone of RAGFlow's two-phase compilation workflow:
- Configuration phase — a dataset's parse config references one or more template groups via
parser_config.compilation_template_group_id - Artifact generation phase — the Compilation page triggers actual artifact production using those groups
Groups are always user-created and tenant-scoped — no builtin groups exist, only a builtin template palette used as pre-fill when building groups.
Scopes and Constraints#
Every group has a scope field ("file" or "dataset") that is auto-derived from its child templates at creation/update time — users do not set it manually.
| Scope | Condition | Execution context |
|---|---|---|
file | Any combination of non-artifacts template kinds (knowledge_graph, tree, timeline, page_index, mind_map) | Per-document |
dataset | Exactly one artifacts template and no other children | KB-wide |
Two additional invariants are enforced server-side (and mirrored client-side in group-interface.ts):
- An
artifactstemplate cannot be combined with other template kinds. - At most one
tree-kind child in a group may have re-chunking enabled — running two re-chunking tree templates would race on the same source chunks and produce non-deterministic output.
At the dataset level, the multi-select form field allows selecting at most one group per scope, so a dataset can carry one file-scope group and one dataset-scope group simultaneously.
Data Model#
Two DB tables (Peewee models):
CompilationTemplateGroup — group header:
tenant_id,name(max 128 chars),description,scope,status- Unique index:
(tenant_id, name, status)
CompilationTemplate — child template rows:
tenant_id,group_id,name,kind,config(JSON),is_builtin,status- Unique index:
(tenant_id, group_id, name, is_builtin, status)
Both use soft deletion (status = "0" for invalid, "1" for valid). Group deletion cascades to children atomically.
Builtin templates (loaded from YAML files in api/db/init_data/compilation_templates/) populate a separate palette and are never assigned a group_id.
Key Source Files#
| Layer | File |
|---|---|
| REST API — groups | compilation_template_group_api.py |
| REST API — builtins & wiki presets | compilation_template_api.py |
| Group service (CRUD + scope logic) | compilation_template_group_service.py |
| Template service (builtin seeding, LLM fill) | compilation_template_service.py |
| DB models | db_models.py L1145–1172 |
| Dataset-level form field | compilation-template-form-field.tsx |
| Dataset setting schema | form-schema.ts L95 |
| Compilation page (artifact view) | dataset/compilation/index.tsx |
| Group management UI (list) | user-setting/compilation-templates/index.tsx |
| Group create/edit UI | compilation-templates/create-next/index.tsx |
| Frontend hooks | use-compilation-template-group-request.ts |
API Endpoints#
Five routes under compilation_template_groups:
| Method | Path | Action |
|---|---|---|
| GET | /compilation_template_groups | List groups (filterable by keywords, scope; paginated) |
| GET | /compilation_template_groups/<group_id> | Fetch a single group with its children |
| POST | /compilation_template_groups | Create group (name ≤ 128 bytes, description ≤ 1024 chars) |
| PUT | /compilation_template_groups/<group_id> | Update group metadata and/or child templates |
| DELETE | /compilation_template_groups/<group_id> | Soft-delete group and its children |
Two additional routes serve the builtin template palette: GET /compilation_templates/builtins (DB-cached, falls back to filesystem) and GET /compilation_templates/wiki_presets (always filesystem-fresh per request).
Workflow: Configuration → Compilation#
[User Settings]
└─ Create/edit template groups
└─ scope derived from child template kinds
[Dataset Configuration]
└─ parser_config.compilation_template_group_id: [group_id_A, group_id_B]
└─ max 1 file-scope + 1 dataset-scope group
[Compilation Page]
└─ useFetchKnowledgeGraph / useFetchArtifactTopicList
└─ Artifacts rendered: Knowledge Graph | LLM Wiki | Skills
The orchestrator resolves group IDs to child template IDs via resolve_template_ids() when reading parser_config.compilation_template_group_id. The lightweight list_for_resolution() path is used by frontend pickers to avoid the LLM-fill overhead of full template reads.
Default LLM assignment is filled lazily at read time via fill_config_default_llm() — not stored in the DB — so templates automatically inherit tenant LLM defaults without duplicating configuration.