Files
materio-d9/web/modules/custom/materio_ai/src/Embedding/EmbeddingClientInterface.php
T
bachirandClaude Opus 5.5 6d8c64c94f 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
2026-11-17 18:26:19 +01:00

55 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Drupal\materio_ai\Embedding;
/**
* Turns texts into vectors with the embedding model.
*/
interface EmbeddingClientInterface {
/**
* Returns the vector of one text.
*
* @param string $text
* The text to vectorize.
* @param float|null $timeout
* Longest wait in seconds; the configured timeout by default. A search
* passes a short one (search_timeout, H8).
*
* @return float[]
* A vector of getDimension() values.
*
* @throws \Drupal\materio_ai\Exception\EmbeddingException
*/
public function embed(string $text, ?float $timeout = NULL): array;
/**
* Returns the vectors of several texts, in the same order and with the same keys.
*
* Texts are sent one per call: Ollama gains nothing from batches on CPU
* (measured in M2).
*
* @param string[] $texts
* The texts to vectorize.
*
* @return float[][]
* The vectors, keyed like $texts.
*
* @throws \Drupal\materio_ai\Exception\EmbeddingException
*/
public function embedMultiple(array $texts): array;
/**
* Returns the model name, stored with each vector.
*/
public function getModel(): string;
/**
* Returns the expected vector dimension.
*/
public function getDimension(): int;
}