Skip to content

Commit c894771

Browse files
committed
refactor(aibundle): improvements on vector stores
1 parent ced2f43 commit c894771

File tree

4 files changed

+1026
-360
lines changed

4 files changed

+1026
-360
lines changed

src/ai-bundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"phpstan/phpstan": "^2.1",
3434
"phpstan/phpstan-strict-rules": "^2.0",
3535
"phpunit/phpunit": "^11.5",
36+
"probots-io/pinecone-php": "^1.0",
3637
"symfony/expression-language": "^7.3|^8.0",
3738
"symfony/security-core": "^7.3|^8.0",
3839
"symfony/translation": "^7.3|^8.0"

src/ai-bundle/config/options.php

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@
667667
->stringNode('database')->isRequired()->end()
668668
->stringNode('collection')->isRequired()->end()
669669
->stringNode('index_name')->isRequired()->end()
670-
->stringNode('vector_field')->end()
670+
->stringNode('vector_field')->isRequired()->end()
671671
->booleanNode('bulk_write')->end()
672672
->end()
673673
->end()
@@ -682,9 +682,9 @@
682682
->stringNode('database')->cannotBeEmpty()->end()
683683
->stringNode('vector_index_name')->cannotBeEmpty()->end()
684684
->stringNode('node_name')->cannotBeEmpty()->end()
685-
->stringNode('vector_field')->end()
686-
->integerNode('dimensions')->end()
687-
->stringNode('distance')->end()
685+
->stringNode('vector_field')->isRequired()->end()
686+
->integerNode('dimensions')->isRequired()->end()
687+
->stringNode('distance')->isRequired()->end()
688688
->booleanNode('quantization')->end()
689689
->end()
690690
->end()
@@ -699,21 +699,49 @@
699699
->end()
700700
->stringNode('namespace')->end()
701701
->arrayNode('filter')
702-
->scalarPrototype()->end()
702+
->scalarPrototype()
703+
->defaultValue([])
704+
->end()
703705
->end()
704706
->integerNode('top_k')->end()
705707
->end()
706708
->end()
707709
->end()
710+
->arrayNode('postgres')
711+
->useAttributeAsKey('name')
712+
->arrayPrototype()
713+
->children()
714+
->stringNode('dsn')->cannotBeEmpty()->end()
715+
->stringNode('username')->end()
716+
->stringNode('password')->end()
717+
->stringNode('table_name')->isRequired()->end()
718+
->stringNode('vector_field')->isRequired()->end()
719+
->enumNode('distance')
720+
->info('Distance metric to use for vector similarity search')
721+
->enumFqcn(PostgresDistance::class)
722+
->defaultValue(PostgresDistance::L2)
723+
->end()
724+
->stringNode('dbal_connection')->cannotBeEmpty()->end()
725+
->end()
726+
->validate()
727+
->ifTrue(static fn (array $v): bool => !isset($v['dsn']) && !isset($v['dbal_connection']))
728+
->thenInvalid('Either "dsn" or "dbal_connection" must be configured.')
729+
->end()
730+
->validate()
731+
->ifTrue(static fn (array $v): bool => isset($v['dsn'], $v['dbal_connection']))
732+
->thenInvalid('Either "dsn" or "dbal_connection" can be configured, but not both.')
733+
->end()
734+
->end()
735+
->end()
708736
->arrayNode('qdrant')
709737
->useAttributeAsKey('name')
710738
->arrayPrototype()
711739
->children()
712740
->stringNode('endpoint')->cannotBeEmpty()->end()
713741
->stringNode('api_key')->cannotBeEmpty()->end()
714742
->stringNode('collection_name')->cannotBeEmpty()->end()
715-
->integerNode('dimensions')->end()
716-
->stringNode('distance')->end()
743+
->integerNode('dimensions')->isRequired()->end()
744+
->stringNode('distance')->isRequired()->end()
717745
->booleanNode('async')->end()
718746
->end()
719747
->end()
@@ -739,32 +767,15 @@
739767
->end()
740768
->end()
741769
->validate()
742-
->ifTrue(static fn ($v) => !isset($v['connection_parameters']) && !isset($v['client']))
770+
->ifTrue(static fn (array $v): bool => !isset($v['connection_parameters']) && !isset($v['client']))
743771
->thenInvalid('Either "connection_parameters" or "client" must be configured.')
744772
->end()
745773
->validate()
746-
->ifTrue(static fn ($v) => isset($v['connection_parameters']) && isset($v['client']))
774+
->ifTrue(static fn (array $v): bool => isset($v['connection_parameters']) && isset($v['client']))
747775
->thenInvalid('Either "connection_parameters" or "client" can be configured, but not both.')
748776
->end()
749777
->end()
750778
->end()
751-
->arrayNode('surreal_db')
752-
->useAttributeAsKey('name')
753-
->arrayPrototype()
754-
->children()
755-
->stringNode('endpoint')->cannotBeEmpty()->end()
756-
->stringNode('username')->cannotBeEmpty()->end()
757-
->stringNode('password')->cannotBeEmpty()->end()
758-
->stringNode('namespace')->cannotBeEmpty()->end()
759-
->stringNode('database')->cannotBeEmpty()->end()
760-
->stringNode('table')->end()
761-
->stringNode('vector_field')->end()
762-
->stringNode('strategy')->end()
763-
->integerNode('dimensions')->end()
764-
->booleanNode('namespaced_user')->end()
765-
->end()
766-
->end()
767-
->end()
768779
->arrayNode('supabase')
769780
->useAttributeAsKey('name')
770781
->arrayPrototype()
@@ -783,51 +794,42 @@
783794
->end()
784795
->end()
785796
->end()
786-
->arrayNode('typesense')
797+
->arrayNode('surrealdb')
787798
->useAttributeAsKey('name')
788799
->arrayPrototype()
789800
->children()
790801
->stringNode('endpoint')->cannotBeEmpty()->end()
791-
->stringNode('api_key')->isRequired()->end()
792-
->stringNode('collection')->isRequired()->end()
793-
->stringNode('vector_field')->end()
794-
->integerNode('dimensions')->end()
802+
->stringNode('username')->cannotBeEmpty()->end()
803+
->stringNode('password')->cannotBeEmpty()->end()
804+
->stringNode('namespace')->cannotBeEmpty()->end()
805+
->stringNode('database')->cannotBeEmpty()->end()
806+
->stringNode('table')->isRequired()->end()
807+
->stringNode('vector_field')->isRequired()->end()
808+
->stringNode('strategy')->isRequired()->end()
809+
->integerNode('dimensions')->isRequired()->end()
810+
->booleanNode('namespaced_user')->end()
795811
->end()
796812
->end()
797813
->end()
798-
->arrayNode('weaviate')
814+
->arrayNode('typesense')
799815
->useAttributeAsKey('name')
800816
->arrayPrototype()
801817
->children()
802818
->stringNode('endpoint')->cannotBeEmpty()->end()
803819
->stringNode('api_key')->isRequired()->end()
804820
->stringNode('collection')->isRequired()->end()
821+
->stringNode('vector_field')->isRequired()->end()
822+
->integerNode('dimensions')->isRequired()->end()
805823
->end()
806824
->end()
807825
->end()
808-
->arrayNode('postgres')
826+
->arrayNode('weaviate')
809827
->useAttributeAsKey('name')
810828
->arrayPrototype()
811829
->children()
812-
->stringNode('dsn')->cannotBeEmpty()->end()
813-
->stringNode('username')->end()
814-
->stringNode('password')->end()
815-
->stringNode('table_name')->isRequired()->end()
816-
->stringNode('vector_field')->end()
817-
->enumNode('distance')
818-
->info('Distance metric to use for vector similarity search')
819-
->enumFqcn(PostgresDistance::class)
820-
->defaultValue(PostgresDistance::L2)
821-
->end()
822-
->stringNode('dbal_connection')->cannotBeEmpty()->end()
823-
->end()
824-
->validate()
825-
->ifTrue(static fn (array $v): bool => !isset($v['dsn']) && !isset($v['dbal_connection']))
826-
->thenInvalid('Either "dsn" or "dbal_connection" must be configured.')
827-
->end()
828-
->validate()
829-
->ifTrue(static fn (array $v): bool => isset($v['dsn'], $v['dbal_connection']))
830-
->thenInvalid('Either "dsn" or "dbal_connection" can be configured, but not both.')
830+
->stringNode('endpoint')->cannotBeEmpty()->end()
831+
->stringNode('api_key')->isRequired()->end()
832+
->stringNode('collection')->isRequired()->end()
831833
->end()
832834
->end()
833835
->end()
@@ -936,7 +938,7 @@
936938
->end()
937939
->end()
938940
->end()
939-
->arrayNode('surreal_db')
941+
->arrayNode('surrealdb')
940942
->useAttributeAsKey('name')
941943
->arrayPrototype()
942944
->children()

0 commit comments

Comments
 (0)