Skip to content

[DOCS]: #816

@yangzhengyz

Description

@yangzhengyz

Type of Documentation Change

Error/Typo fix

Documentation Page URL or Path

No response

Current Content

## Title

Knowledge Base Retrieve API returns `query` as string, inconsistent with API documentation

## Description

When calling the Knowledge Base Retrieve API, the actual response from Dify Cloud returns the top-level `query` field as a string.

However, the official API documentation shows `query` as an object with a `content` field.

Documentation:
https://docs.dify.ai/api-reference/knowledge-bases/retrieve-chunks-from-a-knowledge-base-test-retrieval

## Request

```json
{
  "query": "yz",
  "retrieval_model": {
    "search_method": "hybrid_search",
    "reranking_enable": false,
    "top_k": 10,
    "score_threshold_enabled": false
  }
}

Actual Response

{
  "query": "yz",
  "records": [
    {
      "segment": {
        "id": "19cf80b3-52e0-4a5b-ae88-5ccb252257a1",
        "position": 3,
        "document_id": "21b5c3d6-758b-48b8-ada9-3daef876f5f4",
        "content": "..."
      },
      "score": 0.47933036
    }
  ]
}

Expected Response

According to the API documentation, query should be an object:

{
  "query": {
    "content": "yz"
  },
  "records": [...]
}

Environment

  • Dify endpoint: https://api.dify.ai/v1
  • API: POST /datasets/{dataset_id}/retrieve
  • Search method: hybrid_search
  • Response status: 200

```markdown
Please confirm whether the documented response schema is outdated, or whether the API should return `query` as `{ "content": "..." }`.

Suggested Changes

Please confirm whether the documented response schema is outdated, or whether the API should return query as { "content": "..." }.

Reason for Change

Expected Response

According to the API documentation, query should be an object:

{
  "query": {
    "content": "yz"
  },
  "records": [...]
}

Impact

Java clients generated or implemented according to the official documentation may fail to deserialize the response.

For example, AgentScope Java models query as an object:

private DifyResponse.Query query;

public static class Query {
    private String content;
}

This causes the following deserialization error:

Cannot construct instance of DifyResponse$Query
no String-argument constructor/factory method to deserialize from String value ('杨正')
through reference chain: DifyResponse["query"]

Environment

  • Dify endpoint: https://api.dify.ai/v1
  • API: POST /datasets/{dataset_id}/retrieve
  • Search method: hybrid_search
  • Response status: 200

### Code of Conduct

- [x] I agree to follow Dify's documentation [contribution guidelines](https://github.com/langgenius/dify/blob/0277a37fcad5ad86aeb239485c27fffd5cd90043/CONTRIBUTING.md)
- [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions