Why this change is needed: Two critical issues were identified in Codex review of PR #2391: 1. Migration fails when legacy collections/tables use different embedding dimensions (e.g., upgrading from 1536d to 3072d models causes initialization failures) 2. When model_suffix is empty (no model_name provided), table_name equals legacy_table_name, causing Case 1 logic to delete the only table/collection on second startup How it solves it: - Added dimension compatibility checks before migration in both Qdrant and PostgreSQL - PostgreSQL uses two-method detection: pg_attribute metadata query + vector sampling fallback - When dimensions mismatch, skip migration and create new empty table/collection, preserving legacy data - Added safety check to detect when new and legacy names are identical, preventing deletion - Both backends log clear warnings about dimension mismatches and skipped migrations Impact: - lightrag/kg/qdrant_impl.py: Added dimension check (lines 254-297) and no-suffix safety (lines 163-169) - lightrag/kg/postgres_impl.py: Added dimension check with fallback (lines 2347-2410) and no-suffix safety (lines 2281-2287) - tests/test_no_model_suffix_safety.py: New test file with 4 test cases covering edge scenarios - Backward compatible: All existing scenarios continue working unchanged Testing: - All 20 tests pass (16 existing migration tests + 4 new safety tests) - E2E tests enhanced with explicit verification points for dimension mismatch scenarios - Verified graceful degradation when dimension detection fails - Code style verified with ruff and pre-commit hooks |
||
|---|---|---|
| .. | ||
| api | ||
| evaluation | ||
| kg | ||
| llm | ||
| tools | ||
| __init__.py | ||
| base.py | ||
| constants.py | ||
| exceptions.py | ||
| lightrag.py | ||
| namespace.py | ||
| operate.py | ||
| prompt.py | ||
| rerank.py | ||
| types.py | ||
| utils.py | ||
| utils_graph.py | ||