HKUDS/DeepTutor · error · HTTPException

Knowledge base '{requested}' not found

Error message

Knowledge base '{requested}' not found

What it means

HTTP 404 from _resolve_default_or_name: a specific (non-alias) KB name was requested but does not exist among the manager's knowledge bases for the current base_dir. Distinct from the alias branch: this is an explicit name miss.

Source

Thrown at deeptutor/multi_user/knowledge_access.py:164

            source="admin",
            assigned=True,
            read_only=True,
        )

    raise HTTPException(status_code=404, detail=f"Knowledge base '{name}' not found")


def _resolve_default_or_name(manager: KnowledgeBaseManager, name: str) -> str:
    requested = str(name or "").strip()
    names = manager.list_knowledge_bases()
    if requested and requested in names:
        return requested
    if requested.lower() in DEFAULT_KB_ALIASES:
        default_kb = manager.get_default()
        if default_kb and default_kb in names:
            return default_kb
        raise HTTPException(status_code=404, detail="No default knowledge base is configured")
    raise HTTPException(status_code=404, detail=f"Knowledge base '{requested}' not found")


def manager_for_resource(resource: KnowledgeResource) -> KnowledgeBaseManager:
    return _manager_for(str(resource.base_dir.resolve()))


def list_visible_knowledge_bases() -> list[dict[str, Any]]:
    user = get_current_user()
    manager = current_kb_manager()
    items: list[dict[str, Any]] = []
    for name in manager.list_knowledge_bases():
        items.append(
            {
                "id": f"admin:kb:{name}" if user.is_admin else f"user:kb:{name}",
                "name": name,
                "source": "admin" if user.is_admin else "user",
                "assigned": False,
                "read_only": False,

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Verify the name against manager.list_knowledge_bases() for the same base_dir the manager was built with
  2. Create the KB first (kb create) if it should exist
  3. Confirm the correct user/workspace context is supplying base_dir

Example fix

// before
kb = resolve_kb("team-kb")  # 404: not in this workspace

// after
manager = KnowledgeBaseManager(base_dir=resource_base_dir)
if "team-kb" not in manager.list_knowledge_bases():
    manager.create_knowledge_base("team-kb")
kb = resolve_kb("team-kb")
Defensive patterns

Strategy: validation

Validate before calling

names = manager.list_knowledge_bases()
if name not in names:
    manager.create_knowledge_base(name)
kb = resolve_kb(name)

Type guard

def kb_in_scope(name: str, manager: KnowledgeBaseManager) -> bool:
    return name in manager.list_knowledge_bases()

Try / catch

try:
    resolve_kb(name)
except HTTPException as e:
    if e.status_code == 404 and name.lower() not in DEFAULT_KB_ALIASES:
        raise KBNotFound(name) from e

Prevention

When it happens

Trigger: resolve_kb('my-kb') where 'my-kb' is not returned by manager.list_knowledge_bases(); wrong base_dir scoped to another user/workspace; KB not yet created.

Common situations: Per-user storage directories so each manager sees only its own KBs; calling with a name from a different workspace; race where the KB is created after the call.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/84a922bcc622a7bb. Report an issue: GitHub.