unsloth/studio/backend/core/rag
Roland Tannous 7b3a13fea4 Studio: address gemini-code-assist PR review
Four valid review comments from gemini-code-assist[bot] on #5759:

1. core/rag/bm25.py:_load — wrap bm25s.BM25.load + json.loads with
   specific exception handlers (FileNotFoundError, OSError,
   JSONDecodeError, ValueError) and log a warning instead of
   propagating a 500. Corrupt/partial bm25 dirs now degrade to
   empty-search rather than crashing the request.

2. core/rag/tool.py was importing _resolve_scope_embedder from
   routes/rag.py — a layering violation (core depending on
   routes). Move the resolver into a new core/rag/scope.py module
   along with the chat-settings key constants; routes/rag.py
   now re-imports it under the same name. Same behaviour, no
   cycle, one source of truth for the resolution logic.

3. core/rag/bm25.py:rebuild_index — call delete_scope before saving
   the new index so stale files from a previous build (or a
   bm25s naming change) never coexist with current files. The
   library's save() doesn't unlink files it doesn't write.

4. routes/rag.py:_save_upload was running f.write() synchronously
   inside an async def. Switch to anyio.open_file() so each chunk
   write runs in a worker thread instead of blocking the event
   loop on multi-MB uploads. Cleanup unlink happens after the
   async-with closes the handle so Windows is happy.

Skipped one (vector_store.py:133 'hasattr query_points' redundancy)
— that comment was on the pre-rewrite Qdrant code; the file is
now sqlite-vec backed and the hasattr check is gone.
2026-05-25 16:43:39 +04:00
..
parsers [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-05-25 06:39:01 +00:00
__init__.py Studio: add RAG with hybrid search, reranker, chat integration 2026-05-23 18:46:15 +04:00
bm25.py Studio: address gemini-code-assist PR review 2026-05-25 16:43:39 +04:00
chunking.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-05-25 06:39:01 +00:00
db.py Studio: route RAG parent-process loggers through structlog 2026-05-25 15:25:11 +04:00
embeddings.py Studio: swap RAG vector store from Qdrant to sqlite-vec 2026-05-25 15:13:59 +04:00
ingestion.py Studio: swap RAG vector store from Qdrant to sqlite-vec 2026-05-25 15:13:59 +04:00
reranker.py Studio: route RAG parent-process loggers through structlog 2026-05-25 15:25:11 +04:00
retrieval.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-05-25 06:39:01 +00:00
scope.py Studio: address gemini-code-assist PR review 2026-05-25 16:43:39 +04:00
tool.py Studio: address gemini-code-assist PR review 2026-05-25 16:43:39 +04:00
vector_store.py Studio: address gemini-code-assist PR review 2026-05-25 16:43:39 +04:00