Skip to content

Commit d016af3

Browse files
committed
Combine base interfaces in store component
1 parent 28d7690 commit d016af3

File tree

25 files changed

+79
-98
lines changed

25 files changed

+79
-98
lines changed

src/agent/src/Memory/EmbeddingProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\AI\Platform\Message\UserMessage;
1919
use Symfony\AI\Platform\Model;
2020
use Symfony\AI\Platform\PlatformInterface;
21-
use Symfony\AI\Store\VectorStoreInterface;
21+
use Symfony\AI\Store\StoreInterface;
2222

2323
/**
2424
* @author Denis Zunke <[email protected]>
@@ -28,7 +28,7 @@
2828
public function __construct(
2929
private PlatformInterface $platform,
3030
private Model $model,
31-
private VectorStoreInterface $vectorStore,
31+
private StoreInterface $vectorStore,
3232
) {
3333
}
3434

src/agent/src/Toolbox/Tool/SimilaritySearch.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\AI\Platform\Model;
1616
use Symfony\AI\Platform\PlatformInterface;
1717
use Symfony\AI\Store\Document\VectorDocument;
18-
use Symfony\AI\Store\VectorStoreInterface;
18+
use Symfony\AI\Store\StoreInterface;
1919

2020
/**
2121
* @author Christopher Hertel <[email protected]>
@@ -31,7 +31,7 @@ final class SimilaritySearch
3131
public function __construct(
3232
private readonly PlatformInterface $platform,
3333
private readonly Model $model,
34-
private readonly VectorStoreInterface $vectorStore,
34+
private readonly StoreInterface $store,
3535
) {
3636
}
3737

@@ -41,7 +41,7 @@ public function __construct(
4141
public function __invoke(string $searchTerm): string
4242
{
4343
$vectors = $this->platform->invoke($this->model, $searchTerm)->asVectors();
44-
$this->usedDocuments = $this->vectorStore->query($vectors[0]);
44+
$this->usedDocuments = $this->store->query($vectors[0]);
4545

4646
if ([] === $this->usedDocuments) {
4747
return 'No results found';

src/agent/tests/Memory/EmbeddingProviderTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
use Symfony\AI\Platform\Result\ResultPromise;
2828
use Symfony\AI\Platform\Result\VectorResult;
2929
use Symfony\AI\Platform\Vector\Vector;
30-
use Symfony\AI\Store\VectorStoreInterface;
30+
use Symfony\AI\Store\StoreInterface;
3131

3232
#[UsesClass(Text::class)]
3333
#[UsesClass(ImageUrl::class)]
3434
#[UsesClass(Message::class)]
3535
#[UsesClass(Input::class)]
3636
#[UsesClass(MessageBag::class)]
37-
#[UsesClass(VectorStoreInterface::class)]
37+
#[UsesClass(StoreInterface::class)]
3838
#[UsesClass(Model::class)]
3939
#[UsesClass(PlatformInterface::class)]
4040
#[CoversClass(EmbeddingProvider::class)]
@@ -46,13 +46,13 @@ public function testItIsDoingNothingWithEmptyMessageBag()
4646
$platform = $this->createMock(PlatformInterface::class);
4747
$platform->expects($this->never())->method('invoke');
4848

49-
$vectorStore = $this->createMock(VectorStoreInterface::class);
50-
$vectorStore->expects($this->never())->method('query');
49+
$store = $this->createMock(StoreInterface::class);
50+
$store->expects($this->never())->method('query');
5151

5252
$embeddingProvider = new EmbeddingProvider(
5353
$platform,
5454
$this->createStub(Model::class),
55-
$vectorStore,
55+
$store,
5656
);
5757

5858
$embeddingProvider->loadMemory(new Input(
@@ -67,13 +67,13 @@ public function testItIsDoingNothingWithoutUserMessageInBag()
6767
$platform = $this->createMock(PlatformInterface::class);
6868
$platform->expects($this->never())->method('invoke');
6969

70-
$vectorStore = $this->createMock(VectorStoreInterface::class);
71-
$vectorStore->expects($this->never())->method('query');
70+
$store = $this->createMock(StoreInterface::class);
71+
$store->expects($this->never())->method('query');
7272

7373
$embeddingProvider = new EmbeddingProvider(
7474
$platform,
7575
$this->createStub(Model::class),
76-
$vectorStore,
76+
$store,
7777
);
7878

7979
$embeddingProvider->loadMemory(new Input(
@@ -88,13 +88,13 @@ public function testItIsDoingNothingWhenUserMessageHasNoTextContent()
8888
$platform = $this->createMock(PlatformInterface::class);
8989
$platform->expects($this->never())->method('invoke');
9090

91-
$vectorStore = $this->createMock(VectorStoreInterface::class);
92-
$vectorStore->expects($this->never())->method('query');
91+
$store = $this->createMock(StoreInterface::class);
92+
$store->expects($this->never())->method('query');
9393

9494
$embeddingProvider = new EmbeddingProvider(
9595
$platform,
9696
$this->createStub(Model::class),
97-
$vectorStore,
97+
$store,
9898
);
9999

100100
$embeddingProvider->loadMemory(new Input(
@@ -117,16 +117,16 @@ public function testItIsNotCreatingMemoryWhenNoVectorsFound()
117117
->method('invoke')
118118
->willReturn($resultPromise);
119119

120-
$vectorStore = $this->createMock(VectorStoreInterface::class);
121-
$vectorStore->expects($this->once())
120+
$store = $this->createMock(StoreInterface::class);
121+
$store->expects($this->once())
122122
->method('query')
123123
->with($vector)
124124
->willReturn([]);
125125

126126
$embeddingProvider = new EmbeddingProvider(
127127
$platform,
128128
$this->createStub(Model::class),
129-
$vectorStore,
129+
$store,
130130
);
131131

132132
$memory = $embeddingProvider->loadMemory(new Input(
@@ -151,8 +151,8 @@ public function testItIsCreatingMemoryWithFoundVectors()
151151
->method('invoke')
152152
->willReturn($resultPromise);
153153

154-
$vectorStore = $this->createMock(VectorStoreInterface::class);
155-
$vectorStore->expects($this->once())
154+
$store = $this->createMock(StoreInterface::class);
155+
$store->expects($this->once())
156156
->method('query')
157157
->with($vector)
158158
->willReturn([
@@ -163,7 +163,7 @@ public function testItIsCreatingMemoryWithFoundVectors()
163163
$embeddingProvider = new EmbeddingProvider(
164164
$platform,
165165
$this->createStub(Model::class),
166-
$vectorStore,
166+
$store,
167167
);
168168

169169
$memory = $embeddingProvider->loadMemory(new Input(

src/agent/tests/Toolbox/Tool/SimilaritySearchTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\AI\Platform\Vector\Vector;
2323
use Symfony\AI\Store\Document\Metadata;
2424
use Symfony\AI\Store\Document\VectorDocument;
25-
use Symfony\AI\Store\VectorStoreInterface;
25+
use Symfony\AI\Store\StoreInterface;
2626
use Symfony\Component\Uid\Uuid;
2727

2828
#[CoversClass(SimilaritySearch::class)]
@@ -57,14 +57,14 @@ public function testSearchWithResults()
5757
->with($this->isInstanceOf(Model::class), $searchTerm)
5858
->willReturn($resultPromise);
5959

60-
$vectorStore = $this->createMock(VectorStoreInterface::class);
61-
$vectorStore->expects($this->once())
60+
$store = $this->createMock(StoreInterface::class);
61+
$store->expects($this->once())
6262
->method('query')
6363
->with($vector)
6464
->willReturn([$document1, $document2]);
6565

6666
$model = new Model('test-model');
67-
$similaritySearch = new SimilaritySearch($platform, $model, $vectorStore);
67+
$similaritySearch = new SimilaritySearch($platform, $model, $store);
6868

6969
$result = $similaritySearch($searchTerm);
7070

@@ -90,14 +90,14 @@ public function testSearchWithoutResults()
9090
->with($this->isInstanceOf(Model::class), $searchTerm)
9191
->willReturn($resultPromise);
9292

93-
$vectorStore = $this->createMock(VectorStoreInterface::class);
94-
$vectorStore->expects($this->once())
93+
$store = $this->createMock(StoreInterface::class);
94+
$store->expects($this->once())
9595
->method('query')
9696
->with($vector)
9797
->willReturn([]);
9898

9999
$model = new Model('test-model');
100-
$similaritySearch = new SimilaritySearch($platform, $model, $vectorStore);
100+
$similaritySearch = new SimilaritySearch($platform, $model, $store);
101101

102102
$result = $similaritySearch($searchTerm);
103103

@@ -129,14 +129,14 @@ public function testSearchWithSingleResult()
129129
->with($this->isInstanceOf(Model::class), $searchTerm)
130130
->willReturn($resultPromise);
131131

132-
$vectorStore = $this->createMock(VectorStoreInterface::class);
133-
$vectorStore->expects($this->once())
132+
$store = $this->createMock(StoreInterface::class);
133+
$store->expects($this->once())
134134
->method('query')
135135
->with($vector)
136136
->willReturn([$document]);
137137

138138
$model = new Model('test-model');
139-
$similaritySearch = new SimilaritySearch($platform, $model, $vectorStore);
139+
$similaritySearch = new SimilaritySearch($platform, $model, $store);
140140

141141
$result = $similaritySearch($searchTerm);
142142

src/ai-bundle/src/AiBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
use Symfony\AI\Store\Indexer;
5555
use Symfony\AI\Store\InMemoryStore;
5656
use Symfony\AI\Store\StoreInterface;
57-
use Symfony\AI\Store\VectorStoreInterface;
5857
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
5958
use Symfony\Component\DependencyInjection\Attribute\Target;
6059
use Symfony\Component\DependencyInjection\ChildDefinition;
@@ -114,7 +113,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
114113
}
115114
$stores = array_keys($builder->findTaggedServiceIds('ai.store'));
116115
if (1 === \count($stores)) {
117-
$builder->setAlias(VectorStoreInterface::class, reset($stores));
118116
$builder->setAlias(StoreInterface::class, reset($stores));
119117
}
120118

src/store/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ CHANGELOG
55
---
66

77
* Add core store interfaces:
8-
- `StoreInterface` for basic document storage
9-
- `VectorStoreInterface` extending with similarity search capabilities
8+
- `StoreInterface` for storing and querying document stores
109
- `InitializableStoreInterface` for stores requiring initialization
1110
* Add document types:
1211
- `TextDocument` for raw text with UUID, content, and metadata

src/store/doc/index.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,14 @@ Supported Stores
7878
Implementing a Bridge
7979
---------------------
8080

81-
The main extension points of the Store component are
82-
83-
* ``Symfony\AI\Store\StoreInterface`` - Takes care of adding documents to the store.
84-
* ``Symfony\AI\Store\VectorStoreInterface`` - Takes care of querying the store for documents.
81+
The main extension points of the Store component is the ``Symfony\AI\Store\StoreInterface``, that defines the methods
82+
for adding vectorized documents to the store, and querying the store for documents with a vector.
8583

8684
This leads to a store implementing two methods::
8785

8886
use Symfony\AI\Store\StoreInterface;
89-
use Symfony\AI\Store\VectorStoreInterface;
9087

91-
class MyStore implements StoreInterface, VectorStoreInterface
88+
class MyStore implements StoreInterface
9289
{
9390
public function add(VectorDocument ...$documents): void
9491
{
@@ -98,7 +95,7 @@ This leads to a store implementing two methods::
9895
public function query(Vector $vector, array $options = []): array
9996
{
10097
// Implementation to query the store for documents
101-
return [];
98+
return $documents;
10299
}
103100
}
104101

src/store/src/Bridge/Azure/SearchStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\AI\Platform\Vector\Vector;
1616
use Symfony\AI\Store\Document\Metadata;
1717
use Symfony\AI\Store\Document\VectorDocument;
18-
use Symfony\AI\Store\VectorStoreInterface;
18+
use Symfony\AI\Store\StoreInterface;
1919
use Symfony\Component\Uid\Uuid;
2020
use Symfony\Contracts\HttpClient\HttpClientInterface;
2121

2222
/**
2323
* @author Christopher Hertel <[email protected]>
2424
*/
25-
final readonly class SearchStore implements VectorStoreInterface
25+
final readonly class SearchStore implements StoreInterface
2626
{
2727
/**
2828
* @param string $vectorFieldName The name of the field int the index that contains the vector

src/store/src/Bridge/ChromaDb/Store.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
use Symfony\AI\Store\Document\Metadata;
1717
use Symfony\AI\Store\Document\VectorDocument;
1818
use Symfony\AI\Store\Exception\RuntimeException;
19-
use Symfony\AI\Store\VectorStoreInterface;
19+
use Symfony\AI\Store\StoreInterface;
2020
use Symfony\Component\Uid\Uuid;
2121

2222
/**
2323
* @author Christopher Hertel <[email protected]>
2424
*/
25-
final readonly class Store implements VectorStoreInterface
25+
final readonly class Store implements StoreInterface
2626
{
2727
public function __construct(
2828
private Client $client,

src/store/src/Bridge/ClickHouse/Store.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
use Symfony\AI\Store\Document\VectorDocument;
1818
use Symfony\AI\Store\Exception\RuntimeException;
1919
use Symfony\AI\Store\InitializableStoreInterface;
20-
use Symfony\AI\Store\VectorStoreInterface;
20+
use Symfony\AI\Store\StoreInterface;
2121
use Symfony\Component\Uid\Uuid;
2222
use Symfony\Contracts\HttpClient\HttpClientInterface;
2323
use Symfony\Contracts\HttpClient\ResponseInterface;
2424

2525
/**
2626
* @author Grégoire Pineau <[email protected]>
2727
*/
28-
class Store implements VectorStoreInterface, InitializableStoreInterface
28+
class Store implements StoreInterface, InitializableStoreInterface
2929
{
3030
public function __construct(
3131
private readonly HttpClientInterface $httpClient,

0 commit comments

Comments
 (0)