-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStoreFactory.php
More file actions
49 lines (42 loc) · 1.46 KB
/
Copy pathStoreFactory.php
File metadata and controls
49 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\AI\Store\Bridge\Postgres;
use Doctrine\DBAL\Connection;
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
/**
* @author Guillaume Loulier <personal@guillaumeloulier.fr>
*/
final class StoreFactory
{
public static function createStoreFromPdo(
\PDO $connection,
string $tableName,
string $vectorFieldName = 'embedding',
Distance $distance = Distance::L2,
string $lang = 'english',
): ManagedStoreInterface&StoreInterface {
return new Store($connection, $tableName, $vectorFieldName, $distance, $lang);
}
public static function createStoreFromDbal(
Connection $connection,
string $tableName,
string $vectorFieldName = 'embedding',
Distance $distance = Distance::L2,
string $lang = 'english',
): ManagedStoreInterface&StoreInterface {
$pdo = $connection->getNativeConnection();
if (!$pdo instanceof \PDO) {
throw new InvalidArgumentException('Only DBAL connections using PDO driver are supported.');
}
return static::createStoreFromPdo($pdo, $tableName, $vectorFieldName, $distance, $lang);
}
}