Studio: trim captioner logs to invoked+complete, render subprocess logs as JSON

Two changes to the RAG captioning log output:

  - Drop the noisy per-image and path-selection info lines
    (using-chat-VLM, loading-helper, per-image done). Only the
    'caption_images: invoked' and 'caption_images: complete' lines
    remain; warnings for genuine failures (helper load, per-image
    request, helper unload) are kept.
  - Configure structlog at the top of the ingestion subprocess worker
    with the same env the parent uses. The worker runs in a spawned
    process where structlog was never set up, so its logs fell back to
    structlog's dev ConsoleRenderer ([info] ...) instead of the JSON
    renderer the rest of the app uses. Now captioner/parser logs from
    the subprocess match the parent's JSON format.
This commit is contained in:
Roland Tannous 2026-05-28 13:39:13 +04:00
commit 290201f62e
2 changed files with 15 additions and 15 deletions

View file

@ -170,13 +170,7 @@ def caption_images(
if vlm_url and vlm_model:
endpoint = f"{vlm_url.rstrip('/')}/v1/chat/completions"
model_name = vlm_model
logger.info(
"caption_images: using loaded chat VLM",
endpoint = endpoint,
model = model_name,
)
else:
logger.info("caption_images: chat VLM unavailable, loading helper")
loaded = _load_helper_vlm()
if loaded is None:
logger.warning(
@ -186,20 +180,12 @@ def caption_images(
helper_backend, helper_base_url, helper_model_name = loaded
endpoint = f"{helper_base_url.rstrip('/')}/v1/chat/completions"
model_name = helper_model_name
logger.info("caption_images: using helper VLM", endpoint = endpoint)
out: list[str] = []
with httpx.Client(timeout = _REQUEST_TIMEOUT_SECONDS) as client:
for idx, blob in enumerate(image_bytes_list):
try:
caption = _post_one(client, endpoint, model_name, blob)
out.append(caption)
logger.info(
"caption_images: per-image done",
idx = idx,
caption_len = len(caption),
preview = caption[:80],
)
out.append(_post_one(client, endpoint, model_name, blob))
except Exception as exc: # noqa: BLE001
logger.warning(
"caption_images: per-image request failed",

View file

@ -64,6 +64,20 @@ def _subprocess_worker(
vlm_url: str | None = None,
vlm_model: str | None = None,
) -> None:
# Spawned subprocess: structlog isn't configured here (the parent's
# setup runs in the FastAPI process only), so configure it the same
# way so captioner / parser logs render as JSON like the rest, not
# structlog's default dev ConsoleRenderer.
try:
import os as _os
from loggers.config import LogConfig
LogConfig.setup_logging(
env = _os.getenv("ENVIRONMENT_TYPE", "production"),
)
except Exception: # noqa: BLE001
pass
try:
from core.rag.captioner import caption_images
from core.rag.chunking import chunk_pages