Skip to content

Commit feb796c

Browse files
committed
feature #465 [Examples][Store] Implement indexing pipeline (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Examples][Store] Implement indexing pipeline | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | Fixes #429 | License | MIT ### Needs * symfony/ai#468 ### `./runner indexer` <img width="1832" height="664" alt="CleanShot 2025-09-08 at 17 11 53@2x" src="https://github.com/user-attachments/assets/19f32f93-f4b5-4b90-86a4-74d1623f78f1" /> ### `bin/console app:blog:embed` (removed) <img width="1780" height="306" alt="CleanShot 2025-09-08 at 17 12 45@2x" src="https://github.com/user-attachments/assets/4c8905be-f7b3-455b-8d20-112fe9f77136" /> ### `bin/console app:blog:query` <img width="1752" height="1168" alt="CleanShot 2025-09-08 at 17 13 34@2x" src="https://github.com/user-attachments/assets/45211bfb-366e-413b-b80f-33a757c63e31" /> ### `bin/console ai:store:index blog` <img width="1930" height="388" alt="CleanShot 2025-09-08 at 22 41 00@2x" src="https://github.com/user-attachments/assets/1d27d5e4-de23-4c3a-8465-a87eba79f2fc" /> Commits ------- 29349c11 [Examples][Store] Implement indexing pipeline
2 parents 3632ae9 + b8be2ce commit feb796c

File tree

6 files changed

+26
-80
lines changed

6 files changed

+26
-80
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ composer install
3636
echo "OPENAI_API_KEY='sk-...'" > .env.local
3737

3838
# Initialize vector store
39-
symfony console app:blog:embed -vv
39+
symfony console ai:store:index blog -vv
4040

4141
# Test vector store
4242
symfony console app:blog:query

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The [Chroma DB](https://www.trychroma.com/) is a vector store that is used to st
7474
To initialize the Chroma DB, you need to run the following command:
7575

7676
```shell
77-
symfony console app:blog:embed -vv
77+
symfony console ai:store:index blog -vv
7878
```
7979

8080
Now you should be able to run the test command and get some results:

config/packages/ai.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ ai:
5959
class: 'Symfony\AI\Platform\Bridge\OpenAi\Embeddings'
6060
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Embeddings::TEXT_ADA_002
6161
indexer:
62-
default:
62+
blog:
63+
loader: 'App\Blog\FeedLoader'
64+
source: 'https://feeds.feedburner.com/symfony/blog'
65+
transformers:
66+
- 'Symfony\AI\Store\Document\Transformer\TextTrimTransformer'
6367
vectorizer: 'ai.vectorizer.openai_embeddings'
6468
store: 'ai.store.chroma_db.symfonycon'
6569

@@ -75,3 +79,5 @@ services:
7579
Symfony\AI\Agent\Toolbox\Tool\Wikipedia: ~
7680
Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch:
7781
$vectorizer: '@ai.vectorizer.openai_embeddings'
82+
83+
Symfony\AI\Store\Document\Transformer\TextTrimTransformer: ~

src/Blog/Command/EmbedCommand.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Blog/Embedder.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/Blog/FeedLoader.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,33 @@
1111

1212
namespace App\Blog;
1313

14+
use Symfony\AI\Store\Document\LoaderInterface;
15+
use Symfony\AI\Store\Document\Metadata;
16+
use Symfony\AI\Store\Document\TextDocument;
17+
use Symfony\AI\Store\Exception\InvalidArgumentException;
1418
use Symfony\Component\DomCrawler\Crawler;
1519
use Symfony\Component\Uid\Uuid;
1620
use Symfony\Contracts\HttpClient\HttpClientInterface;
1721

18-
class FeedLoader
22+
final class FeedLoader implements LoaderInterface
1923
{
2024
public function __construct(
2125
private HttpClientInterface $httpClient,
2226
) {
2327
}
2428

2529
/**
26-
* @return Post[]
30+
* @param ?string $source RSS feed URL
31+
* @param array<string, mixed> $options
32+
*
33+
* @return iterable<TextDocument>
2734
*/
28-
public function load(): array
35+
public function load(?string $source, array $options = []): iterable
2936
{
30-
$result = $this->httpClient->request('GET', 'https://feeds.feedburner.com/symfony/blog');
37+
if (null === $source) {
38+
throw new InvalidArgumentException('FeedLoader requires a RSS feed URL as source, null given.');
39+
}
40+
$result = $this->httpClient->request('GET', $source);
3141

3242
$posts = [];
3343
$crawler = new Crawler($result->getContent());
@@ -44,6 +54,8 @@ public function load(): array
4454
);
4555
});
4656

47-
return $posts;
57+
foreach ($posts as $post) {
58+
yield new TextDocument($post->id, $post->toString(), new Metadata($post->toArray()));
59+
}
4860
}
4961
}

0 commit comments

Comments
 (0)