> ## Documentation Index
> Fetch the complete documentation index at: https://strattumai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Save (create or update) a source type definition

> Write a source type definition YAML file to the workspace.

Creates or overwrites ``{WORKSPACE_PATH}/source_types/{name}.yaml``.
The Knowledge Worker picks up this file on its next scheduled run and
begins indexing the configured DuckDB table.

Request body is validated against ``SourceTypeDef`` from strattum_core —
the same model used by the knowledge-worker to parse the YAML.

Used by the Console UI "Configurar indexação" / "Editar" drawer
(PRD-008 section 10.9).



## OpenAPI

````yaml /api-reference/knowledge-api.json post /v1/knowledge/source-types/{name}
openapi: 3.1.0
info:
  title: Strattum Knowledge API
  description: >-
    REST API that serves semantic document search — embeddings via the
    configured LLM provider, indexed in Qdrant, with metadata stored in
    PostgreSQL. (PRD-004, Workstream 1.4)
  version: 1.0.0
servers: []
security: []
paths:
  /v1/knowledge/source-types/{name}:
    post:
      tags:
        - source-types
      summary: Save (create or update) a source type definition
      description: |-
        Write a source type definition YAML file to the workspace.

        Creates or overwrites ``{WORKSPACE_PATH}/source_types/{name}.yaml``.
        The Knowledge Worker picks up this file on its next scheduled run and
        begins indexing the configured DuckDB table.

        Request body is validated against ``SourceTypeDef`` from strattum_core —
        the same model used by the knowledge-worker to parse the YAML.

        Used by the Console UI "Configurar indexação" / "Editar" drawer
        (PRD-008 section 10.9).
      operationId: save_source_type_v1_knowledge_source_types__name__post
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
            pattern: ^[a-z][a-z0-9_-]*$
            title: Name
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SourceTypeDef'
      responses:
        '201':
          description: Source type YAML written to workspace
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SaveSourceTypeResponse'
        '422':
          description: Validation error in request body
components:
  schemas:
    SourceTypeDef:
      properties:
        name:
          type: string
          title: Name
          description: Unique source type identifier (slug, no spaces).
        display_name:
          type: string
          title: Display Name
          description: Human-readable label shown in the Console UI.
          default: ''
        label:
          type: string
          title: Label
          description: Alternative label used by the API (alias for display_name).
          default: ''
        duckdb_table:
          type: string
          title: Duckdb Table
          description: DuckDB table name that contains the operational records.
        id_field:
          type: string
          title: Id Field
          description: Column used as unique record identifier.
          default: id
        sla_minutes:
          type: integer
          minimum: 1
          title: Sla Minutes
          description: Maximum lag (in minutes) before the worker flags a delay.
          default: 60
        preprocessors:
          items:
            type: string
          type: array
          title: Preprocessors
          description: List of preprocessors applied before chunking.
        text_fields:
          items:
            $ref: '#/components/schemas/TextFieldDef'
          type: array
          minItems: 1
          title: Text Fields
          description: Text fields to be chunked and indexed in Qdrant.
        structured_fields:
          items:
            type: string
          type: array
          title: Structured Fields
          description: Columns stored as structured metadata (for filtering).
        payload_fields:
          items:
            type: string
          type: array
          title: Payload Fields
          description: Columns included in the chunk payload (not indexed).
        filter_fields:
          items:
            type: string
          type: array
          title: Filter Fields
          description: Columns available as filters in search queries.
        entity_links:
          items:
            $ref: '#/components/schemas/EntityLinkDef'
          type: array
          title: Entity Links
          description: Field-to-entity mappings for memory graph propagation.
      type: object
      required:
        - name
        - duckdb_table
      title: SourceTypeDef
      description: >-
        Complete definition of an operational Source Type.


        Read from ``/workspace/source_types/{name}.yaml`` by the
        knowledge-worker

        and written by the knowledge-api via POST
        /v1/knowledge/source_types/{name}.


        Minimum required fields: ``name``, ``duckdb_table``, ``text_fields``.
    SaveSourceTypeResponse:
      properties:
        name:
          type: string
          title: Name
        path:
          type: string
          title: Path
        created:
          type: boolean
          title: Created
          description: True when the file was newly created; False when it was overwritten.
      type: object
      required:
        - name
        - path
        - created
      title: SaveSourceTypeResponse
      description: Response for POST /v1/knowledge/source_types/{name}.
    TextFieldDef:
      properties:
        field:
          type: string
          title: Field
          description: Column name in the DuckDB table with the text content.
        format:
          type: string
          enum:
            - plain
            - html
            - json_array
          title: Format
          description: Format of the field content.
          default: plain
        item_field:
          anyOf:
            - type: string
            - type: 'null'
          title: Item Field
          description: >-
            For format='json_array': name of the field inside each array item to
            extract as text.
        chunking_strategy:
          type: string
          enum:
            - full
            - per_item
            - semantic
          title: Chunking Strategy
          description: Chunking strategy applied to this field.
          default: semantic
        max_tokens:
          type: integer
          minimum: 64
          title: Max Tokens
          description: Maximum token size per chunk.
          default: 1024
        overlap_tokens:
          type: integer
          minimum: 0
          title: Overlap Tokens
          description: Number of overlap tokens between consecutive chunks.
          default: 100
      type: object
      required:
        - field
      title: TextFieldDef
      description: |-
        Configuration for a single text field to be chunked and indexed.

        Used in ``SourceTypeDef.text_fields``. Mirrors each entry under
        ``fields.text`` in the source type YAML configuration file.
    EntityLinkDef:
      properties:
        source_field:
          type: string
          title: Source Field
          description: Column name in DuckDB that holds the entity identifier.
        entity_type:
          type: string
          title: Entity Type
          description: Entity type in the graph (e.g. 'customer', 'contact').
        relationship:
          type: string
          title: Relationship
          description: Relationship type in the graph between the chunk and the entity.
          default: RELATED_TO
      type: object
      required:
        - source_field
        - entity_type
      title: EntityLinkDef
      description: |-
        Mapping from a source type field to a memory graph entity.

        Allows the knowledge-worker to automatically propagate relationships
        between indexed chunks and entities in the graph (FalkorDB).

````