diff --git a/README.md b/README.md index 33466fc..8d2c297 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,13 @@ llm_chain: endpoint: '%env(AZURE_SEARCH_ENDPOINT)%' index_name: '%env(AZURE_SEARCH_INDEX)%' api_version: '2024-07-01' + mongodb: + engine: 'mongodb' + 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..d1a1270 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,12 +52,15 @@ 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() ->scalarNode('index_name')->end() ->scalarNode('api_version')->end() + ->scalarNode('database_name')->end() + ->scalarNode('vector_field_name')->end() + ->booleanNode('bulk_write')->end() ->end() ->end() ->end() diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 71c65ab..1870af4 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -13,6 +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\Store as MongoDBStore; use PhpLlm\LlmChain\Store\StoreInterface; use PhpLlm\LlmChain\Store\VectorStoreInterface; use PhpLlm\LlmChain\ToolBox\AsTool; @@ -164,5 +165,17 @@ 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('$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..ac65080 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -13,6 +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\Store as MongoDBStore; use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolBox; @@ -71,6 +72,15 @@ ->args([ '$collectionName' => abstract_arg('Name of ChromaDB collection'), ]) + ->set(MongoDBStore::class) + ->abstract() + ->args([ + '$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)