Skip to main content

Templates

Manage knowledge graph templates. Templates define the schema for nodes and edges -- they specify which properties an entity type has, their data types, validation rules, and default values. Every node and edge in the knowledge graph is associated with a template.

Base path: /api/v1/templates


List Templates

Retrieve a paginated list of templates with optional filtering by type.

GET /api/v1/templates

Query Parameters

ParameterTypeRequiredDefaultDescription
template_typestringNo--Filter by type: node or edge
pageintegerNo1Page number (starts at 1)
page_sizeintegerNoFrom settingsItems per page (capped at max_page_size from settings)

Example Request

curl 'http://localhost:8080/api/v1/templates?page=1&page_size=20'

Filter by type:

curl 'http://localhost:8080/api/v1/templates?template_type=node'

Response

Status: 200 OK

{
"data": [
{
"id": "tmpl-person-abc123",
"name": "Person",
"description": "A person entity with biographical details",
"template_type": "node",
"properties": [
{
"name": "nationality",
"display_name": "Nationality",
"property_type": "string",
"required": false,
"description": "Country of citizenship"
}
],
"is_system": false,
"created_at": "2026-01-15T10:30:00Z",
"updated_at": "2026-02-20T14:22:00Z"
}
],
"pagination": {
"page": 1,
"page_size": 20,
"total": 14
}
}

Null fields (default_value, enum_values, validation_pattern, allowed_node_types) are omitted for brevity. See PropertyDefinition for all fields.


Create Template

Create a new template definition.

POST /api/v1/templates

Request Body

FieldTypeRequiredDefaultDescription
namestringYes--Template name (cannot start with system_)
template_typestringYes--Type: node or edge
descriptionstringNonullHuman-readable description
iconstringNonullIcon identifier for visual display
colorstringNonullColor hex code for visual display (e.g. #4dabf5)
propertiesPropertyDefinition[]No[]List of property definitions
source_idstringNonullSource ID for enabled filtering
Reserved prefix

Template names starting with system_ are reserved for built-in templates and will be rejected with a 400 error.

Example Request

curl -X POST 'http://localhost:8080/api/v1/templates' \
-H 'Content-Type: application/json' \
-d '{
"name": "Person",
"template_type": "node",
"description": "A person entity with biographical details",
"properties": [
{
"name": "nationality",
"display_name": "Nationality",
"property_type": "string",
"required": false,
"description": "Country of citizenship"
}
]
}'

See PropertyDefinition for additional property fields like enum_values, default_value, and validation_pattern.

Response

Status: 201 Created

Returns the full TemplateResponse. Example:

{
"id": "tmpl-person-abc123",
"name": "Person",
"description": "A person entity with biographical details",
"template_type": "node",
"properties": [
{
"name": "nationality",
"display_name": "Nationality",
"property_type": "string",
"required": false,
"description": "Country of citizenship"
}
],
"is_system": false,
"created_at": "2026-03-09T12:00:00Z",
"updated_at": "2026-03-09T12:00:00Z"
}

Errors

StatusReason
400Template name starts with system_
422Validation error (missing required fields, invalid property_type, etc.)

Get Template

Retrieve a single template by ID.

GET /api/v1/templates/{template_id}

Path Parameters

ParameterTypeRequiredDescription
template_idstringYesUnique template identifier

Example Request

curl 'http://localhost:8080/api/v1/templates/tmpl-person-abc123'

Response

Status: 200 OK

{
"id": "tmpl-person-abc123",
"name": "Person",
"description": "A person entity with biographical details",
"template_type": "node",
"properties": [
{
"name": "nationality",
"display_name": "Nationality",
"property_type": "string",
"required": false,
"description": "Country of citizenship"
}
],
"is_system": false,
"created_at": "2026-01-15T10:30:00Z",
"updated_at": "2026-02-20T14:22:00Z"
}

Errors

StatusReason
404Template not found

Update Template

Update an existing template. Only provided fields are updated -- omitted fields remain unchanged.

PATCH /api/v1/templates/{template_id}

Path Parameters

ParameterTypeRequiredDescription
template_idstringYesUnique template identifier

Request Body

FieldTypeRequiredDescription
namestringNoNew template name (cannot start with system_)
descriptionstringNoNew description
iconstringNoNew icon identifier
colorstringNoNew color hex code
propertiesPropertyDefinition[]NoReplacement property definitions (replaces the entire list)
Property replacement

When properties is provided, the entire property list is replaced. To add a property, include all existing properties plus the new one.

Example Request

curl -X PATCH 'http://localhost:8080/api/v1/templates/tmpl-person-abc123' \
-H 'Content-Type: application/json' \
-d '{
"description": "A person entity with extended biographical details",
"properties": [
{
"name": "nationality",
"display_name": "Nationality",
"property_type": "string",
"required": false,
"description": "Country of citizenship"
}
]
}'

Property structure is the same as Create Template. When properties is provided, the entire list is replaced.

Response

Status: 200 OK

Returns the full updated TemplateResponse.

{
"id": "tmpl-person-abc123",
"name": "Person",
"description": "A person entity with extended biographical details",
"template_type": "node",
"properties": [
{
"name": "nationality",
"display_name": "Nationality",
"property_type": "string",
"required": false,
"description": "Country of citizenship"
}
],
"is_system": false,
"created_at": "2026-01-15T10:30:00Z",
"updated_at": "2026-03-09T12:15:00Z"
}

Errors

StatusReason
400Template name starts with system_
404Template not found
422Validation error

Delete Template

Delete a template. By default, deletion is blocked if any nodes or edges reference the template.

DELETE /api/v1/templates/{template_id}

Path Parameters

ParameterTypeRequiredDescription
template_idstringYesUnique template identifier

Query Parameters

ParameterTypeRequiredDefaultDescription
forcebooleanNofalseDelete even if nodes or edges are using this template

Example Request

curl -X DELETE 'http://localhost:8080/api/v1/templates/tmpl-person-abc123'

Force delete a template that is in use:

curl -X DELETE 'http://localhost:8080/api/v1/templates/tmpl-person-abc123?force=true'

Response

Status: 204 No Content

No response body.

Errors

StatusReason
404Template not found
409Template is in use by nodes or edges (use force=true to override)

Regenerate Template Embeddings

Queue a background job to regenerate embeddings for all templates. Embeddings enable semantic template search (e.g., searching "people" finds the "character" template).

POST /api/v1/templates/embeddings
When to use
  • After importing new templates
  • When embeddings are missing or outdated
  • After changing the embedding model

Example Request

curl -X POST 'http://localhost:8080/api/v1/templates/embeddings'

Response

Status: 202 Accepted

{
"task_id": "task-abc123def456",
"status": "queued",
"message": "Template embedding regeneration started"
}
Tracking progress

Use GET /api/v1/queue/tasks/{task_id} to check the status of the background job.


Batch Operations

Queue a batch of create, update, and delete operations to be processed in the background.

POST /api/v1/templates/batch

Request Body

FieldTypeRequiredDescription
operationsBulkOperationRequest[]YesList of operations to execute

Each operation in the list has the following structure:

FieldTypeRequiredDescription
operationstringYesOperation type: create, update, or delete
dataobjectYesOperation-specific payload (see examples below)

Example Request

curl -X POST 'http://localhost:8080/api/v1/templates/batch' \
-H 'Content-Type: application/json' \
-d '{
"operations": [
{
"operation": "create",
"data": { "name": "Location", "template_type": "node", "description": "A geographic location" }
},
{
"operation": "update",
"data": { "id": "tmpl-person-abc123", "description": "Updated person template" }
},
{
"operation": "delete",
"data": { "id": "tmpl-old-def456", "force": true }
}
]
}'

Each data object matches the request body of the corresponding individual endpoint (Create, Update, Delete).

Response

Status: 202 Accepted

{
"task_id": "task-batch-789xyz",
"status": "queued",
"message": "Bulk templates operation queued with 3 operations"
}
Tracking results
Partial failures

Operations are executed in order, but a failure in one operation does not stop subsequent operations. Check the task result for individual outcomes.


Reference

TemplateResponse

The standard response object returned for all template endpoints.

FieldTypeDescription
idstringUnique template identifier
namestringTemplate name
descriptionstring | nullHuman-readable description
template_typestringType: node or edge
iconstring | nullIcon identifier for visual display (e.g. person, building, document)
colorstring | nullColor hex code for visual display (e.g. #4dabf5)
propertiesPropertyDefinition[]Property definitions for this template
is_systembooleanWhether this is a built-in system template
created_atdatetimeISO 8601 creation timestamp
updated_atdatetimeISO 8601 last update timestamp

PropertyDefinition

Defines a single property within a template.

FieldTypeRequiredDefaultDescription
namestringYes--Property name (unique within template)
display_namestringYes--Human-readable display name
property_typePropertyTypeYes--Data type of the property
requiredbooleanNofalseWhether this property is required when creating nodes/edges
default_valueanyNonullDefault value if not provided
enum_valuesstring[]NonullAllowed values (only for enum property type)
descriptionstringNonullDescription of the property
validation_patternstringNonullRegex pattern for validation
allowed_node_typesstring[]NonullFor node_reference and node_reference_list types: allowed template IDs

PropertyType

Supported property data types.

ValueDescription
stringShort text value
textLong-form text
integerWhole number
floatDecimal number
booleanTrue or false
dateDate value (ISO 8601)
datetimeDate and time value (ISO 8601)
urlURL string
emailEmail address
enumOne of a predefined set of values (requires enum_values)
jsonArbitrary JSON object
node_referenceReference to another node (use allowed_node_types to constrain)
node_reference_listList of references to other nodes (use allowed_node_types to constrain)

BulkOperationRequest

A single operation within a batch request.

FieldTypeRequiredDescription
operationstringYesOperation type: create, update, or delete
dataobjectYesOperation payload -- matches the request body of the corresponding individual endpoint