Maintain Knowledge via API
The authentication and invocation methods for the Knowledge Base API are consistent with the Application Service API. However, a single Knowledge Base API token generated has the authority to operate on all visible knowledge bases under the same account. Please pay attention to data security.
Advantages of Utilizing Knowledge Base API
Leveraging the API for knowledge base maintenance significantly enhances data processing efficiency. It enables seamless data synchronization via command-line interfaces, facilitating automated operations instead of manipulating the user interface.
Key advantages include:
- Automated Synchronization: Enables seamless integration between data systems and the Dify knowledge base, fostering efficient workflow construction.
- Comprehensive Management: Offers functionalities such as knowledge base listing, document enumeration, and detailed querying, facilitating the development of custom data management interfaces.
- Flexible Content Ingestion: Accommodates both plain text and file upload methodologies, supporting batch operations for addition and modification of content chunks.
- Enhanced Productivity: Minimizes manual data handling requirements, thereby optimizing the overall user experience on the Dify platform.
How to Use
Navigate to the knowledge base page, and you can switch to the API ACCESS page from the left navigation. On this page, you can view the dataset API documentation provided by Dify and manage the credentials for accessing the dataset API in API Keys.
API Requesting Examples
Create a document from text
This api is based on an existing Knowledge and creates a new document through text based on this Knowledge.
Request example:
Response example:
Create a Document from a file
This API is based on an existing knowledge and creates a new document through a file based on this knowledge.
Create Documents from a File
This api is based on an existing Knowledge and creates a new document through a file based on this Knowledge.
Request example:
Response example:
Create an Empty Knowledge Base
Only used to create an empty knowledge base.
Request example:
Response example:
Get Knowledge Base List
Request example:
Response example:
Delete a Knowledge Base
Request example:
Response example:
Update a Document with Text
This api is based on an existing Knowledge and updates the document through text based on this Knowledge
Request example:
Response example:
Update a document with a file
This api is based on an existing Knowledge, and updates documents through files based on this Knowledge.
Request example:
Response example:
Get Document Embedding Status (Progress)
Request example:
Response example:
Delete a Document
Request example:
Response example:
Get the Document List of a Knowledge Base
Request example:
Response example:
Add Chunks to a Document
Request example:
Response example:
Get Chunks from a Document
Request example:
Response example:
Delete a Chunk in a Document
Request example:
Response example:
Update a Chunk in a Document
Request example:
Response example:
Retrieve Chunks from a Knowledge Base
Request example:
Response example:
Add Metadata Fields to the Knowledge Base
Request example:
Response example:
Modify Metadata Fields in the Knowledge Base
Request example:
Response example:
Delete Metadata Fields in the Knowledge Base
Request example:
Response example:
Enable/Disable Built-in Fields in the Knowledge Base
Request example:
Response example:
Modify Metadata for a Single Document (Assignment)
Request example:
Response example:
Metadata List of the Dataset
Request example:
Response example:
Error message
Response example:
code | status | message |
---|---|---|
no_file_uploaded | 400 | Please upload your file. |
too_many_files | 400 | Only one file is allowed. |
file_too_large | 413 | File size exceeded. |
unsupported_file_type | 415 | File type not allowed. Supported format: txt, markdown, md, pdf, html, html, xlsx, docx, csv |
high_quality_dataset_only | 400 | Current operation only supports ‘high-quality’ datasets. |
dataset_not_initialized | 400 | The dataset is still being initialized or indexing. Please wait a moment. |
archived_document_immutable | 403 | The archived document is not editable. |
dataset_name_duplicate | 409 | The dataset name already exists. Please modify your dataset name. |
invalid_action | 400 | Invalid action. |
document_already_finished | 400 | The document has been processed. Please refresh the page or go to the document details. |
document_indexing | 400 | The document is being processed and cannot be edited. |
invalid_metadata | 400 | The metadata content is incorrect. Please check and verify. |
Was this page helpful?