Skip to content

Commit dc3672a

Browse files
committed
Fix after review
1 parent 6659849 commit dc3672a

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -350,23 +350,23 @@ $eventDispatcher->addListener(ToolCallsExecuted::class, function (ToolCallsExecu
350350
LLM Chain supports document embedding and similarity search using vector stores like ChromaDB, Azure AI Search, MongoDB
351351
Atlas Search, or Pinecone.
352352

353-
For populating a vector store, LLM Chain provides the service `EmbeddingProvider`, which requires an instance of an
353+
For populating a vector store, LLM Chain provides the service `Embedder`, which requires an instance of an
354354
`EmbeddingsModel` and one of `StoreInterface`, and works with a collection of `Document` objects as input:
355355

356356
```php
357-
use PhpLlm\LlmChain\EmbeddingProvider;
357+
use PhpLlm\LlmChain\Embedder;
358358
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings;
359359
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
360360
use PhpLlm\LlmChain\Bridge\Pinecone\Store;
361361
use Probots\Pinecone\Pinecone;
362362
use Symfony\Component\HttpClient\HttpClient;
363363

364-
$embeddingProvider = new EmbeddingProvider(
364+
$embedder = new Embedder(
365365
PlatformFactory::create($_ENV['OPENAI_API_KEY']),
366366
new Embeddings(),
367367
new Store(Pinecone::client($_ENV['PINECONE_API_KEY'], $_ENV['PINECONE_HOST']),
368368
);
369-
$embeddingProvider->embed($documents);
369+
$embedder->embed($documents);
370370
```
371371

372372
The collection of `Document` instances is usually created by text input of your domain entities:

examples/store-mongodb-similarity-search.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1212
use PhpLlm\LlmChain\Document\Metadata;
1313
use PhpLlm\LlmChain\Document\TextDocument;
14-
use PhpLlm\LlmChain\EmbeddingProvider;
14+
use PhpLlm\LlmChain\Embedder;
1515
use PhpLlm\LlmChain\Model\Message\Message;
1616
use PhpLlm\LlmChain\Model\Message\MessageBag;
1717
use Symfony\Component\Dotenv\Dotenv;
@@ -52,8 +52,8 @@
5252

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

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

examples/store-pinecone-similarity-search.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1111
use PhpLlm\LlmChain\Document\Metadata;
1212
use PhpLlm\LlmChain\Document\TextDocument;
13-
use PhpLlm\LlmChain\EmbeddingProvider;
13+
use PhpLlm\LlmChain\Embedder;
1414
use PhpLlm\LlmChain\Model\Message\Message;
1515
use PhpLlm\LlmChain\Model\Message\MessageBag;
1616
use Probots\Pinecone\Pinecone;
@@ -46,8 +46,8 @@
4646

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

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

src/EmbeddingProvider.php renamed to src/Embedder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Symfony\Component\Clock\Clock;
1414
use Symfony\Component\Clock\ClockInterface;
1515

16-
final readonly class EmbeddingProvider
16+
final readonly class Embedder
1717
{
1818
private ClockInterface $clock;
1919

tests/EmbeddingProviderTest.php renamed to tests/EmbedderTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PhpLlm\LlmChain\Document\TextDocument;
1010
use PhpLlm\LlmChain\Document\Vector;
1111
use PhpLlm\LlmChain\Document\VectorDocument;
12-
use PhpLlm\LlmChain\EmbeddingProvider;
12+
use PhpLlm\LlmChain\Embedder;
1313
use PhpLlm\LlmChain\Model\Message\ToolCallMessage;
1414
use PhpLlm\LlmChain\Model\Response\AsyncResponse;
1515
use PhpLlm\LlmChain\Model\Response\ToolCall;
@@ -26,7 +26,7 @@
2626
use Symfony\Component\Clock\MockClock;
2727
use Symfony\Component\Uid\Uuid;
2828

29-
#[CoversClass(EmbeddingProvider::class)]
29+
#[CoversClass(Embedder::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 EmbeddingProviderTest extends TestCase
40+
final class EmbedderTest 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-
$embeddingProvider = new EmbeddingProvider(
48+
$embedder = new Embedder(
4949
PlatformTestHandler::createPlatform(new VectorResponse($vector)),
5050
new Embeddings(),
5151
$store = new TestStore(),
5252
new MockClock(),
5353
);
5454

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

5757
self::assertCount(1, $store->documents);
5858
self::assertInstanceOf(VectorDocument::class, $store->documents[0]);
@@ -66,15 +66,15 @@ public function embedEmptyDocumentList(): void
6666
$logger = $this->createMock(LoggerInterface::class);
6767
$logger->expects($this->once())->method('debug')->with('No documents to embed');
6868

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

77-
$embeddingProvider->embed([]);
77+
$embedder->embed([]);
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-
$embeddingProvider = new EmbeddingProvider(
89+
$embedder = new Embedder(
9090
PlatformTestHandler::createPlatform(new VectorResponse($vector)),
9191
new Embeddings(),
9292
$store = new TestStore(),
9393
new MockClock(),
9494
);
9595

96-
$embeddingProvider->embed($document);
96+
$embedder->embed($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-
$embeddingProvider = new EmbeddingProvider(
115+
$embedder = new Embedder(
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-
$embeddingProvider->embed(
122+
$embedder->embed(
123123
documents: [$document1, $document2],
124124
sleep: 3
125125
);

0 commit comments

Comments
 (0)