Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/store/src/Bridge/Weaviate/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\Exception\LogicException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -61,7 +60,19 @@ public function add(VectorDocument|array $documents): void

public function remove(string|array $ids, array $options = []): void
{
throw new LogicException('Method not implemented yet.');
if (\is_string($ids)) {
$ids = [$ids];
}

if ([] === $ids) {
return;
}

// Note: This implementation makes one HTTP request per ID.
// Future optimization: consider using Weaviate's batch delete API for better performance with large batches.
foreach ($ids as $id) {
$this->request('DELETE', \sprintf('v1/objects/%s', $id), []);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API supports delete in batch on /v1/batch/objects endpoint, please use it:
https://docs.weaviate.io/weaviate/api/rest#tag/batch/POST/batch/objects

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address this

}

public function query(Vector $vector, array $options = []): iterable
Expand Down
87 changes: 87 additions & 0 deletions src/store/src/Bridge/Weaviate/Tests/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,91 @@ public function testStoreCanQuery()
$this->assertCount(2, $results);
$this->assertSame(1, $httpClient->getRequestsCount());
}

public function testStoreCanRemoveSingleId()
{
$httpClient = new MockHttpClient([
new JsonMockResponse([], [
'http_code' => 204,
]),
], 'http://127.0.0.1:8080');

$store = new Store(
$httpClient,
'http://127.0.0.1:8080',
'test',
'test',
);

$store->remove('test-id-1');

$this->assertSame(1, $httpClient->getRequestsCount());
}

public function testStoreCanRemoveMultipleIds()
{
$httpClient = new MockHttpClient([
new JsonMockResponse([], [
'http_code' => 204,
]),
new JsonMockResponse([], [
'http_code' => 204,
]),
new JsonMockResponse([], [
'http_code' => 204,
]),
], 'http://127.0.0.1:8080');

$store = new Store(
$httpClient,
'http://127.0.0.1:8080',
'test',
'test',
);

$store->remove(['test-id-1', 'test-id-2', 'test-id-3']);

$this->assertSame(3, $httpClient->getRequestsCount());
}

public function testStoreCanRemoveWithEmptyArray()
{
$httpClient = new MockHttpClient([], 'http://127.0.0.1:8080');

$store = new Store(
$httpClient,
'http://127.0.0.1:8080',
'test',
'test',
);

$store->remove([]);

$this->assertSame(0, $httpClient->getRequestsCount());
}

public function testStoreCannotRemoveOnInvalidResponse()
{
$httpClient = new MockHttpClient([
new JsonMockResponse([
'error' => [
'message' => 'Object not found',
],
], [
'http_code' => 404,
]),
], 'http://127.0.0.1:8080');

$store = new Store(
$httpClient,
'http://127.0.0.1:8080',
'test',
'test',
);

$this->expectException(ClientException::class);
$this->expectExceptionMessage('HTTP 404 returned for "http://127.0.0.1:8080/v1/objects/non-existent-id".');
$this->expectExceptionCode(404);
$store->remove('non-existent-id');
}
}
Loading