Skip to content

Commit 2e7ac31

Browse files
committed
minor #119 [Examples] Introduce movie fixtures (chr-hertel)
This PR was merged into the main branch. Discussion ---------- [Examples] Introduce movie fixtures | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT Just to reduce the likelihood of lucky punches by providing more movies Commits ------- 310713e introduce movie fixtures
2 parents f7e72fa + 310713e commit 2e7ac31

7 files changed

+46
-51
lines changed

examples/store/mariadb-similarity-search-gemini.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1616
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1717
use Symfony\AI\Agent\Toolbox\Toolbox;
18+
use Symfony\AI\Fixtures\Movies;
1819
use Symfony\AI\Platform\Bridge\Google\Embeddings;
1920
use Symfony\AI\Platform\Bridge\Google\Embeddings\TaskType;
2021
use Symfony\AI\Platform\Bridge\Google\Gemini;
@@ -42,18 +43,10 @@
4243
connection: DriverManager::getConnection((new DsnParser())->parse($_SERVER['MARIADB_URI'])),
4344
tableName: 'my_table',
4445
indexName: 'my_index',
45-
vectorFieldName: 'embedding',
4646
);
4747

48-
// our data
49-
$movies = [
50-
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
51-
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
52-
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
53-
];
54-
5548
// create embeddings and documents
56-
foreach ($movies as $i => $movie) {
49+
foreach (Movies::all() as $i => $movie) {
5750
$documents[] = new TextDocument(
5851
id: Uuid::v4(),
5952
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],

examples/store/mariadb-similarity-search.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1616
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1717
use Symfony\AI\Agent\Toolbox\Toolbox;
18+
use Symfony\AI\Fixtures\Movies;
1819
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1920
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
2021
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
@@ -41,18 +42,10 @@
4142
connection: DriverManager::getConnection((new DsnParser())->parse($_SERVER['MARIADB_URI'])),
4243
tableName: 'my_table',
4344
indexName: 'my_index',
44-
vectorFieldName: 'embedding',
4545
);
4646

47-
// our data
48-
$movies = [
49-
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
50-
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
51-
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
52-
];
53-
5447
// create embeddings and documents
55-
foreach ($movies as $i => $movie) {
48+
foreach (Movies::all() as $i => $movie) {
5649
$documents[] = new TextDocument(
5750
id: Uuid::v4(),
5851
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],

examples/store/meilisearch-similarity-search.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1414
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1515
use Symfony\AI\Agent\Toolbox\Toolbox;
16+
use Symfony\AI\Fixtures\Movies;
1617
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1718
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
1819
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
@@ -43,16 +44,9 @@
4344
indexName: 'movies',
4445
);
4546

46-
// our data
47-
$movies = [
48-
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
49-
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
50-
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
51-
];
52-
5347
// create embeddings and documents
5448
$documents = [];
55-
foreach ($movies as $i => $movie) {
49+
foreach (Movies::all() as $i => $movie) {
5650
$documents[] = new TextDocument(
5751
id: Uuid::v4(),
5852
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],

examples/store/mongodb-similarity-search.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1515
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1616
use Symfony\AI\Agent\Toolbox\Toolbox;
17+
use Symfony\AI\Fixtures\Movies;
1718
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1819
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
1920
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
@@ -44,15 +45,8 @@
4445
vectorFieldName: 'vector',
4546
);
4647

47-
// our data
48-
$movies = [
49-
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
50-
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
51-
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
52-
];
53-
5448
// create embeddings and documents
55-
foreach ($movies as $movie) {
49+
foreach (Movies::all() as $movie) {
5650
$documents[] = new TextDocument(
5751
id: Uuid::v4(),
5852
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],

examples/store/pinecone-similarity-search.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1515
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1616
use Symfony\AI\Agent\Toolbox\Toolbox;
17+
use Symfony\AI\Fixtures\Movies;
1718
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1819
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
1920
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
@@ -38,15 +39,8 @@
3839
// initialize the store
3940
$store = new Store(Pinecone::client($_SERVER['PINECONE_API_KEY'], $_SERVER['PINECONE_HOST']));
4041

41-
// our data
42-
$movies = [
43-
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
44-
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
45-
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
46-
];
47-
4842
// create embeddings and documents
49-
foreach ($movies as $movie) {
43+
foreach (Movies::all() as $movie) {
5044
$documents[] = new TextDocument(
5145
id: Uuid::v4(),
5246
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],

examples/store/postgres-similarity-search.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1616
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1717
use Symfony\AI\Agent\Toolbox\Toolbox;
18+
use Symfony\AI\Fixtures\Movies;
1819
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1920
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
2021
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
@@ -40,19 +41,11 @@
4041
$store = Store::fromDbal(
4142
connection: DriverManager::getConnection((new DsnParser())->parse($_SERVER['POSTGRES_URI'])),
4243
tableName: 'my_table',
43-
vectorFieldName: 'embedding',
4444
);
4545

46-
// our data
47-
$movies = [
48-
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
49-
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
50-
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
51-
];
52-
5346
// create embeddings and documents
5447
$documents = [];
55-
foreach ($movies as $i => $movie) {
48+
foreach (Movies::all() as $i => $movie) {
5649
$documents[] = new TextDocument(
5750
id: Uuid::v4(),
5851
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],

fixtures/Movies.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Fixtures;
13+
14+
final readonly class Movies
15+
{
16+
/**
17+
* @return array<array{title: string, description: string, director: string}>
18+
*/
19+
public static function all(): array
20+
{
21+
return [
22+
['title' => 'Inception', 'description' => 'A skilled thief is given a chance at redemption if he can successfully perform inception, the act of planting an idea in someone\'s subconscious.', 'director' => 'Christopher Nolan'],
23+
['title' => 'The Matrix', 'description' => 'A hacker discovers the world he lives in is a simulated reality and joins a rebellion to overthrow its controllers.', 'director' => 'The Wachowskis'],
24+
['title' => 'The Godfather', 'description' => 'The aging patriarch of an organized crime dynasty transfers control of his empire to his reluctant son.', 'director' => 'Francis Ford Coppola'],
25+
['title' => 'Notting Hill', 'description' => 'A British bookseller meets and falls in love with a famous American actress, navigating the challenges of fame and romance.', 'director' => 'Roger Michell'],
26+
['title' => 'WALL-E', 'description' => 'A small waste-collecting robot inadvertently embarks on a space journey that will decide the fate of mankind.', 'director' => 'Andrew Stanton'],
27+
['title' => 'Spirited Away', 'description' => 'A young girl enters a mysterious world of spirits and must find a way to rescue her parents and return home.', 'director' => 'Hayao Miyazaki'],
28+
['title' => 'Jurassic Park', 'description' => 'During a preview tour, a theme park suffers a major power breakdown that allows its cloned dinosaur exhibits to run amok.', 'director' => 'Steven Spielberg'],
29+
['title' => 'Interstellar', 'description' => 'A team of explorers travel through a wormhole in space in an attempt to ensure humanity\'s survival.', 'director' => 'Christopher Nolan'],
30+
['title' => 'The Shawshank Redemption', 'description' => 'Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.', 'director' => 'Frank Darabont'],
31+
['title' => 'Gladiator', 'description' => 'A former Roman General sets out to exact vengeance against the corrupt emperor who murdered his family and sent him into slavery.', 'director' => 'Ridley Scott'],
32+
];
33+
}
34+
}

0 commit comments

Comments
 (0)