Skip to content

Commit 957151a

Browse files
committed
refactor: rename Embedder to Indexer and open input to iterable (#336)
1 parent fa411a1 commit 957151a

File tree

8 files changed

+38
-38
lines changed

8 files changed

+38
-38
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,22 +396,22 @@ $response = $agent->call($messages);
396396
Symfony AI supports document embedding and similarity search using vector stores like ChromaDB, Azure AI Search, MongoDB
397397
Atlas Search, or Pinecone.
398398
399-
For populating a vector store, Symfony AI provides the service `Embedder`, which requires an instance of an
399+
For populating a vector store, Symfony AI provides the service `Indexer`, which requires an instance of an
400400
`EmbeddingsModel` and one of `StoreInterface`, and works with a collection of `Document` objects as input:
401401
402402
```php
403403
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
404404
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
405405
use Symfony\AI\Store\Bridge\Pinecone\Store;
406-
use Symfony\AI\Store\Embedder;
406+
use Symfony\AI\Store\Indexer;
407407
use Probots\Pinecone\Pinecone;
408408
409-
$embedder = new Embedder(
409+
$indexer = new Indexer(
410410
PlatformFactory::create($_ENV['OPENAI_API_KEY']),
411411
new Embeddings(),
412412
new Store(Pinecone::client($_ENV['PINECONE_API_KEY'], $_ENV['PINECONE_HOST']),
413413
);
414-
$embedder->embed($documents);
414+
$indexer->index($documents);
415415
```
416416
417417
The collection of `Document` instances is usually created by text input of your domain entities:

examples/store/mongodb-similarity-search.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\AI\Store\Bridge\MongoDB\Store;
2323
use Symfony\AI\Store\Document\Metadata;
2424
use Symfony\AI\Store\Document\TextDocument;
25-
use Symfony\AI\Store\Embedder;
25+
use Symfony\AI\Store\Indexer;
2626
use Symfony\Component\Dotenv\Dotenv;
2727
use Symfony\Component\Uid\Uuid;
2828

@@ -61,8 +61,8 @@
6161

6262
// create embeddings for documents
6363
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
64-
$embedder = new Embedder($platform, $embeddings = new Embeddings(), $store);
65-
$embedder->embed($documents);
64+
$indexer = new Indexer($platform, $embeddings = new Embeddings(), $store);
65+
$indexer->index($documents);
6666

6767
// initialize the index
6868
$store->initialize();

examples/store/pinecone-similarity-search.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\AI\Store\Bridge\Pinecone\Store;
2323
use Symfony\AI\Store\Document\Metadata;
2424
use Symfony\AI\Store\Document\TextDocument;
25-
use Symfony\AI\Store\Embedder;
25+
use Symfony\AI\Store\Indexer;
2626
use Symfony\Component\Dotenv\Dotenv;
2727
use Symfony\Component\Uid\Uuid;
2828

@@ -55,8 +55,8 @@
5555

5656
// create embeddings for documents
5757
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
58-
$embedder = new Embedder($platform, $embeddings = new Embeddings(), $store);
59-
$embedder->embed($documents);
58+
$indexer = new Indexer($platform, $embeddings = new Embeddings(), $store);
59+
$indexer->index($documents);
6060

6161
$model = new GPT(GPT::GPT_4O_MINI);
6262

src/ai-bundle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ai:
7777
# multiple collections possible per type
7878
default:
7979
collection: 'my_collection'
80-
embedder:
80+
indexer:
8181
default:
8282
# platform: 'symfony_ai.platform.anthropic'
8383
# store: 'symfony_ai.store.chroma_db.default'

src/ai-bundle/src/DependencyInjection/AIExtension.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
use Symfony\AI\Store\Bridge\ChromaDB\Store as ChromaDBStore;
5050
use Symfony\AI\Store\Bridge\MongoDB\Store as MongoDBStore;
5151
use Symfony\AI\Store\Bridge\Pinecone\Store as PineconeStore;
52-
use Symfony\AI\Store\Embedder;
52+
use Symfony\AI\Store\Indexer;
5353
use Symfony\AI\Store\StoreInterface;
5454
use Symfony\AI\Store\VectorStoreInterface;
5555
use Symfony\Component\Config\FileLocator;
@@ -108,11 +108,11 @@ public function load(array $configs, ContainerBuilder $container): void
108108
$container->setAlias(StoreInterface::class, reset($stores));
109109
}
110110

111-
foreach ($config['embedder'] as $embedderName => $embedder) {
112-
$this->processEmbedderConfig($embedderName, $embedder, $container);
111+
foreach ($config['indexer'] as $indexerName => $indexer) {
112+
$this->processIndexerConfig($indexerName, $indexer, $container);
113113
}
114-
if (1 === \count($config['embedder']) && isset($embedderName)) {
115-
$container->setAlias(Embedder::class, 'symfony_ai.embedder.'.$embedderName);
114+
if (1 === \count($config['indexer']) && isset($indexerName)) {
115+
$container->setAlias(Indexer::class, 'symfony_ai.indexer.'.$indexerName);
116116
}
117117

118118
$container->registerAttributeForAutoconfiguration(AsTool::class, static function (ChildDefinition $definition, AsTool $attribute): void {
@@ -465,7 +465,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
465465
/**
466466
* @param array<string, mixed> $config
467467
*/
468-
private function processEmbedderConfig(int|string $name, array $config, ContainerBuilder $container): void
468+
private function processIndexerConfig(int|string $name, array $config, ContainerBuilder $container): void
469469
{
470470
['name' => $modelName, 'version' => $version, 'options' => $options] = $config['model'];
471471

@@ -482,14 +482,14 @@ private function processEmbedderConfig(int|string $name, array $config, Containe
482482
$modelDefinition->setArgument('$options', $options);
483483
}
484484
$modelDefinition->addTag('symfony_ai.model.embeddings_model');
485-
$container->setDefinition('symfony_ai.embedder.'.$name.'.model', $modelDefinition);
485+
$container->setDefinition('symfony_ai.indexer.'.$name.'.model', $modelDefinition);
486486

487-
$definition = new Definition(Embedder::class, [
488-
'$model' => new Reference('symfony_ai.embedder.'.$name.'.model'),
487+
$definition = new Definition(Indexer::class, [
488+
'$model' => new Reference('symfony_ai.indexer.'.$name.'.model'),
489489
'$platform' => new Reference($config['platform']),
490490
'$store' => new Reference($config['store']),
491491
]);
492492

493-
$container->setDefinition('symfony_ai.embedder.'.$name, $definition);
493+
$container->setDefinition('symfony_ai.indexer.'.$name, $definition);
494494
}
495495
}

src/ai-bundle/src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function getConfigTreeBuilder(): TreeBuilder
192192
->end()
193193
->end()
194194
->end()
195-
->arrayNode('embedder')
195+
->arrayNode('indexer')
196196
->normalizeKeys(false)
197197
->useAttributeAsKey('name')
198198
->arrayPrototype()

src/store/src/Embedder.php renamed to src/store/src/Indexer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* @author Christopher Hertel <[email protected]>
2626
*/
27-
final readonly class Embedder
27+
final readonly class Indexer
2828
{
2929
private ClockInterface $clock;
3030

@@ -39,16 +39,16 @@ public function __construct(
3939
}
4040

4141
/**
42-
* @param TextDocument|TextDocument[] $documents
42+
* @param TextDocument|iterable<TextDocument> $documents
4343
*/
44-
public function embed(TextDocument|array $documents, int $chunkSize = 0, int $sleep = 0): void
44+
public function index(TextDocument|iterable $documents, int $chunkSize = 0, int $sleep = 0): void
4545
{
4646
if ($documents instanceof TextDocument) {
4747
$documents = [$documents];
4848
}
4949

5050
if ([] === $documents) {
51-
$this->logger->debug('No documents to embed');
51+
$this->logger->debug('No documents to index');
5252

5353
return;
5454
}

src/store/tests/EmbedderTest.php renamed to src/store/tests/IndexerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
use Symfony\AI\Store\Document\Metadata;
2828
use Symfony\AI\Store\Document\TextDocument;
2929
use Symfony\AI\Store\Document\VectorDocument;
30-
use Symfony\AI\Store\Embedder;
30+
use Symfony\AI\Store\Indexer;
3131
use Symfony\AI\Store\Tests\Double\PlatformTestHandler;
3232
use Symfony\AI\Store\Tests\Double\TestStore;
3333
use Symfony\Component\Clock\MockClock;
3434
use Symfony\Component\Uid\Uuid;
3535

36-
#[CoversClass(Embedder::class)]
36+
#[CoversClass(Indexer::class)]
3737
#[Medium]
3838
#[UsesClass(TextDocument::class)]
3939
#[UsesClass(Vector::class)]
@@ -44,22 +44,22 @@
4444
#[UsesClass(Platform::class)]
4545
#[UsesClass(AsyncResponse::class)]
4646
#[UsesClass(VectorResponse::class)]
47-
final class EmbedderTest extends TestCase
47+
final class IndexerTest extends TestCase
4848
{
4949
#[Test]
5050
public function embedSingleDocument(): void
5151
{
5252
$document = new TextDocument($id = Uuid::v4(), 'Test content');
5353
$vector = new Vector([0.1, 0.2, 0.3]);
5454

55-
$embedder = new Embedder(
55+
$indexer = new Indexer(
5656
PlatformTestHandler::createPlatform(new VectorResponse($vector)),
5757
new Embeddings(),
5858
$store = new TestStore(),
5959
new MockClock(),
6060
);
6161

62-
$embedder->embed($document);
62+
$indexer->index($document);
6363

6464
self::assertCount(1, $store->documents);
6565
self::assertInstanceOf(VectorDocument::class, $store->documents[0]);
@@ -71,17 +71,17 @@ public function embedSingleDocument(): void
7171
public function embedEmptyDocumentList(): void
7272
{
7373
$logger = self::createMock(LoggerInterface::class);
74-
$logger->expects(self::once())->method('debug')->with('No documents to embed');
74+
$logger->expects(self::once())->method('debug')->with('No documents to index');
7575

76-
$embedder = new Embedder(
76+
$indexer = new Indexer(
7777
PlatformTestHandler::createPlatform(),
7878
new Embeddings(),
7979
$store = new TestStore(),
8080
new MockClock(),
8181
$logger,
8282
);
8383

84-
$embedder->embed([]);
84+
$indexer->index([]);
8585

8686
self::assertSame([], $store->documents);
8787
}
@@ -93,14 +93,14 @@ public function embedDocumentWithMetadata(): void
9393
$document = new TextDocument($id = Uuid::v4(), 'Test content', $metadata);
9494
$vector = new Vector([0.1, 0.2, 0.3]);
9595

96-
$embedder = new Embedder(
96+
$indexer = new Indexer(
9797
PlatformTestHandler::createPlatform(new VectorResponse($vector)),
9898
new Embeddings(),
9999
$store = new TestStore(),
100100
new MockClock(),
101101
);
102102

103-
$embedder->embed($document);
103+
$indexer->index($document);
104104

105105
self::assertSame(1, $store->addCalls);
106106
self::assertCount(1, $store->documents);
@@ -119,14 +119,14 @@ public function embedWithSleep(): void
119119
$document1 = new TextDocument(Uuid::v4(), 'Test content 1');
120120
$document2 = new TextDocument(Uuid::v4(), 'Test content 2');
121121

122-
$embedder = new Embedder(
122+
$indexer = new Indexer(
123123
PlatformTestHandler::createPlatform(new VectorResponse($vector1, $vector2)),
124124
new Embeddings(),
125125
$store = new TestStore(),
126126
$clock = new MockClock('2024-01-01 00:00:00'),
127127
);
128128

129-
$embedder->embed(
129+
$indexer->index(
130130
documents: [$document1, $document2],
131131
sleep: 3
132132
);

0 commit comments

Comments
 (0)