fleet-memory/hindsight-api/tests
Nicolò Boschi 0bf85a3435
fix: improve pytorch model initialization to prevent meta tensor issues (#180)
* fix: prevent meta tensor issues when accelerate is installed without GPU

When accelerate is installed but no GPU is available, transformers can
incorrectly use lazy loading (meta tensors) which fails when
sentence-transformers tries to move the model to a device.

The fix checks hardware and installed packages to determine the right
loading strategy:
- GPU available: device=None, device_map=None (auto-detect GPU)
- No GPU + accelerate: device='cpu', device_map='cpu' (force CPU loading)
- No GPU + no accelerate: device='cpu', device_map=None (normal CPU)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

* fix: add filelock for model initialization in parallel tests

When pytest-xdist runs multiple workers in parallel, they all try to
load models from the HuggingFace cache simultaneously, causing race
conditions and intermittent meta tensor errors.

Added filelock around embeddings and cross_encoder initialization in
conftest.py, similar to how pg0 database setup is serialized. Models
are now pre-initialized in the fixture before being passed to tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

* fix: add MPS support for macOS Apple Silicon

Extend GPU detection to include Apple MPS backend in addition to CUDA.
This ensures macOS users with Apple Silicon use MPS acceleration
instead of being incorrectly routed to the CPU fallback path.
2026-01-20 14:15:51 +01:00
..
fixtures rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
__init__.py rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
conftest.py fix: improve pytorch model initialization to prevent meta tensor issues (#180) 2026-01-20 14:15:51 +01:00
test_admin_backup_restore.py feat: run db migrations offline (optionally) (#114) 2026-01-07 15:49:51 +01:00
test_agents_api.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_batch_chunking.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_causal_relations.py fix: duplicated causal relationships and token optimization (#126) 2026-01-08 14:43:48 +01:00
test_causal_relationships.py fix: duplicated causal relationships and token optimization (#126) 2026-01-08 14:43:48 +01:00
test_chunking.py improve retain performances, caching and tests 2025-12-08 18:21:56 +01:00
test_combined_scoring.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_custom_embedding_dimension.py feat: new 'worker' service (#176) 2026-01-20 10:17:56 +01:00
test_document_tracking.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_emergent_filtering.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_extensions.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_fact_extraction_analysis.py fix: misc perf improvements (#133) 2026-01-08 22:49:04 +01:00
test_fact_extraction_output_ratio.py fix: misc perf improvements (#133) 2026-01-08 22:49:04 +01:00
test_fact_extraction_quality.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_fact_ordering.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_http_api_integration.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_link_utils.py prepare for release 2025-12-03 11:52:25 +01:00
test_llm_provider.py fix: ollama structured support (#63) 2025-12-22 16:35:24 +01:00
test_llm_token_metrics.py feat: add metrics for llm call latency (#120) 2026-01-08 11:40:34 +01:00
test_llm_tools.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_load_large_batch.py feat: new 'worker' service (#176) 2026-01-20 10:17:56 +01:00
test_main_module.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_mcp_local.py feat: add local mcp server (#32) 2025-12-16 10:50:20 +01:00
test_mcp_routing.py fix(mcp): add back bank list and create_bank tools (#123) 2026-01-08 14:02:28 +01:00
test_mental_models.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_metrics.py misc: performance improvements (#140) 2026-01-09 14:47:20 +01:00
test_mpfp_retrieval.py fix: improve mpfp retrieval (#146) 2026-01-12 18:58:05 +01:00
test_multilingual.py ci: fix flak tests (#131) 2026-01-08 18:44:30 +01:00
test_observation_trends.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_observations.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_per_operation_llm_config.py feat: support different provider/models per operation (#125) 2026-01-08 14:02:57 +01:00
test_query_analyzer.py fix: ci and ui build (#9) 2025-12-03 15:47:53 +01:00
test_reflect_agent.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_retain.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_schema_isolation.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_search_trace.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_server_module.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
test_sql_schema_safety.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_tags_visibility.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
test_tei_cross_encoder.py fix: improve mpfp retrieval (#146) 2026-01-12 18:58:05 +01:00
test_temporal_ranges.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_think.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_worker.py feat: new 'worker' service (#176) 2026-01-20 10:17:56 +01:00