feat(retrieval): preload Qwen models during setup
CI / Capabilities and shell quality (push) Successful in 11s
CI / Python tests and compilation (push) Successful in 11s
CI / PowerShell tests on Ubuntu (push) Successful in 28s
CI / CI configuration security checks (push) Successful in 3s
CI / Build and inspect generated packages (push) Successful in 6s
CI / Qwen retrieval integration (push) Successful in 14m20s
CI / Bash integration and installation guards (push) Successful in 16s
CI / Installed client configuration smoke tests (push) Successful in 13s

This commit is contained in:
fraujulian committed 2026-09-18 15:47:42 +02:00
1 parent b5123df02a
commit 49be8edbec
4 files changed
+60 -3

No files matched your search

+19
View File
@@ -82,6 +82,25 @@ class RetrievalServerTests(unittest.TestCase):
with patch.dict('sys.modules', torch=SimpleNamespace(cuda=SimpleNamespace(is_available=lambda: False))):
self.assertEqual(MODULE.preferred_device(), 'cpu')
def test_preload_models_warms_embedding_and_reranking_from_model_cache(self):
with TemporaryDirectory() as temporary:
cache = Path(temporary) / 'model-cache'
calls = []
encoder = SimpleNamespace(encode=lambda values, **kwargs: calls.append(('encode', values, kwargs)) or [embedding()])
reranker = SimpleNamespace(predict=lambda pairs, **kwargs: calls.append(('predict', pairs, kwargs)) or [0.0])
with patch.object(MODULE, 'shared_encoder', return_value=encoder), \
patch.object(MODULE, 'shared_reranker', return_value=reranker), \
patch.dict(os.environ, {'HF_HOME': 'other-cache'}):
getattr(MODULE, 'preload_models', lambda _: None)(cache)
self.assertEqual(str(cache.resolve()), os.environ['HF_HOME'])
self.assertTrue(cache.is_dir())
self.assertEqual([
('encode', ['Verify semantic retrieval models.'], {'prompt_name': 'query'}),
('predict', [('Verify semantic retrieval models.', 'Verify semantic retrieval models.')], {'show_progress_bar': False}),
], calls)
@unittest.skipUnless(os.environ.get('QWEN_TEST_MODEL_CACHE'), 'Set QWEN_TEST_MODEL_CACHE to run the real-model check.')
def test_real_models(self):
if not huggingface_available():
+13
View File
@@ -48,6 +48,19 @@ class SemanticRetrievalTests(unittest.TestCase):
self.assertEqual(run.call_count, 2)
self.assertNotIn('--extra-index-url', run.call_args.args[0])
def test_sync_preloads_models_after_installing_runtime(self):
with tempfile.TemporaryDirectory() as directory:
home = Path(directory) / 'home'
target = home / '.my-ai-configuration/semantic-retrieval'
python = MODULE.python_path(target / '.venv')
with patch.object(MODULE, 'ensure_runtime', return_value=python), \
patch.object(MODULE.subprocess, 'run') as run:
MODULE.sync(ROOT, home, ['codex'], True, False, False)
self.assertEqual([[
str(python), str(target / 'server.py'), 'preload', '--model-cache', str(target / 'model-cache')
]], [call.args[0] for call in run.call_args_list])
def test_summary_dry_run_omits_details_without_writes(self):
with tempfile.TemporaryDirectory() as directory:
home = Path(directory) / 'home'