-
-
Notifications
You must be signed in to change notification settings - Fork 44
[Platform] Add Ollama embeddings #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/platform/tests/Bridge/Ollama/Embeddings/ResultConverterTest.php
Outdated
Show resolved
Hide resolved
5cd354e
to
096f582
Compare
Ok, should be better 😅 |
Looks like I need to be faster with proposing my changes :D glad that you already have tests at hand This is my example to proof, that Ollama can solve the same movie selection task <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\AI\Agent\Agent;
use Symfony\AI\Agent\Toolbox\AgentProcessor;
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
use Symfony\AI\Agent\Toolbox\Toolbox;
use Symfony\AI\Fixtures\Movies;
use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Bridge\Ollama\Embeddings;
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\TextDocument;
use Symfony\AI\Store\Document\Vectorizer;
use Symfony\AI\Store\Indexer;
use Symfony\AI\Store\InMemoryStore;
use Symfony\Component\Uid\Uuid;
require_once dirname(__DIR__).'/bootstrap.php';
// initialize the store
$store = new InMemoryStore();
// create embeddings and documents
foreach (Movies::all() as $i => $movie) {
$documents[] = new TextDocument(
id: Uuid::v4(),
content: 'Title: '.$movie['title'].\PHP_EOL.'Director: '.$movie['director'].\PHP_EOL.'Description: '.$movie['description'],
metadata: new Metadata($movie),
);
}
// create embeddings for documents
$platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client());
$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::MXBAI_EMBED_LARGE));
$indexer = new Indexer($vectorizer, $store, logger());
$indexer->index($documents);
$model = new Llama(Llama::V3_2_1B);
$similaritySearch = new SimilaritySearch($platform, $embeddings, $store);
$toolbox = new Toolbox([$similaritySearch], logger: logger());
$processor = new AgentProcessor($toolbox);
$agent = new Agent($platform, $model, [$processor], [$processor], logger());
$messages = new MessageBag(
Message::forSystem('Please answer all user questions only using SimilaritySearch function.'),
Message::ofUser('Which movie fits the theme of the mafia?')
);
$result = $agent->call($messages);
echo $result->getContent().\PHP_EOL; |
Hi @JoshuaBehrens 👋🏻 Ah, didn't know that you were working on it, sorry 😅 Regarding your example, I just listed the model that are commonly used, if you have any other model in mind, feel free to list them, we can add them in the class 🙂 BTW, I agree (if the suggestion is to add an example via Ollama), we should add one with the Ollama stack |
No worries @Guikingone I did not have any real dips on that ^^' Implementation looks similar: class Embeddings extends Model
{
public const MXBAI_EMBED_LARGE = 'mxbai-embed-large';
public const NOMIC_EMBED_TEXT = 'nomic-embed-text';
public const ALL_MINILM = 'all-minilm';
/**
* @param array<string, mixed> $options
*/
public function __construct(string $name = self::ALL_MINILM, array $options = [])
{
parent::__construct($name, [], $options);
}
} ![]() Right now I am refactoring the use of the modal class so I wanted to wait for my refactoring but I will just amend yours later :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Guikingone, thanks for working on that and extending our Ollama support!
My initial thought was that this is straight forward and a matching implementation, but checking it out and testing it got me thinking.
I think it would be great, if we can ease the Ollama usage a bit and reduce it to one model class and client. For deciding on the endpoint and result converter, we could use the model's capabilities. Either hard code them in the model class or dynamically fetch them from /api/show
endpoint.
how does that sound?
src/platform/CHANGELOG.md
Outdated
@@ -14,7 +14,7 @@ CHANGELOG | |||
- AWS Bedrock (Anthropic Claude, Meta Llama, Amazon Nova) | |||
- Mistral AI (language models and embeddings) | |||
- Meta Llama (via Azure, Ollama, Replicate, AWS Bedrock) | |||
- Ollama (local model hosting) | |||
- Ollama (local model hosting and embeddings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this addition is meaningful, since we create the embeddings also with models and the main feature of ollama is running models locally
Agree on the refactoring, the |
9ce976e
to
4018185
Compare
4018185
to
bf18f6c
Compare
Should be better, nice catch around the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good & works now - thanks! 👍
37a4b76
to
005ef2f
Compare
Hi 👋🏻
This PR aims to add the support for embeddings via
Ollama
, the platform is updated to handle the new embedding client.