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
10 changes: 4 additions & 6 deletions src/ai-bundle/config/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\PlatformInterface;
use Symfony\AI\Store\Bridge\Postgres\Distance as PostgresDistance;
use Symfony\AI\Store\Bridge\Redis\Distance;
use Symfony\AI\Store\Document\VectorizerInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
Expand Down Expand Up @@ -794,8 +792,8 @@
->end()
->enumNode('distance')
->info('Distance metric to use for vector similarity search')
->enumFqcn(PostgresDistance::class)
->defaultValue(PostgresDistance::L2)
->values(['cosine', 'inner_product', 'l1', 'l2'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only issue I see here is the fact that if a new case is added/removed in PostgresDistance, this config won't be up-to-date with it.
It will require to update the values (and add a conflict in the composer json ?).

But I don't see better solution for now. Unless removing the values restrictions and doing the value validation

  • either in the AiBundle.php
  • either in a callback here (but I'm not sure if it will avoid the unresolved enum...)

I wonder how it's dealed in other symfony packages, this should not be the first enum in an optional dependency isn't it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR welcome if you find something. To unblock, I merge this one in the current state.

->defaultValue('l2')
->end()
->stringNode('dbal_connection')->cannotBeEmpty()->end()
->end()
Expand Down Expand Up @@ -844,8 +842,8 @@
->end()
->enumNode('distance')
->info('Distance metric to use for vector similarity search')
->values(Distance::cases())
->defaultValue(Distance::Cosine)
->values(['COSINE', 'L2', 'IP'])
->defaultValue('COSINE')
->end()
->end()
->validate()
Expand Down
8 changes: 4 additions & 4 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@
use Symfony\AI\Store\Bridge\Neo4j\Store as Neo4jStore;
use Symfony\AI\Store\Bridge\OpenSearch\Store as OpenSearchStore;
use Symfony\AI\Store\Bridge\Pinecone\Store as PineconeStore;
use Symfony\AI\Store\Bridge\Postgres\Distance as PostgresDistance;
use Symfony\AI\Store\Bridge\Postgres\Store as PostgresStore;
use Symfony\AI\Store\Bridge\Qdrant\Store as QdrantStore;
use Symfony\AI\Store\Bridge\Redis\Distance as RedisDistance;
use Symfony\AI\Store\Bridge\Redis\Store as RedisStore;
use Symfony\AI\Store\Bridge\Supabase\Store as SupabaseStore;
use Symfony\AI\Store\Bridge\SurrealDb\Store as SurrealDbStore;
Expand Down Expand Up @@ -1437,9 +1439,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
];
}

if (\array_key_exists('distance', $store)) {
$arguments[3] = $store['distance'];
}
$arguments[3] = PostgresDistance::from($store['distance']);

$definition
->setLazy(true)
Expand Down Expand Up @@ -1507,7 +1507,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
$redisClient,
$store['index_name'] ?? $name,
$store['key_prefix'],
$store['distance'],
RedisDistance::from($store['distance']),
])
->addTag('proxy', ['interface' => StoreInterface::class])
->addTag('proxy', ['interface' => ManagedStoreInterface::class])
Expand Down
16 changes: 8 additions & 8 deletions src/ai-bundle/tests/DependencyInjection/AiBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
use Symfony\AI\Store\Bridge\Neo4j\Store as Neo4jStore;
use Symfony\AI\Store\Bridge\OpenSearch\Store as OpenSearchStore;
use Symfony\AI\Store\Bridge\Pinecone\Store as PineconeStore;
use Symfony\AI\Store\Bridge\Postgres\Distance;
use Symfony\AI\Store\Bridge\Postgres\Distance as PostgresDistance;
use Symfony\AI\Store\Bridge\Postgres\Store as PostgresStore;
use Symfony\AI\Store\Bridge\Qdrant\Store as QdrantStore;
use Symfony\AI\Store\Bridge\Redis\Distance as RedisDistance;
Expand Down Expand Up @@ -2588,7 +2588,7 @@ public function testPostgresStoreWithDifferentConnectionCanBeConfigured()
$this->assertSame('my_connection', (string) $definition->getArgument(0));
$this->assertSame('db', $definition->getArgument(1));
$this->assertSame('foo', $definition->getArgument(2));
$this->assertSame(Distance::L2, $definition->getArgument(3));
$this->assertSame(PostgresDistance::L2, $definition->getArgument(3));

$this->assertTrue($definition->hasTag('proxy'));
$this->assertSame([
Expand All @@ -2609,7 +2609,7 @@ public function testPostgresStoreWithDifferentConnectionCanBeConfigured()
'db' => [
'dbal_connection' => 'my_connection',
'vector_field' => 'foo',
'distance' => Distance::L1->value,
'distance' => PostgresDistance::L1->value,
],
],
],
Expand All @@ -2625,7 +2625,7 @@ public function testPostgresStoreWithDifferentConnectionCanBeConfigured()
$this->assertSame('my_connection', (string) $definition->getArgument(0));
$this->assertSame('db', $definition->getArgument(1));
$this->assertSame('foo', $definition->getArgument(2));
$this->assertSame(Distance::L1, $definition->getArgument(3));
$this->assertSame(PostgresDistance::L1, $definition->getArgument(3));

$this->assertTrue($definition->hasTag('proxy'));
$this->assertSame([
Expand All @@ -2647,7 +2647,7 @@ public function testPostgresStoreWithDifferentConnectionCanBeConfigured()
'dbal_connection' => 'my_connection',
'table_name' => 'foo',
'vector_field' => 'foo',
'distance' => Distance::L1->value,
'distance' => PostgresDistance::L1->value,
],
],
],
Expand All @@ -2663,7 +2663,7 @@ public function testPostgresStoreWithDifferentConnectionCanBeConfigured()
$this->assertSame('my_connection', (string) $definition->getArgument(0));
$this->assertSame('foo', $definition->getArgument(1));
$this->assertSame('foo', $definition->getArgument(2));
$this->assertSame(Distance::L1, $definition->getArgument(3));
$this->assertSame(PostgresDistance::L1, $definition->getArgument(3));

$this->assertTrue($definition->hasTag('proxy'));
$this->assertSame([
Expand Down Expand Up @@ -2997,7 +2997,7 @@ public function testRedisStoreWithCustomDistanceCanBeConfigured()
'my_redis_store' => [
'client' => 'foo',
'index_name' => 'my_vector_index',
'distance' => RedisDistance::L2,
'distance' => RedisDistance::L2->value,
],
],
],
Expand Down Expand Up @@ -7217,7 +7217,7 @@ private function getFullConfig(): array
'my_redis_store_with_custom_distance' => [
'client' => 'foo',
'index_name' => 'my_vector_index',
'distance' => RedisDistance::L2,
'distance' => RedisDistance::L2->value,
],
],
'supabase' => [
Expand Down