Studio: route RAG parent-process loggers through structlog

core/rag/db.py, vector_store.py, tool.py, bm25.py, and reranker.py
all run only in the FastAPI parent process. Switch their loggers
from Python stdlib to studio's structlog get_logger so their output
shows up in the same JSON stream as the rest of the backend (the
request_completed / RAG search lines).

embeddings.py and ingestion.py stay on stdlib because they execute
inside the mp.spawn ingestion subprocess, which doesn't inherit the
parent's structlog configuration.
This commit is contained in:
Roland Tannous 2026-05-25 15:25:11 +04:00
commit 005234c953
5 changed files with 13 additions and 11 deletions

View file

@ -17,15 +17,15 @@ A scope is ``kb_<uuid>`` or ``thread_<uuid>``. Each scope stores:
from __future__ import annotations
import json
import logging
import shutil
import threading
from pathlib import Path
from typing import Any
from loggers import get_logger
from utils.paths.storage_roots import ensure_dir, rag_bm25_root
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
_load_lock = threading.Lock()
_cache: dict[str, tuple[Any, list[str]]] = {}

View file

@ -11,14 +11,14 @@ to the RAG code path only — chat code keeps its plain sqlite handle.
from __future__ import annotations
import logging
import sqlite3
import threading
from pathlib import Path
from loggers import get_logger
from utils.paths.storage_roots import ensure_dir, rag_root
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
_conn: sqlite3.Connection | None = None
_conn_lock = threading.Lock()
@ -96,7 +96,7 @@ def get_rag_connection() -> sqlite3.Connection:
_load_sqlite_vec(conn)
_ensure_schema(conn)
_conn = conn
logger.info("RAG vector store: opened %s", rag_db_path())
logger.info("RAG vector store opened", path = str(rag_db_path()))
return _conn

View file

@ -17,15 +17,15 @@ replacing the import in ``_load``.
from __future__ import annotations
import gc
import logging
import threading
from typing import Any
from loggers import get_logger
from utils.rag.config import RAG_RERANK_BATCH_SIZE, RAG_RERANKER_MODEL
from .retrieval import Hit
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
_lock = threading.Lock()
_model: Any | None = None

View file

@ -16,10 +16,11 @@ LLM doesn't need to know about KB UUIDs.
from __future__ import annotations
import logging
from typing import Any
logger = logging.getLogger(__name__)
from loggers import get_logger
logger = get_logger(__name__)
SEARCH_KNOWLEDGE_BASE_TOOL = {

View file

@ -20,10 +20,11 @@ scope, so dims within a scope are always consistent.
from __future__ import annotations
import json
import logging
from typing import Iterable
logger = logging.getLogger(__name__)
from loggers import get_logger
logger = get_logger(__name__)
def kb_scope(kb_id: str) -> str: