Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions examples/.env
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,36 @@ ALBERT_API_URL=
# For MariaDB store. Server defined in compose.yaml
MARIADB_URI=pdo-mysql://root@127.0.0.1:3309/my_database

# Meilisearch
# Meilisearch (store)
MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_API_KEY=changeMe

# For using LMStudio
LMSTUDIO_HOST_URL=http://127.0.0.1:1234

# Qdrant
# Qdrant (store)
QDRANT_HOST=http://127.0.0.1:6333
QDRANT_SERVICE_API_KEY=changeMe

# SurrealDB
# SurrealDB (store)
SURREALDB_HOST=http://127.0.0.1:8000
SURREALDB_USER=symfony
SURREALDB_PASS=symfony

# Neo4J
# Neo4J (store)
NEO4J_HOST=http://127.0.0.1:7474
NEO4J_DATABASE=neo4j
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=symfonyai

# Typesense
# Typesense (store)
TYPESENSE_HOST=http://127.0.0.1:8108
TYPESENSE_API_KEY=changeMe

# Milvus (store)
MILVUS_HOST=http://127.0.0.1:19530
MILVUS_API_KEY=root:Milvus
MILVUS_DATABASE=symfony

# Cerebras
CEREBRAS_API_KEY=
64 changes: 64 additions & 0 deletions examples/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,69 @@ services:
ports:
- '8108:8108'

# Milvus services
etcd:
container_name: milvus-etcd
image: quay.io/coreos/etcd:v3.5.18
environment:
- ETCD_AUTO_COMPACTION_MODE=revision
- ETCD_AUTO_COMPACTION_RETENTION=1000
- ETCD_QUOTA_BACKEND_BYTES=4294967296
- ETCD_SNAPSHOT_COUNT=50000
volumes:
- etcd_vlm:/etcd
command: etcd -advertise-client-urls=http://etcd:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
healthcheck:
test: [ "CMD", "etcdctl", "endpoint", "health" ]
interval: 30s
timeout: 20s
retries: 3

minio:
container_name: milvus-minio
image: minio/minio:RELEASE.2024-12-18T13-15-44Z
environment:
MINIO_ACCESS_KEY: minioadmin
MINIO_SECRET_KEY: minioadmin
ports:
- '9001:9001'
- '9000:9000'
volumes:
- minio_vlm:/minio_data
command: minio server /minio_data --console-address ":9001"
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
interval: 30s
timeout: 20s
retries: 3

milvus:
container_name: milvus-standalone
image: milvusdb/milvus:v2.6.0
command: ["milvus", "run", "standalone"]
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
MQ_TYPE: woodpecker
volumes:
- milvus_vlm:/var/lib/milvus
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
interval: 30s
start_period: 90s
timeout: 20s
retries: 3
ports:
- '19530:19530'
- '9091:9091'
depends_on:
- 'etcd'
- 'minio'

volumes:
typesense_data:
etcd_vlm:
minio_vlm:
milvus_vlm:
72 changes: 72 additions & 0 deletions examples/rag/milvus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\OpenAi\Embeddings;
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Store\Bridge\Milvus\Store;
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\Component\Uid\Uuid;

require_once dirname(__DIR__).'/bootstrap.php';

// initialize the store
$store = new Store(
httpClient: http_client(),
endpointUrl: env('MILVUS_HOST'),
apiKey: env('MILVUS_API_KEY'),
database: env('MILVUS_DATABASE'),
collection: 'movies',
);

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

// create embeddings and documents
$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('OPENAI_API_KEY'), http_client());
$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings());
$indexer = new Indexer($vectorizer, $store, logger());
$indexer->index($documents);

$model = new Gpt(Gpt::GPT_4O_MINI);

$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 technology?')
);
$result = $agent->call($messages);

echo $result->getContent().\PHP_EOL;
15 changes: 15 additions & 0 deletions src/ai-bundle/config/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@
->end()
->end()
->end()
->arrayNode('milvus')
->normalizeKeys(false)
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->scalarNode('endpoint')->cannotBeEmpty()->end()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('database')->isRequired()->end()
->scalarNode('collection')->isRequired()->end()
->scalarNode('vector_field')->end()
->scalarNode('dimensions')->end()
->scalarNode('metric_type')->end()
->end()
->end()
->end()
->arrayNode('mongodb')
->normalizeKeys(false)
->useAttributeAsKey('name')
Expand Down
32 changes: 32 additions & 0 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use Symfony\AI\Store\Bridge\Local\DistanceStrategy;
use Symfony\AI\Store\Bridge\Local\InMemoryStore;
use Symfony\AI\Store\Bridge\Meilisearch\Store as MeilisearchStore;
use Symfony\AI\Store\Bridge\Milvus\Store as MilvusStore;
use Symfony\AI\Store\Bridge\MongoDb\Store as MongoDbStore;
use Symfony\AI\Store\Bridge\Neo4j\Store as Neo4jStore;
use Symfony\AI\Store\Bridge\Pinecone\Store as PineconeStore;
Expand Down Expand Up @@ -634,6 +635,37 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
}
}

if ('milvus' === $type) {
foreach ($stores as $name => $store) {
$arguments = [
new Reference('http_client'),
$store['endpoint'],
$store['api_key'],
$store['database'],
$store['collection'],
];

if (\array_key_exists('vector_field', $store)) {
$arguments[5] = $store['vector_field'];
}

if (\array_key_exists('dimensions', $store)) {
$arguments[6] = $store['dimensions'];
}

if (\array_key_exists('metric_type', $store)) {
$arguments[7] = $store['metric_type'];
}

$definition = new Definition(MilvusStore::class);
$definition
->addTag('ai.store')
->setArguments($arguments);

$container->setDefinition('ai.store.'.$type.'.'.$name, $definition);
}
}

if ('mongodb' === $type) {
foreach ($stores as $name => $store) {
$arguments = [
Expand Down
11 changes: 11 additions & 0 deletions src/ai-bundle/tests/DependencyInjection/AiBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,17 @@ private function getFullConfig(): array
'strategy' => 'cosine',
],
],
'milvus' => [
'my_milvus_store' => [
'endpoint' => 'http://127.0.0.1:19530',
'api_key' => 'foo',
'database' => 'test',
'collection' => 'default',
'vector_field' => '_vectors',
'dimensions' => 768,
'metric_type' => 'COSINE',
],
],
'mongodb' => [
'my_mongo_store' => [
'database' => 'my_db',
Expand Down
8 changes: 6 additions & 2 deletions src/store/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You can find more advanced usage in combination with an Agent using the store fo
* `Similarity Search with MariaDB (RAG)`_
* `Similarity Search with Meilisearch (RAG)`_
* `Similarity Search with memory storage (RAG)`_
* `Similarity Search with Milvus (RAG)`_
* `Similarity Search with MongoDB (RAG)`_
* `Similarity Search with Neo4j (RAG)`_
* `Similarity Search with Pinecone (RAG)`_
Expand All @@ -62,6 +63,7 @@ Supported Stores
* `InMemory`_
* `MariaDB`_ (requires `ext-pdo`)
* `Meilisearch`_
* `Milvus`_
* `MongoDB Atlas`_ (requires `mongodb/mongodb` as additional dependency)
* `Neo4j`_
* `Pinecone`_ (requires `probots-io/pinecone-php` as additional dependency)
Expand Down Expand Up @@ -101,9 +103,10 @@ This leads to a store implementing two methods::

.. _`Retrieval Augmented Generation`: https://de.wikipedia.org/wiki/Retrieval-Augmented_Generation
.. _`Similarity Search with MariaDB (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/mariadb-gemini.php
.. _`Similarity Search with MongoDB (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/mongodb.php
.. _`Similarity Search with Meilisearch (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/meilisearch.php
.. _`Similarity Search with memory storage (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/in-memory.php
.. _`Similarity Search with Milvus (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/meilisearch.php
.. _`Similarity Search with MongoDB (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/milvus.php
.. _`Similarity Search with Neo4j (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/neo4j.php
.. _`Similarity Search with Pinecone (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/pinecone.php
.. _`Similarity Search with Symfony Cache (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/cache.php
Expand All @@ -113,10 +116,11 @@ This leads to a store implementing two methods::
.. _`Azure AI Search`: https://azure.microsoft.com/products/ai-services/ai-search
.. _`Chroma`: https://www.trychroma.com/
.. _`MariaDB`: https://mariadb.org/projects/mariadb-vector/
.. _`MongoDB Atlas`: https://www.mongodb.com/atlas
.. _`Pinecone`: https://www.pinecone.io/
.. _`Postgres`: https://www.postgresql.org/about/news/pgvector-070-released-2852/
.. _`Meilisearch`: https://www.meilisearch.com/
.. _`Milvus`: https://milvus.io/
.. _`MongoDB Atlas`: https://www.mongodb.com/atlas
.. _`SurrealDB`: https://surrealdb.com/
.. _`InMemory`: https://www.php.net/manual/en/language.types.array.php
.. _`Qdrant`: https://qdrant.tech/
Expand Down
Loading