materio_ai: cached search vectors, 1 s delay, pause and cron warm-up (H8)

- QueryEmbedder: vector of a search phrase cached 30 days (cache bin
  materio_ai), model given search_timeout seconds (1 by default, new
  setting, update 11001), left alone 60 s after a failure
  (ModelPausedException, not logged).
- NeighbourSearch honours the enabled setting: the search called the model
  even when materio_ai was switched off.
- materio_ai_cron() loads the model with the normal timeout: after a
  restart, loading (2.9 s) exceeds the search delay and Ollama drops it,
  so searches alone would never load it. Ultimate cron job exported.
- On any model failure the search answers with the keyword results only.
- QueryEmbedderTest: cache, delay, pause, cache during the pause, warm-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
This commit is contained in:
2026-11-17 18:26:19 +01:00
co-authored by Claude Opus 5.5
parent a656427aec
commit 6d8c64c94f
15 changed files with 379 additions and 13 deletions
@@ -7,6 +7,7 @@ use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Component\Utility\Unicode;
use Drupal\materio_ai\Exception\ModelPausedException;
use Drupal\materio_sapi\KeywordText;
use Drupal\materio_sapi\RankFusion;
use Drupal\search_api\Entity\Index;
@@ -165,8 +166,9 @@ class Base extends ControllerBase {
* Nodes closest in meaning to the phrase (materio_ai, Solr kNN).
*
* Not for a term chosen in the autocomplete (direct search) nor without
* the materio_ai service. On a model or Solr error, the keyword results
* stand alone (delay and cache in H8).
* the materio_ai service. On a model or Solr error, or past the delay of
* QueryEmbedder (1 s), the keyword results stand alone, with no message:
* the search answers as before H5.
*
* @return array<int, float>
* Scores keyed by nid, best first.
@@ -184,7 +186,10 @@ class Base extends ControllerBase {
return \Drupal::service('materio_ai.neighbour_search')->search($phrase, $lang, self::KNN_LIMIT);
}
catch (\Throwable $e) {
\Drupal::logger('materio_sapi')->warning('Neighbour search failed, keyword results only: @message', ['@message' => $e->getMessage()]);
// Paused model: its failure was logged when it happened.
if (!$e instanceof ModelPausedException) {
\Drupal::logger('materio_sapi')->warning('Neighbour search failed, keyword results only: @message', ['@message' => $e->getMessage()]);
}
return [];
}
}