Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 488d762

Browse files
authored
refactor: rename Embedder to Indexer and open input to iterable (#336)
1 parent 9ae7051 commit 488d762

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,22 +391,22 @@ $response = $chain->call($messages);
391391
LLM Chain supports document embedding and similarity search using vector stores like ChromaDB, Azure AI Search, MongoDB
392392
Atlas Search, or Pinecone.
393393
394-
For populating a vector store, LLM Chain provides the service `Embedder`, which requires an instance of an
394+
For populating a vector store, LLM Chain provides the service `Indexer`, which requires an instance of an
395395
`EmbeddingsModel` and one of `StoreInterface`, and works with a collection of `Document` objects as input:
396396
397397
```php
398398
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
399399
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory;
400400
use PhpLlm\LlmChain\Store\Bridge\Pinecone\Store;
401-
use PhpLlm\LlmChain\Store\Embedder;
401+
use PhpLlm\LlmChain\Store\Indexer;
402402
use Probots\Pinecone\Pinecone;
403403
404-
$embedder = new Embedder(
404+
$indexer = new Indexer(
405405
PlatformFactory::create($_ENV['OPENAI_API_KEY']),
406406
new Embeddings(),
407407
new Store(Pinecone::client($_ENV['PINECONE_API_KEY'], $_ENV['PINECONE_HOST']),
408408
);
409-
$embedder->embed($documents);
409+
$indexer->index($documents);
410410
```
411411
412412
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
@@ -13,7 +13,7 @@
1313
use PhpLlm\LlmChain\Store\Bridge\MongoDB\Store;
1414
use PhpLlm\LlmChain\Store\Document\Metadata;
1515
use PhpLlm\LlmChain\Store\Document\TextDocument;
16-
use PhpLlm\LlmChain\Store\Embedder;
16+
use PhpLlm\LlmChain\Store\Indexer;
1717
use Symfony\Component\Dotenv\Dotenv;
1818
use Symfony\Component\Uid\Uuid;
1919

@@ -52,8 +52,8 @@
5252

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

5858
// initialize the index
5959
$store->initialize();

examples/store/pinecone-similarity-search.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use PhpLlm\LlmChain\Store\Bridge\Pinecone\Store;
1313
use PhpLlm\LlmChain\Store\Document\Metadata;
1414
use PhpLlm\LlmChain\Store\Document\TextDocument;
15-
use PhpLlm\LlmChain\Store\Embedder;
15+
use PhpLlm\LlmChain\Store\Indexer;
1616
use Probots\Pinecone\Pinecone;
1717
use Symfony\Component\Dotenv\Dotenv;
1818
use Symfony\Component\Uid\Uuid;
@@ -46,8 +46,8 @@
4646

4747
// create embeddings for documents
4848
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
49-
$embedder = new Embedder($platform, $embeddings = new Embeddings(), $store);
50-
$embedder->embed($documents);
49+
$indexer = new Indexer($platform, $embeddings = new Embeddings(), $store);
50+
$indexer->index($documents);
5151

5252
$model = new GPT(GPT::GPT_4O_MINI);
5353

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* @author Christopher Hertel <[email protected]>
1919
*/
20-
final readonly class Embedder
20+
final readonly class Indexer
2121
{
2222
private ClockInterface $clock;
2323

@@ -32,16 +32,16 @@ public function __construct(
3232
}
3333

3434
/**
35-
* @param TextDocument|TextDocument[] $documents
35+
* @param TextDocument|iterable<TextDocument> $documents
3636
*/
37-
public function embed(TextDocument|array $documents, int $chunkSize = 0, int $sleep = 0): void
37+
public function index(TextDocument|iterable $documents, int $chunkSize = 0, int $sleep = 0): void
3838
{
3939
if ($documents instanceof TextDocument) {
4040
$documents = [$documents];
4141
}
4242

4343
if ([] === $documents) {
44-
$this->logger->debug('No documents to embed');
44+
$this->logger->debug('No documents to index');
4545

4646
return;
4747
}

tests/Store/Document/NullVectorTest.php renamed to tests/Platform/Vector/NullVectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpLlm\LlmChain\Tests\Store\Document;
5+
namespace PhpLlm\LlmChain\Tests\Platform\Vector;
66

77
use PhpLlm\LlmChain\Platform\Vector\NullVector;
88
use PhpLlm\LlmChain\Platform\Vector\VectorInterface;

tests/Store/Document/VectorTest.php renamed to tests/Platform/Vector/VectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpLlm\LlmChain\Tests\Store\Document;
5+
namespace PhpLlm\LlmChain\Tests\Platform\Vector;
66

77
use PhpLlm\LlmChain\Platform\Vector\Vector;
88
use PhpLlm\LlmChain\Platform\Vector\VectorInterface;

tests/Store/EmbedderTest.php renamed to tests/Store/IndexerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PhpLlm\LlmChain\Store\Document\Metadata;
1515
use PhpLlm\LlmChain\Store\Document\TextDocument;
1616
use PhpLlm\LlmChain\Store\Document\VectorDocument;
17-
use PhpLlm\LlmChain\Store\Embedder;
17+
use PhpLlm\LlmChain\Store\Indexer;
1818
use PhpLlm\LlmChain\Tests\Double\PlatformTestHandler;
1919
use PhpLlm\LlmChain\Tests\Double\TestStore;
2020
use PHPUnit\Framework\Attributes\CoversClass;
@@ -26,7 +26,7 @@
2626
use Symfony\Component\Clock\MockClock;
2727
use Symfony\Component\Uid\Uuid;
2828

29-
#[CoversClass(Embedder::class)]
29+
#[CoversClass(Indexer::class)]
3030
#[Medium]
3131
#[UsesClass(TextDocument::class)]
3232
#[UsesClass(Vector::class)]
@@ -37,22 +37,22 @@
3737
#[UsesClass(Platform::class)]
3838
#[UsesClass(AsyncResponse::class)]
3939
#[UsesClass(VectorResponse::class)]
40-
final class EmbedderTest extends TestCase
40+
final class IndexerTest extends TestCase
4141
{
4242
#[Test]
4343
public function embedSingleDocument(): void
4444
{
4545
$document = new TextDocument($id = Uuid::v4(), 'Test content');
4646
$vector = new Vector([0.1, 0.2, 0.3]);
4747

48-
$embedder = new Embedder(
48+
$indexer = new Indexer(
4949
PlatformTestHandler::createPlatform(new VectorResponse($vector)),
5050
new Embeddings(),
5151
$store = new TestStore(),
5252
new MockClock(),
5353
);
5454

55-
$embedder->embed($document);
55+
$indexer->index($document);
5656

5757
self::assertCount(1, $store->documents);
5858
self::assertInstanceOf(VectorDocument::class, $store->documents[0]);
@@ -64,17 +64,17 @@ public function embedSingleDocument(): void
6464
public function embedEmptyDocumentList(): void
6565
{
6666
$logger = self::createMock(LoggerInterface::class);
67-
$logger->expects(self::once())->method('debug')->with('No documents to embed');
67+
$logger->expects(self::once())->method('debug')->with('No documents to index');
6868

69-
$embedder = new Embedder(
69+
$indexer = new Indexer(
7070
PlatformTestHandler::createPlatform(),
7171
new Embeddings(),
7272
$store = new TestStore(),
7373
new MockClock(),
7474
$logger,
7575
);
7676

77-
$embedder->embed([]);
77+
$indexer->index([]);
7878

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

89-
$embedder = new Embedder(
89+
$indexer = new Indexer(
9090
PlatformTestHandler::createPlatform(new VectorResponse($vector)),
9191
new Embeddings(),
9292
$store = new TestStore(),
9393
new MockClock(),
9494
);
9595

96-
$embedder->embed($document);
96+
$indexer->index($document);
9797

9898
self::assertSame(1, $store->addCalls);
9999
self::assertCount(1, $store->documents);
@@ -112,14 +112,14 @@ public function embedWithSleep(): void
112112
$document1 = new TextDocument(Uuid::v4(), 'Test content 1');
113113
$document2 = new TextDocument(Uuid::v4(), 'Test content 2');
114114

115-
$embedder = new Embedder(
115+
$indexer = new Indexer(
116116
PlatformTestHandler::createPlatform(new VectorResponse($vector1, $vector2)),
117117
new Embeddings(),
118118
$store = new TestStore(),
119119
$clock = new MockClock('2024-01-01 00:00:00'),
120120
);
121121

122-
$embedder->embed(
122+
$indexer->index(
123123
documents: [$document1, $document2],
124124
sleep: 3
125125
);

0 commit comments

Comments
 (0)