Maintain Knowledge Base 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 documents from files
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
Only used to create an empty knowledge base.
Request example:
Response example:
Knowledge list
Request example:
Response example:
Delete knowledge
Request example:
Response example:
Update document via 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 from 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 document
Request example:
Response example:
Knowledge document list
Request example:
Response example:
Add chunk
Request example:
Response example:
Get documents chunks
Request example:
Response example:
Delete document segment
Request example:
Response example:
Update document chunk
Request example:
Response example:
Error message
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. |