38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Recommendations\VectorSimilarity;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Factory to resolve the configured VectorAdapterInterface implementation.
|
|
*/
|
|
final class VectorAdapterFactory
|
|
{
|
|
/**
|
|
* @return VectorAdapterInterface|null null when vector similarity is disabled
|
|
*/
|
|
public static function make(): ?VectorAdapterInterface
|
|
{
|
|
if (! (bool) config('recommendations.similarity.vector_enabled', false)) {
|
|
return null;
|
|
}
|
|
|
|
$adapter = (string) config('recommendations.similarity.vector_adapter', 'pgvector');
|
|
|
|
return match ($adapter) {
|
|
'pgvector' => new PgvectorAdapter(),
|
|
'pinecone' => new PineconeAdapter(),
|
|
default => self::fallback($adapter),
|
|
};
|
|
}
|
|
|
|
private static function fallback(string $adapter): PgvectorAdapter
|
|
{
|
|
Log::warning("[VectorAdapterFactory] Unknown adapter '{$adapter}', falling back to pgvector.");
|
|
return new PgvectorAdapter();
|
|
}
|
|
}
|