Skip to content

Commit f4d9d5e

Browse files
committed
bug #1695 [Store][Qdrant] Improvement on ScopingHttpClient support (Guikingone)
This PR was merged into the main branch. Discussion ---------- [Store][Qdrant] Improvement on `ScopingHttpClient` support | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Docs? | no | Issues | -- | License | MIT Commits ------- 6419c2b refactor(store): Qdrant improved on ScopingHttpClient
2 parents 9838ae0 + 6419c2b commit f4d9d5e

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

src/store/src/Bridge/Qdrant/StoreFactory.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\AI\Store\Bridge\Qdrant;
1313

14-
use Symfony\AI\Store\Exception\InvalidArgumentException;
1514
use Symfony\AI\Store\ManagedStoreInterface;
1615
use Symfony\AI\Store\StoreInterface;
1716
use Symfony\Component\HttpClient\HttpClient;
@@ -32,12 +31,6 @@ public static function create(
3231
string $embeddingsDistance = 'Cosine',
3332
bool $async = false,
3433
): StoreInterface&ManagedStoreInterface {
35-
$httpClient = $httpClient instanceof ScopingHttpClient ? $httpClient : HttpClient::create();
36-
37-
if (!$httpClient instanceof ScopingHttpClient && (null === $endpoint || null === $apiKey)) {
38-
throw new InvalidArgumentException(\sprintf('The HttpClient must be an instance of "%s" or both "endpoint" and "apiKey" must be provided.', ScopingHttpClient::class));
39-
}
40-
4134
if (null !== $endpoint) {
4235
$defaultOptions = [];
4336
if (null !== $apiKey) {
@@ -46,7 +39,7 @@ public static function create(
4639
];
4740
}
4841

49-
$httpClient = ScopingHttpClient::forBaseUri($httpClient, $endpoint, $defaultOptions);
42+
$httpClient = ScopingHttpClient::forBaseUri($httpClient ?? HttpClient::create(), $endpoint, $defaultOptions);
5043
}
5144

5245
return new Store($httpClient, $collectionName, $embeddingsDimension, $embeddingsDistance, $async);

src/store/src/Bridge/Qdrant/Tests/StoreFactoryTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,11 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\AI\Store\Bridge\Qdrant\Store;
1616
use Symfony\AI\Store\Bridge\Qdrant\StoreFactory;
17-
use Symfony\AI\Store\Exception\InvalidArgumentException;
1817
use Symfony\Component\HttpClient\HttpClient;
1918
use Symfony\Component\HttpClient\ScopingHttpClient;
2019

2120
final class StoreFactoryTest extends TestCase
2221
{
23-
public function testStoreCannotBeCreatedWithoutScopingHttpClientAndRequiredInfos()
24-
{
25-
$this->expectException(InvalidArgumentException::class);
26-
$this->expectExceptionMessage(\sprintf('The HttpClient must be an instance of "%s" or both "endpoint" and "apiKey" must be provided.', ScopingHttpClient::class));
27-
$this->expectExceptionCode(0);
28-
StoreFactory::create('foo', httpClient: HttpClient::create());
29-
}
30-
3122
public function testStoreCanBeCreatedWithHttpClientAndRequiredInfos()
3223
{
3324
$store = StoreFactory::create('foo', 'http://127.0.0.1:6333', 'bar');

0 commit comments

Comments
 (0)