Skip to content

KeyError: 'image' / 'docx' in configure_content() on /api/update (2.0.0b28) #1317

@JustMarco88

Description

@JustMarco88

Summary

GET /api/update returns HTTP 500 (Failed to update content index) on a fresh Khoj 2.0.0b28 install when the default t=all search type is used. Scoping to t=markdown (or any non-image, non-docx type) works correctly.

Root cause

In khoj/routers/helpers.py::configure_content(), the image and docx branches use bracket lookup on files:

# line ~3142 (image)
if (search_type == state.SearchType.All.value or search_type == state.SearchType.Image.value) and files["image"]:

# line ~3157 (docx)
if (search_type == state.SearchType.All.value or search_type == state.SearchType.Docx.value) and files["docx"]:

Every other content type in the same function uses files.get(...) and is safe against a missing key:

# org (~3024), markdown (~3046), pdf (~3064), plaintext (~3082)
if ... and files.get("markdown"):

When a client (or a call from /api/update) does not populate files with "image" and "docx" keys, the bracket lookup raises KeyError. The inner try/except Exception on those two blocks catches it, logs Failed to setup images: 'image' / Failed to setup docx: 'docx', and sets success = False. The outer caller then raises RuntimeError("Failed to update content index") -> 500.

Logs from affected install

🚨 Failed to setup images: 'image'
Traceback (most recent call last):
KeyError: 'image'
🚨 Failed to setup docx: 'docx'
Traceback (most recent call last):
KeyError: 'docx'
🚨 Failed to update server indexed content via API: Failed to update content index

Workaround

Scope the request to a non-image, non-docx type:

GET /api/update?force=true&t=markdown

Short-circuits the two buggy guards before the bracket lookup.

Suggested fix

Two-character change:

-        ) and files["image"]:
+        ) and files.get("image"):

And the same for files["docx"]. Consistent with how every other file-type branch already works in the same function.

Environment

  • Khoj: 2.0.0b28 (from PyPI, 2026-03-26 release)
  • Python: 3.12
  • OS: macOS 15.4 (Apple Silicon)
  • Deployment: native process, --no-gui, single-user

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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