unsloth/studio/backend/core/rag
Roland Tannous 3f6a390df6 Studio: precache RAG reranker on startup; instrument loader + predict
The reranker model (BAAI/bge-reranker-base by default, ~1.1 GB) was
never precached, so the first user-facing rerank call paid the full
download cost — which on slow connections looked like a hang and got
retried by upstream timeouts. The deprecation warning that surfaced
during the hang was actually from sentence-transformers internals
firing while the download was still in flight.

Mirror the precache_helper_gguf pattern: add precache_reranker() that
calls snapshot_download in a daemon thread at FastAPI startup. The
first opt-in rerank now finds the weights already on disk and only
pays the in-process model load.

Also tighten the loader:
  - explicit device selection (cuda when torch.cuda.is_available,
    else cpu) so we don't rely on sentence-transformers auto-detect
    behaviour that has historically picked cpu under odd
    CUDA_VISIBLE_DEVICES configs;
  - structlog-shaped logs with elapsed_seconds around load + predict
    so a real runtime hang is visible in /tmp/studio.log with
    'RAG reranker predict starting' / 'RAG reranker predict done'.
2026-05-27 20:36:19 +04:00
..
parsers Studio: splice VLM figure captions next to their 'Figure N:' line 2026-05-27 17:02:36 +04:00
__init__.py Studio: add RAG with hybrid search, reranker, chat integration 2026-05-23 18:46:15 +04:00
bm25.py Studio: trim verbose comments/docstrings across RAG code 2026-05-26 13:51:11 +04:00
captioner.py Studio: render figure regions (vector + raster) for RAG captioning 2026-05-27 16:36:54 +04:00
chunking.py Studio: break RAG chunks at figure/table caption boundaries 2026-05-27 16:09:23 +04:00
db.py Studio: trim verbose comments/docstrings across RAG code 2026-05-26 13:51:11 +04:00
embeddings.py Studio: pass BytesIO (not PIL Image) to BGE-VL encode so model.data_process can re-open 2026-05-27 05:44:40 +04:00
ingestion.py Studio: route RAG ingestion + captioner loggers through structlog 2026-05-27 15:20:22 +04:00
reranker.py Studio: precache RAG reranker on startup; instrument loader + predict 2026-05-27 20:36:19 +04:00
retrieval.py Studio: add figure-reference retrieval source to RAG hybrid search 2026-05-27 16:22:08 +04:00
scope.py Studio: text-mode default with VLM-captioned figure splicing; helper VLM fallback 2026-05-27 11:16:56 +04:00
tool.py Studio: hide RAG retrieval scores from chunks, citations, and side panel 2026-05-27 17:15:18 +04:00
vector_store.py Studio: trim verbose comments/docstrings across RAG code 2026-05-26 13:51:11 +04:00