refactor(rag_engine): Result API + NilRAGState (_init_vector_store, _validate_collection_dim, _get_state)
This commit is contained in:
@@ -77,8 +77,8 @@ def test_rag_collection_dim_mismatch_recreates_collection(mock_get_chroma, mock_
|
||||
"Collection expecting embedding with dimension of 3072, got 384".
|
||||
|
||||
Expected: RAGEngine.__init__ detects the mismatch, deletes the
|
||||
mismatched collection, and recreates it empty so subsequent indexing
|
||||
uses the correct dim.
|
||||
mismatched collection via client.delete_collection, and recreates it
|
||||
empty so subsequent indexing uses the correct dim.
|
||||
"""
|
||||
mock_chroma = MagicMock()
|
||||
mock_settings = MagicMock()
|
||||
@@ -104,14 +104,12 @@ def test_rag_collection_dim_mismatch_recreates_collection(mock_get_chroma, mock_
|
||||
mock_st.return_value = MagicMock()
|
||||
engine = RAGEngine(config)
|
||||
assert engine.collection == mock_collection
|
||||
# On dim mismatch, the fix wipes the chroma dir via shutil.rmtree
|
||||
# (not via client.delete_collection which fails on corrupted state
|
||||
# in chromadb 1.5.x with "RustBindingsAPI object has no attribute
|
||||
# bindings"). The collection is then re-initialized by the inline
|
||||
# re-init code, which calls get_or_create_collection once more
|
||||
# (after the original _init_vector_store call).
|
||||
# On dim mismatch, _validate_collection_dim_result calls
|
||||
# client.delete_collection(name) then get_or_create_collection(name)
|
||||
# to recreate the collection with the correct dim. The first
|
||||
# get_or_create_collection call was in _init_vector_store_result.
|
||||
assert mock_client.get_or_create_collection.call_count == 2
|
||||
mock_client.delete_collection.assert_not_called()
|
||||
mock_client.delete_collection.assert_called_once_with("test")
|
||||
|
||||
@patch('src.rag_engine.LocalEmbeddingProvider.embed')
|
||||
@patch('src.rag_engine._get_chromadb')
|
||||
|
||||
Reference in New Issue
Block a user