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

# Patch Dataset Schema

> Merge a partial graph-model spec into the dataset's stored graph schema.

Where PUT replaces the schema wholesale, PATCH upserts by name: each entity
in **entities** is added if new, otherwise its fields are upserted by field
name (a matching field is replaced whole, whatever its kind) and its scalars
(description, primaryLabelField, indexFields, identityFields) overwritten only
when sent. Removals apply after the upserts; **options** is shallow-merged.
With no stored schema the patch is applied to an empty spec, so it behaves
like PUT. Keys may be snake_case or camelCase.

## Path Parameters
- **dataset_id** (UUID): UUID of the dataset (from GET /api/v1/datasets).

## Request Parameters
- **entities** (List[EntitySpec]): Entities to add or update, keyed by name.
- **removeEntities** (List[str]): Entity names to drop after the upserts.
- **removeFields** (List[\{entity, field\}]): Fields to drop after the upserts.
- **options** (Optional[Dict]): Graph options to shallow-merge (e.g. autoTypeNodes).
- **root** (Optional[str]): Replace the root entity when sent.

## Response
The merged document, in the shape GET /schema returns.

## Error Codes
Error bodies are `{"message": ...}`.
- **404 Not Found**: Dataset not found or no write permission.
- **422 Unprocessable Content**: The merged schema is not a valid graph-model
  spec, a removed entity is still targeted by a relation, or a removal names an
  entity or field that is not in the schema. The message names the item.



## OpenAPI

````yaml /cognee_openapi_spec.json patch /api/v1/datasets/{dataset_id}/schema
openapi: 3.1.0
info:
  title: Cognee API
  description: Cognee API with Bearer token and Cookie auth
  version: 1.0.0
servers:
  - url: https://{tenant}.aws.cognee.ai
    description: 'Cognee Cloud: your tenant pod, named in the platform.cognee.ai dashboard'
    variables:
      tenant:
        default: your-tenant
        description: Your tenant name, shown in the Cognee Cloud dashboard
  - url: http://localhost:8000
    description: 'Self-hosted: a locally running cognee server'
security:
  - BearerAuth: []
  - ApiKeyAuth: []
tags:
  - name: activity
    description: >-
      Activity endpoints for inspecting pipeline runs, traced spans, tenant
      users, agents, and dataset exports.
  - name: add
    description: Data ingestion endpoints for adding text, files, and structured data.
  - name: agent connections
    description: >-
      Endpoints for registering, unregistering, and inspecting agent connections
      to the instance.
  - name: agent management
    description: Endpoints for creating, listing, retrieving, and deleting agents.
  - name: auth
    description: >-
      Authentication endpoints for user registration, login, and token
      management.
  - name: checks
    description: >-
      Diagnostic endpoint for validating a Cognee Cloud API key supplied in the
      X-Api-Key header.
  - name: cognify
    description: >-
      Knowledge processing endpoints to transform raw data into knowledge
      graphs.
  - name: configuration
    description: >-
      Endpoints for storing, retrieving, and listing a user's saved
      configurations.
  - name: conflicts
    description: ''
  - name: datasets
    description: Dataset management endpoints for listing, creating, and deleting datasets.
  - name: delete
    description: Data deletion endpoints (deprecated — use datasets endpoints instead).
  - name: forget
    description: Endpoint for removing data from the knowledge graph.
  - name: health
    description: Liveness, readiness, and component health checks.
  - name: improve
    description: Endpoint for enriching and improving an existing knowledge graph.
  - name: integrations
    description: >-
      Endpoints for connecting, provisioning, and disconnecting OAuth providers
      and plugins.
  - name: llm
    description: >-
      LLM-backed endpoints for inferring graph schemas and generating custom
      extraction prompts.
  - name: memify
    description: >-
      Endpoint for running enrichment pipelines over existing graphs or supplied
      data.
  - name: ontologies
    description: >-
      Endpoints for uploading, listing, and deleting ontology files used during
      cognify.
  - name: permissions
    description: Permission management for multi-user access control.
  - name: recall
    description: >-
      Endpoints for querying the knowledge graph and reviewing past recall
      history.
  - name: remember
    description: >-
      Endpoints for ingesting data into the knowledge graph and storing session
      memory entries.
  - name: responses
    description: Response generation endpoints using the knowledge graph.
  - name: schema
    description: >-
      Schema inspection endpoints for a dataset's derived schema inventory and
      the caller-wide memory provenance graph.
  - name: search
    description: Search endpoints for querying the knowledge graph.
  - name: sessions
    description: >-
      Endpoints for listing sessions and reporting usage, cost, and token
      statistics.
  - name: settings
    description: Configuration endpoints for managing Cognee settings.
  - name: skills
    description: >-
      Skill management endpoints for ingesting, listing, retrieving, and
      deleting dataset skills, plus read-only retrieval of improvement
      proposals.
  - name: slack
    description: >-
      Endpoints for listing workspace channels, setting channel allowlists, and
      linking Slack accounts.
  - name: sync
    description: Endpoints for syncing local data to Cognee Cloud and checking sync status.
  - name: update
    description: Endpoint for updating existing data in a dataset.
  - name: users
    description: User management endpoints.
  - name: validate
    description: >-
      Diagnostic endpoint for checking consistency between a dataset's graph and
      vector stores.
  - name: visualize
    description: Graph visualization endpoints.
paths:
  /api/v1/datasets/{dataset_id}/schema:
    patch:
      tags:
        - datasets
      summary: Patch Dataset Schema
      description: >-
        Merge a partial graph-model spec into the dataset's stored graph schema.


        Where PUT replaces the schema wholesale, PATCH upserts by name: each
        entity

        in **entities** is added if new, otherwise its fields are upserted by
        field

        name (a matching field is replaced whole, whatever its kind) and its
        scalars

        (description, primaryLabelField, indexFields, identityFields)
        overwritten only

        when sent. Removals apply after the upserts; **options** is
        shallow-merged.

        With no stored schema the patch is applied to an empty spec, so it
        behaves

        like PUT. Keys may be snake_case or camelCase.


        ## Path Parameters

        - **dataset_id** (UUID): UUID of the dataset (from GET
        /api/v1/datasets).


        ## Request Parameters

        - **entities** (List[EntitySpec]): Entities to add or update, keyed by
        name.

        - **removeEntities** (List[str]): Entity names to drop after the
        upserts.

        - **removeFields** (List[\{entity, field\}]): Fields to drop after the
        upserts.

        - **options** (Optional[Dict]): Graph options to shallow-merge (e.g.
        autoTypeNodes).

        - **root** (Optional[str]): Replace the root entity when sent.


        ## Response

        The merged document, in the shape GET /schema returns.


        ## Error Codes

        Error bodies are `{"message": ...}`.

        - **404 Not Found**: Dataset not found or no write permission.

        - **422 Unprocessable Content**: The merged schema is not a valid
        graph-model
          spec, a removed entity is still targeted by a relation, or a removal names an
          entity or field that is not in the schema. The message names the item.
      operationId: patch_dataset_schema_api_v1_datasets__dataset_id__schema_patch
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Dataset Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GraphSchemaPatch'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                title: >-
                  Response Patch Dataset Schema Api V1 Datasets  Dataset Id 
                  Schema Patch
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseDTO'
          description: Not Found
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseDTO'
          description: Unprocessable Content
      security:
        - BearerAuth: []
        - ApiKeyAuth: []
components:
  schemas:
    GraphSchemaPatch:
      properties:
        entities:
          items:
            $ref: '#/components/schemas/EntityPatch'
          type: array
          title: Entities
        removeEntities:
          items:
            type: string
          type: array
          title: Removeentities
        removeFields:
          items:
            $ref: '#/components/schemas/FieldRemoval'
          type: array
          title: Removefields
        options:
          anyOf:
            - $ref: '#/components/schemas/GraphSchemaOptions'
            - type: 'null'
        root:
          anyOf:
            - type: string
            - type: 'null'
          title: Root
      additionalProperties: false
      type: object
      title: GraphSchemaPatch
      description: Body of ``PATCH /datasets/{id}/schema``; snake_case or camelCase keys.
    ErrorResponseDTO:
      properties:
        message:
          type: string
          title: Message
      type: object
      required:
        - message
      title: ErrorResponseDTO
    EntityPatch:
      properties:
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        primaryLabelField:
          anyOf:
            - type: string
            - type: 'null'
          title: Primarylabelfield
        indexFields:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Indexfields
        identityFields:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Identityfields
        fields:
          items:
            oneOf:
              - $ref: '#/components/schemas/PrimitiveFieldSpec'
              - $ref: '#/components/schemas/EnumFieldSpec'
              - $ref: '#/components/schemas/RelationFieldSpec'
            discriminator:
              propertyName: kind
              mapping:
                enum: '#/components/schemas/EnumFieldSpec'
                primitive: '#/components/schemas/PrimitiveFieldSpec'
                relation: '#/components/schemas/RelationFieldSpec'
          type: array
          title: Fields
      additionalProperties: false
      type: object
      required:
        - name
      title: EntityPatch
      description: >-
        Partial ``EntitySpec``.


        ``fields`` are upserted by name into the stored entity (a field whose
        name

        matches is replaced whole, whatever its kind). Scalars overwrite the
        stored

        value only when sent; an omitted key keeps the stored value, an explicit

        ``null`` clears it.
    FieldRemoval:
      properties:
        entity:
          type: string
          title: Entity
        field:
          type: string
          title: Field
      additionalProperties: false
      type: object
      required:
        - entity
        - field
      title: FieldRemoval
    GraphSchemaOptions:
      properties:
        autoTypeNodes:
          type: boolean
          title: Autotypenodes
          default: true
      additionalProperties: false
      type: object
      title: GraphSchemaOptions
    PrimitiveFieldSpec:
      properties:
        kind:
          type: string
          const: primitive
          title: Kind
          default: primitive
        name:
          type: string
          title: Name
        primitiveType:
          type: string
          enum:
            - string
            - number
            - boolean
            - date
          title: Primitivetype
          default: string
        required:
          type: boolean
          title: Required
          default: false
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
      additionalProperties: false
      type: object
      required:
        - name
      title: PrimitiveFieldSpec
    EnumFieldSpec:
      properties:
        kind:
          type: string
          const: enum
          title: Kind
          default: enum
        name:
          type: string
          title: Name
        enumValues:
          items:
            type: string
          type: array
          minItems: 1
          title: Enumvalues
        required:
          type: boolean
          title: Required
          default: false
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
      additionalProperties: false
      type: object
      required:
        - name
        - enumValues
      title: EnumFieldSpec
    RelationFieldSpec:
      properties:
        kind:
          type: string
          const: relation
          title: Kind
          default: relation
        name:
          type: string
          title: Name
        relation:
          $ref: '#/components/schemas/RelationSpec'
        required:
          type: boolean
          title: Required
          default: false
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
      additionalProperties: false
      type: object
      required:
        - name
        - relation
      title: RelationFieldSpec
    RelationSpec:
      properties:
        targetEntityName:
          type: string
          title: Targetentityname
        cardinality:
          type: string
          enum:
            - one
            - many
          title: Cardinality
          default: one
        inverse:
          anyOf:
            - $ref: '#/components/schemas/InverseSpec'
            - type: 'null'
      additionalProperties: false
      type: object
      required:
        - targetEntityName
      title: RelationSpec
    InverseSpec:
      properties:
        enabled:
          type: boolean
          title: Enabled
          default: true
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        cardinality:
          anyOf:
            - type: string
              enum:
                - one
                - many
            - type: 'null'
          title: Cardinality
      additionalProperties: false
      type: object
      title: InverseSpec
      description: 'Reserved: accepted for frontend parity but not compiled into the schema.'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.