From 28c8a202cb34d9ac8cedb9c6a3a0e84bf728ac64 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 26 Sep 2024 15:05:53 +0200 Subject: [PATCH 1/7] fix --- src/DependencyInjection/LlmChainExtension.php | 14 ++++++++++++++ src/Resources/config/services.php | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 71c65ab..4e6b0dd 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -12,6 +12,7 @@ use PhpLlm\LlmChain\OpenAI\Platform\Azure as AzurePlatform; use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform; use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore; +use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore; use PhpLlm\LlmChain\Store\StoreInterface; use PhpLlm\LlmChain\Store\VectorStoreInterface; @@ -164,5 +165,18 @@ private function processStoreConfig(string $name, array $stores, ContainerBuilde $container->setDefinition('llm_chain.store.'.$name, $definition); } + + if ('mongodb' === $stores['engine']) { + $definition = new ChildDefinition(MongoDBStore::class); + $definition + ->replaceArgument('$dsn', $stores['dsn']) + ->replaceArgument('$databaseName', $stores['databaseName']) + ->replaceArgument('$collectionName', $stores['collection_name']) + ->replaceArgument('$indexName', $stores['index_name']) + ->replaceArgument('$vectorFieldName', $stores['vector_field_name']) + ->replaceArgument('$bulkWrite', $stores['bulk_write']); + + $container->setDefinition('llm_chain.store.'.$name, $definition); + } } } diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 2a717a4..e1d407b 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -12,6 +12,7 @@ use PhpLlm\LlmChain\OpenAI\Platform\Azure as AzurePlatform; use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform; use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore; +use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore; use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; @@ -71,6 +72,16 @@ ->args([ '$collectionName' => abstract_arg('Name of ChromaDB collection'), ]) + ->set(MongoDBStore::class) + ->abstract() + ->args([ + '$dsn' => abstract_arg('The DSN to connect to the MongoDB server'), + '$databaseName' => abstract_arg('The name of the database'), + '$collectionName' => abstract_arg('The name of the collection'), + '$indexName' => abstract_arg('The name of the Atlas Search index'), + '$vectorFieldName' => abstract_arg('The name of the field int the index that contains the vector'), + '$bulkWrite' => abstract_arg('Use bulk write operations'), + ]) // tools ->set(ToolBox::class) From 0ba267f439db0fd1dd03b7ab83f04860f1c387f9 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 26 Sep 2024 15:08:10 +0200 Subject: [PATCH 2/7] - --- README.md | 8 ++++++++ src/DependencyInjection/Configuration.php | 2 +- src/DependencyInjection/LlmChainExtension.php | 2 +- src/Resources/config/services.php | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 33466fc..3a51c05 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,14 @@ llm_chain: endpoint: '%env(AZURE_SEARCH_ENDPOINT)%' index_name: '%env(AZURE_SEARCH_INDEX)%' api_version: '2024-07-01' + mongodb: + engine: 'mongodb' + uri: '%env(MONGODB_URI)%' + database_name: '%env(MONGODB_DATABASE)%' + collection_name: '%env(MONGODB_COLLECTION)%' + index_name: '%env(MONGODB_INDEX)%' + vector_field_name: 'vector' + bulk_write: false ``` ## Usage diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7c366f7..c3f0660 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,7 +52,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->useAttributeAsKey('name') ->arrayPrototype() ->children() - ->enumNode('engine')->values(['chroma-db', 'azure-search'])->isRequired()->end() + ->enumNode('engine')->values(['chroma-db', 'azure-search', 'mongodb'])->isRequired()->end() ->scalarNode('collection_name')->end() ->scalarNode('api_key')->end() ->scalarNode('endpoint')->end() diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 4e6b0dd..221c274 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -169,7 +169,7 @@ private function processStoreConfig(string $name, array $stores, ContainerBuilde if ('mongodb' === $stores['engine']) { $definition = new ChildDefinition(MongoDBStore::class); $definition - ->replaceArgument('$dsn', $stores['dsn']) + ->replaceArgument('$uri', $stores['uri']) ->replaceArgument('$databaseName', $stores['databaseName']) ->replaceArgument('$collectionName', $stores['collection_name']) ->replaceArgument('$indexName', $stores['index_name']) diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index e1d407b..e6a058b 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -75,7 +75,7 @@ ->set(MongoDBStore::class) ->abstract() ->args([ - '$dsn' => abstract_arg('The DSN to connect to the MongoDB server'), + '$uri' => abstract_arg('The URI to connect to the MongoDB server'), '$databaseName' => abstract_arg('The name of the database'), '$collectionName' => abstract_arg('The name of the collection'), '$indexName' => abstract_arg('The name of the Atlas Search index'), From af6f539c3accecb592f31c2516842256e5db6423 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 26 Sep 2024 15:09:21 +0200 Subject: [PATCH 3/7] - --- src/DependencyInjection/Configuration.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index c3f0660..647be1f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -58,6 +58,9 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('endpoint')->end() ->scalarNode('index_name')->end() ->scalarNode('api_version')->end() + ->scalarNode('database_name')->end() + ->scalarNode('uri')->end() + ->scalarNode('vector_field_name')->end() ->end() ->end() ->end() From c4c1d0d206b99ab301a9a1808ef763e6a2840ff0 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 26 Sep 2024 22:22:16 +0200 Subject: [PATCH 4/7] - --- src/DependencyInjection/Configuration.php | 2 +- src/DependencyInjection/LlmChainExtension.php | 1 - src/Resources/config/services.php | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 647be1f..7c2c88d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -59,7 +59,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('index_name')->end() ->scalarNode('api_version')->end() ->scalarNode('database_name')->end() - ->scalarNode('uri')->end() + ->scalarNode('ur')->end() ->scalarNode('vector_field_name')->end() ->end() ->end() diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 221c274..875d1ed 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -169,7 +169,6 @@ private function processStoreConfig(string $name, array $stores, ContainerBuilde if ('mongodb' === $stores['engine']) { $definition = new ChildDefinition(MongoDBStore::class); $definition - ->replaceArgument('$uri', $stores['uri']) ->replaceArgument('$databaseName', $stores['databaseName']) ->replaceArgument('$collectionName', $stores['collection_name']) ->replaceArgument('$indexName', $stores['index_name']) diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index e6a058b..150df4b 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -75,7 +75,6 @@ ->set(MongoDBStore::class) ->abstract() ->args([ - '$uri' => abstract_arg('The URI to connect to the MongoDB server'), '$databaseName' => abstract_arg('The name of the database'), '$collectionName' => abstract_arg('The name of the collection'), '$indexName' => abstract_arg('The name of the Atlas Search index'), From 6f6dfecfd53e64cb06c031771f3ce355816d28ce Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Thu, 26 Sep 2024 23:53:34 +0200 Subject: [PATCH 5/7] fix: clean up config --- README.md | 1 - src/DependencyInjection/Configuration.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a51c05..8d2c297 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ llm_chain: api_version: '2024-07-01' mongodb: engine: 'mongodb' - uri: '%env(MONGODB_URI)%' database_name: '%env(MONGODB_DATABASE)%' collection_name: '%env(MONGODB_COLLECTION)%' index_name: '%env(MONGODB_INDEX)%' diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7c2c88d..d1a1270 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -59,8 +59,8 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('index_name')->end() ->scalarNode('api_version')->end() ->scalarNode('database_name')->end() - ->scalarNode('ur')->end() ->scalarNode('vector_field_name')->end() + ->booleanNode('bulk_write')->end() ->end() ->end() ->end() From f99e544ecc39ddd03ee6ef8c4681f76a1d8f1e56 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Thu, 26 Sep 2024 23:55:33 +0200 Subject: [PATCH 6/7] fix: codestyle --- src/DependencyInjection/LlmChainExtension.php | 2 +- src/Resources/config/services.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 875d1ed..8dfeb77 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -12,8 +12,8 @@ use PhpLlm\LlmChain\OpenAI\Platform\Azure as AzurePlatform; use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform; use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore; -use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore; +use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; use PhpLlm\LlmChain\Store\StoreInterface; use PhpLlm\LlmChain\Store\VectorStoreInterface; use PhpLlm\LlmChain\ToolBox\AsTool; diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 150df4b..651c7ec 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -12,8 +12,8 @@ use PhpLlm\LlmChain\OpenAI\Platform\Azure as AzurePlatform; use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform; use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore; -use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore; +use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolBox; From cf7b864fc8a3fc845bba73480ecc724fe93fc62f Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Fri, 27 Sep 2024 00:02:55 +0200 Subject: [PATCH 7/7] fix: class names --- src/DependencyInjection/LlmChainExtension.php | 2 +- src/Resources/config/services.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 8dfeb77..1870af4 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -13,7 +13,7 @@ use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform; use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore; use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore; -use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; +use PhpLlm\LlmChain\Store\MongoDB\Store as MongoDBStore; use PhpLlm\LlmChain\Store\StoreInterface; use PhpLlm\LlmChain\Store\VectorStoreInterface; use PhpLlm\LlmChain\ToolBox\AsTool; diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 651c7ec..ac65080 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -13,7 +13,7 @@ use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform; use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore; use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore; -use PhpLlm\LlmChain\Store\MongoDB\SearchStore as MongoDBStore; +use PhpLlm\LlmChain\Store\MongoDB\Store as MongoDBStore; use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolBox;