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).
This commit is contained in:
@@ -204,6 +204,10 @@ class RAGEngine:
|
|||||||
db_path = os.path.abspath(os.path.join(self.base_dir, ".slop_cache", f"chroma_{self.collection.name}"))
|
db_path = os.path.abspath(os.path.join(self.base_dir, ".slop_cache", f"chroma_{self.collection.name}"))
|
||||||
if os.path.exists(db_path):
|
if os.path.exists(db_path):
|
||||||
shutil.rmtree(db_path, ignore_errors=True)
|
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.client = chromadb.PersistentClient(path=os.path.dirname(db_path))
|
||||||
self.collection = self.client.get_or_create_collection(name=self.collection.name)
|
self.collection = self.client.get_or_create_collection(name=self.collection.name)
|
||||||
return Result(data=None)
|
return Result(data=None)
|
||||||
|
|||||||
Reference in New Issue
Block a user