Skip to content

Commit fdd3fa6

Browse files
committed
[Store] Add IndexerInterface for better abstraction and testability
- Add IndexerInterface with index method for TextDocument processing - Update Indexer class to implement IndexerInterface - Update AiBundle to use IndexerInterface for dependency injection aliasing - Update demo Embedder to use IndexerInterface instead of concrete class
1 parent 38afc15 commit fdd3fa6

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

demo/src/Blog/Embedder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
use Symfony\AI\Store\Document\Metadata;
1515
use Symfony\AI\Store\Document\TextDocument;
16-
use Symfony\AI\Store\Indexer;
16+
use Symfony\AI\Store\IndexerInterface;
1717

1818
final readonly class Embedder
1919
{
2020
public function __construct(
2121
private FeedLoader $loader,
22-
private Indexer $indexer,
22+
private IndexerInterface $indexer,
2323
) {
2424
}
2525

src/ai-bundle/src/AiBundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use Symfony\AI\Store\Bridge\Weaviate\Store as WeaviateStore;
6868
use Symfony\AI\Store\Document\Vectorizer;
6969
use Symfony\AI\Store\Indexer;
70+
use Symfony\AI\Store\IndexerInterface;
7071
use Symfony\AI\Store\StoreInterface;
7172
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
7273
use Symfony\Component\DependencyInjection\Attribute\Target;
@@ -144,7 +145,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
144145
$this->processIndexerConfig($indexerName, $indexer, $builder);
145146
}
146147
if (1 === \count($config['indexer']) && isset($indexerName)) {
147-
$builder->setAlias(Indexer::class, 'ai.indexer.'.$indexerName);
148+
$builder->setAlias(IndexerInterface::class, 'ai.indexer.'.$indexerName);
148149
}
149150

150151
$builder->registerAttributeForAutoconfiguration(AsTool::class, static function (ChildDefinition $definition, AsTool $attribute): void {

src/store/src/Indexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Christopher Hertel <[email protected]>
2323
*/
24-
final readonly class Indexer
24+
final readonly class Indexer implements IndexerInterface
2525
{
2626
public function __construct(
2727
private Vectorizer $vectorizer,

src/store/src/IndexerInterface.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Store;
13+
14+
use Symfony\AI\Store\Document\TextDocument;
15+
16+
/**
17+
* Converts a collection of TextDocuments into VectorDocuments and pushes them to a store implementation.
18+
*
19+
* @author Oskar Stark <[email protected]>
20+
*/
21+
interface IndexerInterface
22+
{
23+
/**
24+
* @param TextDocument|iterable<TextDocument> $documents
25+
* @param int $chunkSize number of documents to vectorize and store in one batch
26+
*/
27+
public function index(TextDocument|iterable $documents, int $chunkSize = 50): void;
28+
}

0 commit comments

Comments
 (0)