The knowledge base query API only returns the initial user's knowledge base list. #7042

Closed
opened 2026-02-21 18:18:34 -05:00 by yindo · 4 comments
Owner

Originally created by @lackoxy on GitHub (Dec 4, 2024).

Originally assigned to: @JohnJyong on GitHub.

Self Checks

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

Dify version

0.13.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. The current user creates an API key.

  2. Use the API key to call the interface for querying the knowledge base list.

✔️ Expected Behavior

Users should only be able to view the list of knowledge bases they are authorized to access when calling the interface.
For example,these are what i can see in database list.
I recreate a new dify app for test.
Here's the user, '缺氧' 's knowledge base page and '缺氧' created APIKEY to use API.
image

Actual Behavior

Current users are seeing the initial user's accessible database list, and the databases created by the current user are not being returned.
The result returned from the API does not include "测试3 仅缺氧可见" Because this is created by the current user instead of the initial user.
When use '缺氧' ‘s APIKEY, the knowledge base page only mentions 'lackoxy' 's knowledge bases list.
Here's the initial user (lackoxy) knowledge base page
image
#11281

Originally created by @lackoxy on GitHub (Dec 4, 2024). Originally assigned to: @JohnJyong on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [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 (我已阅读并同意 [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. ### Dify version 0.13.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. The current user creates an API key. 2. Use the API key to call the interface for querying the knowledge base list. ### ✔️ Expected Behavior Users should only be able to view the list of knowledge bases they are authorized to access when calling the interface. For example,these are what i can see in database list. I recreate a new dify app for test. Here's the user, '缺氧' 's knowledge base page and '缺氧' created APIKEY to use API. ![image](https://github.com/user-attachments/assets/092a7bfc-81e0-4748-98de-9f1f2fb68c0e) ### ❌ Actual Behavior Current users are seeing the initial user's accessible database list, and the databases created by the current user are not being returned. The result returned from the API does not include "测试3 仅缺氧可见" Because this is created by the current user instead of the initial user. When use '缺氧' ‘s APIKEY, the knowledge base page only mentions 'lackoxy' 's knowledge bases list. Here's the initial user (lackoxy) knowledge base page ![image](https://github.com/user-attachments/assets/768f119f-1d3b-40e9-85c3-6f41f64e12ff) #11281
yindo added the 🐞 bug label 2026-02-21 18:18:34 -05:00
yindo closed this issue 2026-02-21 18:18:34 -05:00
Author
Owner

@lackoxy commented on GitHub (Dec 4, 2024):

The API return value is as follows
APIKEY created by ‘缺氧’

{
    "data": [
        {
            "id": "2d9642de-18b1-4d10-b55d-7577216d57ab",
            "name": "测试2 全部成员可见",
            "description": "",
            "provider": "vendor",
            "permission": "all_team_members",
            "data_source_type": "upload_file",
            "indexing_technique": "high_quality",
            "app_count": 0,
            "document_count": 1,
            "word_count": 470358,
            "created_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63",
            "created_at": 1733296911,
            "updated_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63",
            "updated_at": 1733296945,
            "embedding_model": "text-embedding-v3",
            "embedding_model_provider": "tongyi",
            "embedding_available": true,
            "retrieval_model_dict": {
                "search_method": "semantic_search",
                "reranking_enable": false,
                "reranking_mode": null,
                "reranking_model": {
                    "reranking_provider_name": "",
                    "reranking_model_name": ""
                },
                "weights": null,
                "top_k": 2,
                "score_threshold_enabled": false,
                "score_threshold": 0.0
            },
            "tags": [],
            "external_knowledge_info": {
                "external_knowledge_id": null,
                "external_knowledge_api_id": null,
                "external_knowledge_api_name": null,
                "external_knowledge_api_endpoint": null
            },
            "external_retrieval_model": {
                "top_k": 2,
                "score_threshold": 0.0,
                "score_threshold_enabled": false
            }
        },
        {
            "id": "9b19ded8-72b3-4372-9912-b55c8902f854",
            "name": "测试1 仅lackoxy可见",
            "description": "",
            "provider": "vendor",
            "permission": "only_me",
            "data_source_type": "upload_file",
            "indexing_technique": "high_quality",
            "app_count": 0,
            "document_count": 1,
            "word_count": 86802,
            "created_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63",
            "created_at": 1733296622,
            "updated_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63",
            "updated_at": 1733296893,
            "embedding_model": "text-embedding-v1",
            "embedding_model_provider": "tongyi",
            "embedding_available": true,
            "retrieval_model_dict": {
                "search_method": "semantic_search",
                "reranking_enable": false,
                "reranking_mode": null,
                "reranking_model": {
                    "reranking_provider_name": "",
                    "reranking_model_name": ""
                },
                "weights": null,
                "top_k": 2,
                "score_threshold_enabled": false,
                "score_threshold": 0.0
            },
            "tags": [],
            "external_knowledge_info": {
                "external_knowledge_id": null,
                "external_knowledge_api_id": null,
                "external_knowledge_api_name": null,
                "external_knowledge_api_endpoint": null
            },
            "external_retrieval_model": {
                "top_k": 2,
                "score_threshold": 0.0,
                "score_threshold_enabled": false
            }
        }
    ],
    "has_more": false,
    "limit": 20,
    "total": 2,
    "page": 1
}
@lackoxy commented on GitHub (Dec 4, 2024): The API return value is as follows APIKEY created by ‘缺氧’ ```json { "data": [ { "id": "2d9642de-18b1-4d10-b55d-7577216d57ab", "name": "测试2 全部成员可见", "description": "", "provider": "vendor", "permission": "all_team_members", "data_source_type": "upload_file", "indexing_technique": "high_quality", "app_count": 0, "document_count": 1, "word_count": 470358, "created_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63", "created_at": 1733296911, "updated_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63", "updated_at": 1733296945, "embedding_model": "text-embedding-v3", "embedding_model_provider": "tongyi", "embedding_available": true, "retrieval_model_dict": { "search_method": "semantic_search", "reranking_enable": false, "reranking_mode": null, "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": null, "top_k": 2, "score_threshold_enabled": false, "score_threshold": 0.0 }, "tags": [], "external_knowledge_info": { "external_knowledge_id": null, "external_knowledge_api_id": null, "external_knowledge_api_name": null, "external_knowledge_api_endpoint": null }, "external_retrieval_model": { "top_k": 2, "score_threshold": 0.0, "score_threshold_enabled": false } }, { "id": "9b19ded8-72b3-4372-9912-b55c8902f854", "name": "测试1 仅lackoxy可见", "description": "", "provider": "vendor", "permission": "only_me", "data_source_type": "upload_file", "indexing_technique": "high_quality", "app_count": 0, "document_count": 1, "word_count": 86802, "created_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63", "created_at": 1733296622, "updated_by": "2e7cd82e-cdbc-49fa-8fc2-5a5a24605c63", "updated_at": 1733296893, "embedding_model": "text-embedding-v1", "embedding_model_provider": "tongyi", "embedding_available": true, "retrieval_model_dict": { "search_method": "semantic_search", "reranking_enable": false, "reranking_mode": null, "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": null, "top_k": 2, "score_threshold_enabled": false, "score_threshold": 0.0 }, "tags": [], "external_knowledge_info": { "external_knowledge_id": null, "external_knowledge_api_id": null, "external_knowledge_api_name": null, "external_knowledge_api_endpoint": null }, "external_retrieval_model": { "top_k": 2, "score_threshold": 0.0, "score_threshold_enabled": false } } ], "has_more": false, "limit": 20, "total": 2, "page": 1 } ```
Author
Owner

@dosubot[bot] commented on GitHub (Dec 4, 2024):

The issue you're experiencing with the knowledge base query API returning the initial user's knowledge base list instead of the current user's list might be related to how the API handles authentication and permissions. The API uses an API token to determine which knowledge bases a user is authorized to access. This token should be included in the Authorization HTTP header in the format Authorization: Bearer {API_KEY}. The token grants access to all visible knowledge bases under the same account [1].

If the API is not returning the expected results, it could be due to the API token being associated with the wrong user or permissions not being correctly set for the knowledge bases. Ensure that the API key used in the request is generated by the current user and that the visibility permissions for the knowledge bases are correctly configured. The visibility settings can be "Only Me," "All team members," or "Partial team members," which control who can access the knowledge base [2].

If the issue persists, it might be necessary to check the implementation of the API to ensure that it correctly handles user-specific permissions and visibility settings.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Dec 4, 2024): <!-- Answer --> The issue you're experiencing with the knowledge base query API returning the initial user's knowledge base list instead of the current user's list might be related to how the API handles authentication and permissions. The API uses an API token to determine which knowledge bases a user is authorized to access. This token should be included in the `Authorization` HTTP header in the format `Authorization: Bearer {API_KEY}`. The token grants access to all visible knowledge bases under the same account <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/.gitbook/assets/Dify-test.openapi.json)</sup>. If the API is not returning the expected results, it could be due to the API token being associated with the wrong user or permissions not being correctly set for the knowledge bases. Ensure that the API key used in the request is generated by the current user and that the visibility permissions for the knowledge bases are correctly configured. The visibility settings can be "Only Me," "All team members," or "Partial team members," which control who can access the knowledge base <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/knowledge-base/knowledge-and-documents-maintenance.md)</sup>. If the issue persists, it might be necessary to check the implementation of the API to ensure that it correctly handles user-specific permissions and visibility settings. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@lackoxy commented on GitHub (Jan 7, 2025):

Any information there?

@lackoxy commented on GitHub (Jan 7, 2025): Any information there?
Author
Owner

@dosubot[bot] commented on GitHub (Feb 8, 2025):

Hi, @lackoxy. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • A bug was reported in the knowledge base query API.
  • The API returns the initial user's knowledge base list instead of the current user's list when using an API key.
  • I suggested checking API key generation and visibility permissions.
  • You requested further clarification on the issue.

Next Steps

  • Please confirm if this issue is still relevant to the latest version of the Dify repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 8, 2025): Hi, @lackoxy. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary** - A bug was reported in the knowledge base query API. - The API returns the initial user's knowledge base list instead of the current user's list when using an API key. - I suggested checking API key generation and visibility permissions. - You requested further clarification on the issue. **Next Steps** - Please confirm if this issue is still relevant to the latest version of the Dify repository by commenting here. - If there is no further activity, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7042