External Knowledge API
Editor: Allen. Dify Technical Writer
Last updated
Editor: Allen. Dify Technical Writer
Last updated
This API is used to connect to a knowledge base that is independent of the Dify and maintained by developers. For more details, please refer to Connecting to an External Knowledge Base. You can use API-Key
in the Authorization
HTTP Header to verify permissions. The authentication logic is defined by you in the retrieval API, as shown below:
The request accepts the following data in JSON format.
Property | Required | Type | Description | Example value |
---|---|---|---|---|
The retrieval_setting
property is an object containing the following keys:
Property | Required | Type | Description | Example value |
---|---|---|---|---|
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
The records
property is a list object containing the following keys:
If the action fails, the service sends back the following error information in JSON format:
The error_code
property has the following types:
AccessDeniedException The request is denied because of missing access permissions. Check your permissions and retry your request. HTTP Status Code: 403
InternalServerException An internal server error occurred. Retry your request. HTTP Status Code: 500
Property | Required | Type | Description | Example value |
---|---|---|---|---|
Property | Required | Type | Description | Example value |
---|---|---|---|---|
Property | Required | Type | Description | Example value |
---|---|---|---|---|
Code | Description |
---|---|
knowledge_id
TRUE
string
Your knowledge's unique ID
AAA-BBB-CCC
query
TRUE
string
User's query
What is Dify?
retrieval_setting
TRUE
object
Knowledge's retrieval parameters
See below
top_k
TRUE
int
Maximum number of retrieved results
5
score_threshold
TRUE
float
The score limit of relevance of the result to the query, scope: 0~1
0.5
records
TRUE
List[Object]
A list of records from querying the knowledge base.
See below
content
TRUE
string
Contains a chunk of text from a data source in the knowledge base.
Dify:The Innovation Engine for GenAI Applications
score
TRUE
float
The score of relevance of the result to the query, scope: 0~1
0.5
title
TRUE
string
Document title
Dify Introduction
metadata
FALSE
json
Contains metadata attributes and their values for the document in the data source.
See example
error_code
TRUE
int
Error code
1001
error_msg
TRUE
string
The description of API exception
Invalid Authorization header format. Expected 'Bearer ' format.
1001
Invalid Authorization header format.
1002
Authorization failed
2001
The knowledge does not exist