8 Commits

Author SHA1 Message Date
yangdx
be744a28a7 Update Postgres tests for keyset pagination and API changes
- Use check_table_exists DB method
- Update mocks for keyset pagination
- Enforce error on dimension mismatch
- Remove deprecated module patches
- Verify workspace migration isolation
2025-12-21 18:37:28 +08:00
yangdx
ff19a67feb Add model_suffix argument to Qdrant tests
- Pass suffix to dimension tests
- Add explicit suffix to safety tests
- Test empty suffix scenario
- Update collection init calls
2025-12-21 02:16:47 +08:00
yangdx
1c083c6699 Remove redundant pytest.mark.asyncio decorators
- Remove explicit asyncio markers
- Clean up unused imports in tests
2025-12-19 16:00:37 +08:00
yangdx
a3b33bbc3c Remove E2E tests and update migration unit tests
- Delete E2E workflows and test files
- Remove multi-model demo example
- Update Postgres migration unit tests
- Enforce workspace requirement in tests
- Fix dimension mismatch test mocks
2025-12-19 15:20:32 +08:00
yangdx
bf618fc976 Refactor Qdrant setup and migration logic
- Validate dimensions before migration
- Require namespace and workspace args
- Raise error on vector size mismatch
- Simplify collection initialization flow
- Update tests for strict checks
2025-12-19 10:45:18 +08:00
BukeLy
3b8a1e64b7 style: apply ruff formatting fixes to test files
Apply ruff-format fixes to 6 test files to pass pre-commit checks:
- test_dimension_mismatch.py
- test_e2e_multi_instance.py
- test_no_model_suffix_safety.py
- test_postgres_migration.py
- test_unified_lock_safety.py
- test_workspace_migration_isolation.py

Changes are primarily assert statement reformatting to match ruff style guide.
2025-11-23 16:59:02 +08:00
BukeLy
e2d68adff9 style: apply ruff formatting to test files 2025-11-23 16:45:50 +08:00
BukeLy
f69cf9bcd6 fix: prevent vector dimension mismatch crashes and data loss on no-suffix restarts
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
2025-11-23 15:44:07 +08:00