mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
Fix: shared dataset chunk index lookup (#14764)
### What problem does this PR solve? shared dataset chunk index lookup ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -706,6 +706,36 @@ class TestDocRoutesUnit:
|
||||
assert res["data"]["total"] == 1
|
||||
assert res["data"]["chunks"][0]["id"] == "chunk-1"
|
||||
|
||||
def test_list_chunks_uses_dataset_owner_index_for_team_dataset(self, monkeypatch):
|
||||
module = _load_restful_chunk_module(monkeypatch)
|
||||
seen = {}
|
||||
monkeypatch.setattr(module.KnowledgebaseService, "accessible", lambda **_kwargs: True)
|
||||
monkeypatch.setattr(
|
||||
module.KnowledgebaseService,
|
||||
"get_by_id",
|
||||
lambda _dataset_id: (True, SimpleNamespace(tenant_id="owner-tenant")),
|
||||
)
|
||||
monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(kb_id="ds-1")])
|
||||
monkeypatch.setattr(module, "request", SimpleNamespace(args=_DummyArgs({})))
|
||||
|
||||
def _index_exist(index_name, dataset_id):
|
||||
seen["index_exist"] = (index_name, dataset_id)
|
||||
return True
|
||||
|
||||
class _Retriever:
|
||||
async def search(self, _query, index_name, dataset_ids, *_args, **_kwargs):
|
||||
seen["search"] = (index_name, dataset_ids)
|
||||
return SimpleNamespace(total=0, ids=[], field={}, highlight={})
|
||||
|
||||
_patch_docstore(monkeypatch, module, index_exist=_index_exist)
|
||||
monkeypatch.setattr(module.settings, "retriever", _Retriever())
|
||||
|
||||
res = _run(_route_core(module.list_chunks)("member-tenant", "ds-1", "doc-1"))
|
||||
|
||||
assert res["code"] == 0
|
||||
assert seen["index_exist"] == ("idx-owner-tenant", "ds-1")
|
||||
assert seen["search"] == ("idx-owner-tenant", ["ds-1"])
|
||||
|
||||
def test_add_chunk_access_guard(self, monkeypatch):
|
||||
module = _load_restful_chunk_module(monkeypatch)
|
||||
monkeypatch.setattr(module.KnowledgebaseService, "accessible", lambda **_kwargs: False)
|
||||
|
||||
@@ -377,7 +377,7 @@ def _load_chunk_module(monkeypatch):
|
||||
|
||||
@staticmethod
|
||||
def get_by_id(_kb_id):
|
||||
return True, SimpleNamespace(pagerank=0.6, tenant_embd_id=2, tenant_llm_id=1)
|
||||
return True, SimpleNamespace(pagerank=0.6, tenant_id="tenant-1", tenant_embd_id=2, tenant_llm_id=1)
|
||||
|
||||
kb_service_mod.KnowledgebaseService = _KnowledgebaseService
|
||||
monkeypatch.setitem(sys.modules, "api.db.services.knowledgebase_service", kb_service_mod)
|
||||
@@ -653,4 +653,3 @@ def test_restful_chunk_guard_branches_unit(monkeypatch):
|
||||
res = _run(_route_core(module.switch_chunks)("tenant-1", "kb-1", "doc-1"))
|
||||
assert res["message"] == "`available_int` or `available` is required.", res
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user