Quelltext des aktuellen Standes
<?php
declare(strict_types=1);
use OpenNIT\AI\EmbeddingClient;
return static function (): void {
test('cosine: identische Vektoren = 1', function () {
$v = [1.0, 2.0, 3.0];
assertTrue(abs(EmbeddingClient::cosine($v, $v) - 1.0) < 1e-9, 'cos(self)=1');
});
test('cosine: orthogonale Vektoren = 0', function () {
assertTrue(abs(EmbeddingClient::cosine([1, 0], [0, 1])) < 1e-9, 'orthogonal=0');
});
test('cosine: Nullvektor = 0 (kein DivByZero)', function () {
assertSame(0.0, EmbeddingClient::cosine([0, 0, 0], [1, 2, 3]));
});
test('fromConfig: Anthropic ohne Embeddings = null', function () {
assertSame(null, EmbeddingClient::fromConfig(['provider' => 'anthropic'], 'key'));
});
test('fromConfig: lokal ohne Modell = null', function () {
assertSame(null, EmbeddingClient::fromConfig(['provider' => 'openai_compatible', 'custom_base_url' => 'http://x/v1'], 'key'));
});
};