How to modify the top_k value of dify deployed by docker to 20? #8923

Closed
opened 2026-02-21 18:28:39 -05:00 by yindo · 2 comments
Owner

Originally created by @Vampxgg on GitHub (Mar 3, 2025).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

How to modify the top_k value of dify deployed by docker to 20?

Image

Originally created by @Vampxgg on GitHub (Mar 3, 2025). ### Self Checks - [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 report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Provide a description of requested docs changes How to modify the top_k value of dify deployed by docker to 20? ![Image](https://github.com/user-attachments/assets/0808c182-379e-4c21-beab-6a9e9a327948)
yindo added the 🙋‍♂️ question label 2026-02-21 18:28:39 -05:00
yindo closed this issue 2026-02-21 18:28:39 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 3, 2025):

To modify the top_k value of Dify deployed by Docker to 20, you need to set the TOP_K_MAX_VALUE environment variable in the web service section of your docker-compose-template.yaml file. You can do this by adding or modifying the line as follows:

web:
  image: langgenius/dify-web:0.15.3
  restart: always
  environment:
    CONSOLE_API_URL: ${CONSOLE_API_URL:-}
    APP_API_URL: ${APP_API_URL:-}
    SENTRY_DSN: ${WEB_SENTRY_DSN:-}
    NEXT_TELEMETRY_DISABLED: ${NEXT_TELEMETRY_DISABLED:-0}
    TEXT_GENERATION_TIMEOUT_MS: ${TEXT_GENERATION_TIMEOUT_MS:-60000}
    CSP_WHITELIST: ${CSP_WHITELIST:-}
    TOP_K_MAX_VALUE: 20
    INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH: ${INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH:-}

Additionally, you can also set the TOP_K_MAX_VALUE in the .env file used by Docker Compose by modifying the following line:

TOP_K_MAX_VALUE=20

This ensures that the TOP_K_MAX_VALUE is set to 20 for the web service [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 3, 2025): <!-- Answer --> To modify the `top_k` value of Dify deployed by Docker to 20, you need to set the `TOP_K_MAX_VALUE` environment variable in the `web` service section of your `docker-compose-template.yaml` file. You can do this by adding or modifying the line as follows: ```yaml web: image: langgenius/dify-web:0.15.3 restart: always environment: CONSOLE_API_URL: ${CONSOLE_API_URL:-} APP_API_URL: ${APP_API_URL:-} SENTRY_DSN: ${WEB_SENTRY_DSN:-} NEXT_TELEMETRY_DISABLED: ${NEXT_TELEMETRY_DISABLED:-0} TEXT_GENERATION_TIMEOUT_MS: ${TEXT_GENERATION_TIMEOUT_MS:-60000} CSP_WHITELIST: ${CSP_WHITELIST:-} TOP_K_MAX_VALUE: 20 INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH: ${INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH:-} ``` Additionally, you can also set the `TOP_K_MAX_VALUE` in the `.env` file used by Docker Compose by modifying the following line: ```env TOP_K_MAX_VALUE=20 ``` This ensures that the `TOP_K_MAX_VALUE` is set to 20 for the web service <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/docker-compose-template.yaml)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/docker/.env.example)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9861c78d-bb75-424f-b76d-453caeb65c10?feedback_type=other)</sup>
Author
Owner

@SamJo2023 commented on GitHub (Sep 12, 2025):

  1. Modify the value of the environment variable in .env and docker-compose.yaml
  • KEY TOP_K_MAX_VALUE: ${TOP_K_MAX_VALUE:-10} in docker-compose.yaml is changed to the maximum recall number you want
  • KEY TOP_K_MAX_VALUE=10 in .env (directory: ./.env) Change to the maximum recall number you want
  1. After the modification is completed, execute
docker compose down
docker compose up -d
  1. Settings in the application:
    A very critical point is the setting of position 1 in the figure below.
    It will only take effect after it is set here. Otherwise, if 2 is set greater than 10, the maximum number of returned fragments is still 10. If the values ​​set in 1 and 2 are different, the smallest value will be finally taken.

@SamJo2023 commented on GitHub (Sep 12, 2025): 1. Modify the value of the environment variable in ` .env ` and **docker-compose.yaml** - KEY `TOP_K_MAX_VALUE: ${TOP_K_MAX_VALUE:-10}` in docker-compose.yaml is changed to the maximum recall number you want - KEY `TOP_K_MAX_VALUE=10` in .env (directory: ./.env) Change to the maximum recall number you want 2. After the modification is completed, execute ``` cmd docker compose down docker compose up -d ``` 3. Settings in the application: A very critical point is the setting of position 1 in the figure below. It will only take effect after it is set here. Otherwise, if 2 is set greater than 10, the maximum number of returned fragments is still 10. If the values ​​set in 1 and 2 are different, the smallest value will be finally taken. ![](https://obtong-1317320194.cos.ap-guangzhou.myqcloud.com/obsidian/202509121702341.png?imageSlim)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8923