[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.
Python aifaissgpt-osslangchainllama-indexllmlocalstorageoffline-firstollamaprivacypythonragretrieval-augmented-generationvector-databasevector-searchvectors
fix: recover from corrupt sync snapshots (#410)
Hongzhu Yi7d1eb7be8ae2
diff --git a/packages/leann-core/src/leann/sync.py b/packages/leann-core/src/leann/sync.pyindex ef5a116..52f4897 100644--- a/packages/leann-core/src/leann/sync.py+++ b/packages/leann-core/src/leann/sync.py@@ -299,3 +299,13 @@ class FileSynchronizer:self.tree = pickle.load(f)except FileNotFoundError:self.tree = None+ except (+ OSError,+ EOFError,+ pickle.UnpicklingError,+ AttributeError,+ ImportError,+ IndexError,+ ) as exc:+ logger.warning("Cannot load sync snapshot %s: %s", self.snapshot_path, exc)+ self.tree = Nonediff --git a/tests/test_sync.py b/tests/test_sync.pyindex 03c0015..c8c62ce 100644--- a/tests/test_sync.py+++ b/tests/test_sync.py@@ -56,6 +56,24 @@ class TestMerkleTreeCompare(unittest.TestCase):class TestFileSynchronizer(unittest.TestCase):+ def test_corrupt_snapshot_is_rebuilt(self):+ with tempfile.TemporaryDirectory() as temp_dir:+ root = Path(temp_dir)+ document = root / "file.txt"+ document.write_text("hello world", encoding="utf-8")+ snapshot = root / "sync.pickle"+ snapshot.write_bytes(b"truncated pickle")++ synchronizer = FileSynchronizer(+ root_dir=temp_dir,+ snapshot_path=str(snapshot),+ )++ added, removed, modified = synchronizer.detect_changes()+ assert added == [str(document.resolve())]+ assert removed == []+ assert modified == []+def test_generate_file_hashes(self):with tempfile.TemporaryDirectory() as temp_dir:file_path = Path(temp_dir) / "file.txt"