Example Response of External Knowledge API #26

Closed
opened 2026-02-16 11:19:32 -05:00 by yindo · 2 comments
Owner

Originally created by @zolgear on GitHub (Oct 9, 2024).

https://docs.dify.ai/guides/knowledge-base/external-knowledge-api-documentation

en\guides\knowledge-base\external-knowledge-api-documentation.md


There is an issue with the JSON response generated by Swagger.

{
  "records": {
    "content": "text",
    "score": 0,
    "title": "text",
    "metadata": "text"
  }
}

The records should be an array, but it is represented with { }. If implemented as is, it will result in a "500 Internal Server Error: 'str' object has no attribute 'get'" during the hit test in /app/api/controllers/console/datasets/external.py.

Fix:

{
  "records": [
    {
      "content": "text",
      "score": 0,
      "title": "text",
      "metadata": "text"
    }
  ]
}

Can you modify en\.gitbook\assets\Dify-test.openapi.json to fix it?

Originally created by @zolgear on GitHub (Oct 9, 2024). <https://docs.dify.ai/guides/knowledge-base/external-knowledge-api-documentation> [en\guides\knowledge-base\external-knowledge-api-documentation.md](https://github.com/langgenius/dify-docs/blob/432003dd81ca304bade0f121659ba724769bc3e0/en/guides/knowledge-base/external-knowledge-api-documentation.md) ---- There is an issue with the JSON response generated by Swagger. ```json { "records": { "content": "text", "score": 0, "title": "text", "metadata": "text" } } ``` The `records` should be an array, but it is represented with `{ }`. If implemented as is, it will result in a "500 Internal Server Error: 'str' object has no attribute 'get'" during the hit test in `/app/api/controllers/console/datasets/external.py`. Fix: ```json { "records": [ { "content": "text", "score": 0, "title": "text", "metadata": "text" } ] } ``` Can you modify `en\.gitbook\assets\Dify-test.openapi.json` to fix it?
yindo added the bug label 2026-02-16 11:19:32 -05:00
yindo closed this issue 2026-02-16 11:19:32 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 9, 2024):

To fix the issue with the records field in the Dify-test.openapi.json file, you need to modify the schema to ensure records is an array. Here's how you can update it:

Change the records field definition from an object to an array of objects:

"records": {
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "content": {
        "type": "string",
        "description": "Contains a chunk of text from a data source in the knowledge base."
      },
      "score": {
        "type": "number",
        "format": "float",
        "description": "The score of relevance of the result to the query, scope: 0~1"
      },
      "title": {
        "type": "string",
        "description": "Document title"
      },
      "metadata": {
        "type": "string",
        "description": "Contains metadata attributes and their values for the document in the data source."
      }
    },
    "required": ["content", "score", "title"]
  },
  "title": "A list of records from querying the knowledge base."
}

This change will ensure that the records field is correctly formatted as an array, preventing the "500 Internal Server Error" [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 9, 2024): <!-- Answer --> To fix the issue with the `records` field in the `Dify-test.openapi.json` file, you need to modify the schema to ensure `records` is an array. Here's how you can update it: Change the `records` field definition from an object to an array of objects: ```json "records": { "type": "array", "items": { "type": "object", "properties": { "content": { "type": "string", "description": "Contains a chunk of text from a data source in the knowledge base." }, "score": { "type": "number", "format": "float", "description": "The score of relevance of the result to the query, scope: 0~1" }, "title": { "type": "string", "description": "Document title" }, "metadata": { "type": "string", "description": "Contains metadata attributes and their values for the document in the data source." } }, "required": ["content", "score", "title"] }, "title": "A list of records from querying the knowledge base." } ``` This change will ensure that the `records` field is correctly formatted as an array, preventing the "500 Internal Server Error" <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/.gitbook/assets/Dify-test.openapi.json)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@zolgear commented on GitHub (Nov 1, 2024):

Thank you for making these changes.

@zolgear commented on GitHub (Nov 1, 2024): Thank you for making these changes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs-archived#26