CreateKnowledgeObject

Updated at:

Creates a document object in a knowledge base by using the document content or an uploaded file.

Operation description

Creates a knowledge object. The tenant and caller identities are determined by the POP authentication context.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dataworks:CreateKnowledgeObject

create

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

KnowledgeBaseId

string

Yes

The target knowledge base.

12345678-1234-4234-8234-123456789abc

Name

string

Yes

The document name. Existing objects are not overwritten based on the name.

Business description

Description

string

No

The document description.

Sales metrics and policy document

Content

object

No

Only Content.Document is supported. It includes Text and ContentFormat (MARKDOWN or TEXT).

Document

object

No

This operation returns only the document content.

Text

string

No

The current document body that can be disclosed. This parameter is optional. It is omitted when parsing is incomplete, authorization is not granted, or the content cannot be provided completely and securely. A single retrieved snippet must not be passed off as the entire document.

Updated full body

ContentFormat

string

No

Required when Text is present. Valid values: MARKDOWN or TEXT.

MARKDOWN

SemanticModel

object

No

This operation does not accept this branch. Use a build task to import YAML for new semantic models.

Datasets

array<object>

No

The logical datasets included in the model. If no datasets can be disclosed, this is an empty array.

array<object>

No

Name

string

No

The document name. Existing objects are not overwritten based on the name.

Business description

Description

string

No

The document description.

Sales metrics and policy document

EntityId

string

No

The metadata entity ID returned by Data Map. The client must pass this ID as is without concatenating it.

maxcompute-table:::project_name:schema_name:table_name

PrimaryKey

array

No

The explicitly declared primary key field name. This parameter is optional. Each item must exist in the Fields of the current dataset.

string

No

The explicitly declared primary key field name. This parameter is optional. Each item must exist in the Fields of the current dataset.

order_id

Fields

array<object>

No

The fields defined in the dataset that are permitted to be disclosed. If no field definitions are provided, this is an empty array.

object

No

Name

string

No

The document name. Existing objects are not overwritten based on the name.

Business description

Description

string

No

The document description.

Sales metrics and policy document

DataType

string

No

The data type of the field. This must be provided for model fields that are disclosed and is not inferred by the server.

BIGINT

Metrics

array<object>

No

The executable metrics in the model. If no metrics are available, this is an empty array. Metrics with only candidate formulas are not included.

array<object>

No

Name

string

No

The document name. Existing objects are not overwritten based on the name.

Business description

Description

string

No

The document description.

Sales metrics and policy document

DatasetName

string

No

The SemanticDataset.Name to which the metric belongs. It must be found in the Datasets of this model.

orders

Unit

string

No

The explicitly declared unit of the metric. This parameter is optional. It is not returned when no reliable source is available.

CNY

Expression

object

No

The executable expression. It must include at least one dialect version and is not auto-completed by the model.

Dialects

array<object>

No

The expressions of the same metric in different SQL dialects. At least one item is required. Dialects must not be duplicated.

object

No

Dialect

string

No

The SQL dialect, such as MaxCompute or ANSI_SQL.

MaxCompute

Sql

string

No

The non-empty calculation expression in the specified dialect. It is not a complete query statement.

SUM(pay_amount)

Relationships

array<object>

No

The relationships defined in the model and expressed by field pairs. If no relationships are available, this is an empty array. Relationships are not inferred from graph paths.

array<object>

No

Name

string

No

The document name. Existing objects are not overwritten based on the name.

Business description

FromDataset

string

No

The SemanticDataset.Name of the starting dataset.

orders

ToDataset

string

No

The SemanticDataset.Name of the destination dataset.

customers

JoinKeys

array<object>

No

The equi-join pairs of fields at both ends of the relationship. For composite relationships, fields are paired one by one.

object

No

FromField

string

No

The name of the field in the starting dataset that participates in the relationship. It must be defined in the Fields of the dataset corresponding to FromDataset.

customer_id

ToField

string

No

The name of the field in the destination dataset that participates in the relationship. It must be defined in the Fields of the dataset corresponding to ToDataset.

id

UploadId

string

No

The ID of the completed PUT upload session for this knowledge base. This parameter is mutually exclusive with Content.

12345678-1234-4234-8234-123456789abd

ClientToken

string

No

The client token that ensures idempotency. Retries with the same token maintain the original request.

create-document-001

Type

string

Yes

The object type. Fixed to DOCUMENT for this operation.

Valid values:

  • DOCUMENT

DOCUMENT

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The unique identifier of the request, which can be used to troubleshoot issues.

00000000-0000-4000-8000-000000000001

Success

boolean

Indicates whether the request is successful.

Data

object

The business data returned when the request is successful.

KnowledgeBaseId

string

The ID of the knowledge base to which the object belongs.

12345678-1234-4234-8234-123456789abc

KnowledgeObjectId

string

The ID used to locate the object by type. For semantic models, the modelId of the semantic layer is used. For documents, a stable ID generated by the local document table is used. Callers do not parse the ID and do not use the retrieval ID.

obj-document-001

Type

string

The type of the object. The value is fixed to DOCUMENT.

DOCUMENT

Name

string

The user-facing name of the object. This field is editable. Renaming the object does not change the KnowledgeObjectId.

Business description

Description

string

The brief description of the object. This field is editable. Pass an empty string to clear the description.

Sales metrics and policy document

FileName

string

The original file name of the uploaded document. This field is read-only. Renaming the object does not change this value. This field is not returned for external documents and semantic models.

Business_Description.pdf

Content

object

The current valid typed knowledge content. The document or semantic model structure is returned based on the type.

Document

object

This operation returns only the document content.

Text

string

The current document body that can be disclosed. This parameter is optional. It is omitted when parsing is incomplete, authorization is not granted, or the content cannot be provided completely and securely. A single retrieved snippet must not be passed off as the entire document.

Updated full body

ContentFormat

string

Required when Text is present. Valid values: MARKDOWN or TEXT.

MARKDOWN

SemanticModel

object

The semantic model structure. This field exists only when the type is set to SEMANTIC_MODEL.

Datasets

array<object>

The logical datasets contained in the model. An empty array is returned if no datasets can be disclosed.

array<object>

Name

string

The user-facing name of the object. This field is editable. Renaming the object does not change the KnowledgeObjectId.

Business description

Description

string

The brief description of the object. This field is editable. Pass an empty string to clear the description.

Sales metrics and policy document

EntityId

string

The metadata entity ID returned by Data Map. The client must pass this ID as is without concatenating it.

maxcompute-table:::project_name:schema_name:table_name

PrimaryKey

array

The explicitly declared primary key field name. This parameter is optional. Each item must exist in the Fields of the current dataset.

string

The explicitly declared primary key field name. This parameter is optional. Each item must exist in the Fields of the current dataset.

order_id

Fields

array<object>

The fields defined in the dataset that are permitted to be disclosed. If no field definitions are provided, this is an empty array.

object

Name

string

The user-facing name of the object. This field is editable. Renaming the object does not change the KnowledgeObjectId.

Business description

Description

string

The brief description of the object. This field is editable. Pass an empty string to clear the description.

Sales metrics and policy document

DataType

string

The data type of the field. This must be provided for model fields that are disclosed and is not inferred by the server.

BIGINT

Metrics

array<object>

The executable metrics in the model. If no metrics are available, this is an empty array. Metrics with only candidate formulas are not included.

array<object>

Name

string

The user-facing name of the object. This field is editable. Renaming the object does not change the KnowledgeObjectId.

Business description

Description

string

The brief description of the object. This field is editable. Pass an empty string to clear the description.

Sales metrics and policy document

DatasetName

string

The SemanticDataset.Name to which the metric belongs. It must be found in the Datasets of this model.

orders

Unit

string

The explicitly declared unit of the metric. This parameter is optional. It is not returned when no reliable source is available.

CNY

Expression

object

The executable expression. It must include at least one dialect version and is not auto-completed by the model.

Dialects

array<object>

The expressions of the same metric in different SQL dialects. At least one item is required. Dialects must not be duplicated.

object

Dialect

string

The SQL dialect, such as MaxCompute or ANSI_SQL.

MaxCompute

Sql

string

The non-empty calculation expression in the specified dialect. It is not a complete query statement.

SUM(pay_amount)

Relationships

array<object>

The relationships defined in the model and expressed by field pairs. If no relationships are available, this is an empty array. Relationships are not inferred from graph paths.

array<object>

Name

string

The user-facing name of the object. This field is editable. Renaming the object does not change the KnowledgeObjectId.

Business description

FromDataset

string

The SemanticDataset.Name of the starting dataset.

orders

ToDataset

string

The SemanticDataset.Name of the destination dataset.

customers

JoinKeys

array<object>

The equi-join pairs of fields at both ends of the relationship. For composite relationships, fields are paired one by one.

object

FromField

string

The name of the field in the starting dataset that participates in the relationship. It must be defined in the Fields of the dataset corresponding to FromDataset.

customer_id

ToField

string

The name of the field in the destination dataset that participates in the relationship. It must be defined in the Fields of the dataset corresponding to ToDataset.

id

SizeBytes

integer

The size of the uploaded original file in bytes. This field is read-only and does not represent the length of the edited content.

10240

SourceReferences

array<object>

The array of source references. An empty array is currently returned.

object

Type

string

The category of the source reference. The structure retains KNOWLEDGE_SOURCE. Currently, SourceReferences is an empty array.

DOCUMENT

SourceId

string

The SourceId of the KnowledgeSource registered in the current knowledge base. This field exists only when the type is KNOWLEDGE_SOURCE.

src-001

CreateTime

integer

The time when the object was first created.

1790200800000

ModifyTime

integer

The time when the object was last modified, in milliseconds. This value is used for conditional updates of DOCUMENT content. This field does not indicate that optimistic locking updates are supported for semantic models.

1790200800000

Editable

boolean

Indicates whether the current caller has full content editing permissions. The value is true for OWNER and ADMIN, and false for VIEWER. Permissions are checked again for write operations.

VersionNo

integer

The current version of the SEMANTIC_MODEL being read. Pass this value when updating the content to edit the version in place.

1

DownloadUrl

string

The temporary download URL for the original uploaded file of a DOCUMENT or the current specification YAML of a SEMANTIC_MODEL returned by GetKnowledgeObject. This is not a persistent property.

https://example.invalid/short-lived-result-download

ExpiresIn

integer

The validity period of the download URL, in seconds. This field is returned together with DownloadUrl.

300

DownloadFiles

array<object>

The download items for multi-file specification YAMLs, including file names and temporary download URLs.

object

FileName

string

The original file name of the uploaded document. This field is read-only. Renaming the object does not change this value. This field is not returned for external documents and semantic models.

Business_Description.pdf

DownloadUrl

string

The temporary download URL of the specification YAML file. The validity period is subject to ExpiresIn.

https://example.invalid/short-lived-result-download

Code

string

The business error code. You can use this code to determine the error type when a request fails.

InvalidParameter

Message

string

The error message returned when the request fails.

The request parameters are invalid

Examples

Success response

JSON format

{
  "RequestId": "00000000-0000-4000-8000-000000000001",
  "Success": false,
  "Data": {
    "KnowledgeBaseId": "12345678-1234-4234-8234-123456789abc",
    "KnowledgeObjectId": "obj-document-001",
    "Type": "DOCUMENT",
    "Name": "Business description",
    "Description": "Sales metrics and policy document",
    "FileName": "Business_Description.pdf",
    "Content": {
      "Document": {
        "Text": "Updated full body",
        "ContentFormat": "MARKDOWN"
      },
      "SemanticModel": {
        "Datasets": [
          {
            "Name": "Business description",
            "Description": "Sales metrics and policy document",
            "EntityId": "maxcompute-table:::project_name:schema_name:table_name",
            "PrimaryKey": [
              "order_id"
            ],
            "Fields": [
              {
                "Name": "Business description",
                "Description": "Sales metrics and policy document",
                "DataType": "BIGINT"
              }
            ]
          }
        ],
        "Metrics": [
          {
            "Name": "Business description",
            "Description": "Sales metrics and policy document",
            "DatasetName": "orders",
            "Unit": "CNY",
            "Expression": {
              "Dialects": [
                {
                  "Dialect": "MaxCompute",
                  "Sql": "SUM(pay_amount)"
                }
              ]
            }
          }
        ],
        "Relationships": [
          {
            "Name": "Business description",
            "FromDataset": "orders",
            "ToDataset": "customers",
            "JoinKeys": [
              {
                "FromField": "customer_id",
                "ToField": "id"
              }
            ]
          }
        ]
      }
    },
    "SizeBytes": 10240,
    "SourceReferences": [
      {
        "Type": "DOCUMENT",
        "SourceId": "src-001"
      }
    ],
    "CreateTime": 1790200800000,
    "ModifyTime": 1790200800000,
    "Editable": false,
    "VersionNo": 1,
    "DownloadUrl": "https://example.invalid/short-lived-result-download",
    "ExpiresIn": 300,
    "DownloadFiles": [
      {
        "FileName": "Business_Description.pdf",
        "DownloadUrl": "https://example.invalid/short-lived-result-download"
      }
    ]
  },
  "Code": "InvalidParameter",
  "Message": "The request parameters are invalid"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParameter The request parameters are invalid.
400 UploadIncomplete The upload or content is invalid.
400 InputTooLarge The upload or content is invalid.
500 InternalError The knowledge base operation failed. Use RequestId to contact support.
403 Forbidden You are not authorized to perform this operation.
404 ResourceNotFound The requested resource does not exist or is not visible.
409 Conflict The resource state conflicts with this operation.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.