Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Cache/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function query(Vector $vector, array $options = []): iterable
yield from $this->distanceCalculator->calculate($vectorDocuments, $vector, $options['maxItems'] ?? null);
}

public function drop(): void
public function drop(array $options = []): void
{
$this->cache->clear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/ClickHouse/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function setup(array $options = []): void
$this->execute('POST', $sql);
}

public function drop(): void
public function drop(array $options = []): void
{
$this->execute('POST', 'DROP TABLE IF EXISTS {{ table }}');
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Cloudflare/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setup(array $options = []): void
]);
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('DELETE', \sprintf('vectorize/v2/indexes/%s', $this->index));
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/ManticoreSearch/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setup(array $options = []): void
));
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('cli', \sprintf('DROP TABLE %s', $this->table));
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/MariaDb/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function setup(array $options = []): void
);
}

public function drop(): void
public function drop(array $options = []): void
{
$this->connection->exec(\sprintf('DROP TABLE IF EXISTS %s', $this->tableName));
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Meilisearch/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('DELETE', \sprintf('indexes/%s', $this->indexName), []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Milvus/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('POST', 'v2/vectordb/databases/drop', [
'dbName' => $this->database,
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/MongoDb/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function setup(array $options = []): void
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->getCollection()->drop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Neo4j/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('POST', \sprintf('db/%s/query/v2', $this->databaseName), [
'statement' => 'MATCH (n) DETACH DELETE n',
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/OpenSearch/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function setup(array $options = []): void
]);
}

public function drop(): void
public function drop(array $options = []): void
{
$indexExistResponse = $this->httpClient->request('HEAD', \sprintf('%s/%s', $this->endpoint, $this->indexName));

Expand Down
33 changes: 32 additions & 1 deletion src/store/src/Bridge/Pinecone/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;

/**
* @author Christopher Hertel <[email protected]>
*/
final class Store implements StoreInterface
final class Store implements StoreInterface, ManagedStoreInterface
{
/**
* @param array<string, mixed> $filter
Expand All @@ -35,6 +37,23 @@ public function __construct(
) {
}

public function setup(array $options = []): void
{
if (false === isset($options['indexName']) || false === isset($options['dimension'])) {
throw new InvalidArgumentException('No supported options.');
}

$this->pinecone
->control()
->index($options['indexName'])
->createServerless(
$options['dimension'],
$options['metric'] ?? null,
$options['cloud'] ?? null,
$options['region'] ?? null,
);
}

public function add(VectorDocument ...$documents): void
{
$vectors = [];
Expand Down Expand Up @@ -73,6 +92,18 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(array $options = []): void
{
if (false === isset($options['indexName'])) {
throw new InvalidArgumentException('No supported options.');
}

$this->pinecone
->control()
->index($options['indexName'])
->delete();
}

private function getVectors(): VectorResource
{
return $this->pinecone->data()->vectors();
Expand Down
72 changes: 72 additions & 0 deletions src/store/src/Bridge/Pinecone/Tests/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Probots\Pinecone\Client;
use Probots\Pinecone\Resources\Control\IndexResource;
use Probots\Pinecone\Resources\ControlResource;
use Probots\Pinecone\Resources\Data\VectorResource;
use Probots\Pinecone\Resources\DataResource;
use Saloon\Http\Response;
Expand All @@ -24,6 +26,76 @@

final class StoreTest extends TestCase
{
public function testStoreCantSetupWithInvalidOptions()
{
$pinecone = $this->createMock(Client::class);
$store = new Store($pinecone);

$this->expectException(\InvalidArgumentException::class);

$store->setup();
}

public function testStoreCanSetup()
{
$pinecone = $this->createMock(Client::class);
$indexResource = $this->createMock(IndexResource::class);
$controlResource = $this->createMock(ControlResource::class);

$pinecone->expects($this->once())
->method('control')
->willReturn($controlResource);

$controlResource->expects($this->once())
->method('index')
->with('test-index')
->willReturn($indexResource);

$indexResource->expects($this->once())
->method('createServerless')
->with(1536, null, null, null);

$store = new Store($pinecone);
$store->setup([
'indexName' => 'test-index',
'dimension' => 1536,
]);
}

public function testStoreCantDropWithInvalidOptions()
{
$pinecone = $this->createMock(Client::class);
$store = new Store($pinecone);

$this->expectException(\InvalidArgumentException::class);

$store->drop();
}

public function testStoreCanDrop()
{
$pinecone = $this->createMock(Client::class);
$indexResource = $this->createMock(IndexResource::class);
$controlResource = $this->createMock(ControlResource::class);

$pinecone->expects($this->once())
->method('control')
->willReturn($controlResource);

$controlResource->expects($this->once())
->method('index')
->with('test-index')
->willReturn($indexResource);

$indexResource->expects($this->once())
->method('delete');

$store = new Store($pinecone);
$store->drop([
'indexName' => 'test-index',
]);
}

public function testAddSingleDocument()
{
$vectorResource = $this->createMock(VectorResource::class);
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Postgres/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setup(array $options = []): void
);
}

public function drop(): void
public function drop(array $options = []): void
{
$this->connection->exec(\sprintf('DROP TABLE IF EXISTS %s', $this->tableName));
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Qdrant/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('DELETE', \sprintf('collections/%s', $this->collectionName));
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Redis/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function setup(array $options = []): void
$this->redis->clearLastError();
}

public function drop(): void
public function drop(array $options = []): void
{
try {
$this->redis->rawCommand('FT.DROPINDEX', $this->indexName);
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/SurrealDb/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->authenticate();

Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Typesense/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('DELETE', \sprintf('collections/%s', $this->collection), []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Bridge/Weaviate/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function query(Vector $vector, array $options = []): iterable
}
}

public function drop(): void
public function drop(array $options = []): void
{
$this->request('DELETE', \sprintf('v1/schema/%s', $this->collection), []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/InMemory/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function query(Vector $vector, array $options = []): iterable
yield from $this->distanceCalculator->calculate($documents, $vector, $options['maxItems'] ?? null);
}

public function drop(): void
public function drop(array $options = []): void
{
$this->documents = [];
}
Expand Down
5 changes: 4 additions & 1 deletion src/store/src/ManagedStoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ interface ManagedStoreInterface
*/
public function setup(array $options = []): void;

public function drop(): void;
/**
* @param array<mixed> $options
*/
public function drop(array $options = []): void;
}