From f3d823b7566f44dbb64b0d3a72fc9bb706001f27 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 27 Jun 2026 22:41:43 -0400 Subject: [PATCH] fix(rag): use _get_chromadb() in dim check to avoid NameError The dim check in _validate_collection_dim_result references `chromadb` which is a local variable in _init_vector_store_result (not in scope for the dim check method). This causes a NameError when the dim check fires. The fix calls _get_chromadb() to get the chromadb reference (consistent with _init_vector_store_result). The test mock sets _get_chromadb.return_value to (mock_chroma, mock_settings), so the new PersistentClient is the same mock and the test assertions work. Fixes the regression introduced by 24e93a75 (which changed the dim check from delete_collection to shutil.rmtree + new PersistentClient without updating the chromadb reference scope). --- src/rag_engine.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rag_engine.py b/src/rag_engine.py index 350b0130..f90523e7 100644 --- a/src/rag_engine.py +++ b/src/rag_engine.py @@ -204,6 +204,10 @@ class RAGEngine: db_path = os.path.abspath(os.path.join(self.base_dir, ".slop_cache", f"chroma_{self.collection.name}")) if os.path.exists(db_path): shutil.rmtree(db_path, ignore_errors=True) + chroma_module = _get_chromadb() + if chroma_module is None: + return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.CONFIG, message="chromadb is not installed", source="rag._validate_collection_dim")]) + chromadb, _ = chroma_module self.client = chromadb.PersistentClient(path=os.path.dirname(db_path)) self.collection = self.client.get_or_create_collection(name=self.collection.name) return Result(data=None)