Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit b2802ee

Browse files
feat: Add support for new MongoDB store (#24)
* fix * - * - * - * fix: clean up config * fix: codestyle * fix: class names --------- Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
1 parent 8405efb commit b2802ee

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ llm_chain:
4949
endpoint: '%env(AZURE_SEARCH_ENDPOINT)%'
5050
index_name: '%env(AZURE_SEARCH_INDEX)%'
5151
api_version: '2024-07-01'
52+
mongodb:
53+
engine: 'mongodb'
54+
database_name: '%env(MONGODB_DATABASE)%'
55+
collection_name: '%env(MONGODB_COLLECTION)%'
56+
index_name: '%env(MONGODB_INDEX)%'
57+
vector_field_name: 'vector'
58+
bulk_write: false
5259
```
5360
5461
## Usage

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ public function getConfigTreeBuilder(): TreeBuilder
5252
->useAttributeAsKey('name')
5353
->arrayPrototype()
5454
->children()
55-
->enumNode('engine')->values(['chroma-db', 'azure-search'])->isRequired()->end()
55+
->enumNode('engine')->values(['chroma-db', 'azure-search', 'mongodb'])->isRequired()->end()
5656
->scalarNode('collection_name')->end()
5757
->scalarNode('api_key')->end()
5858
->scalarNode('endpoint')->end()
5959
->scalarNode('index_name')->end()
6060
->scalarNode('api_version')->end()
61+
->scalarNode('database_name')->end()
62+
->scalarNode('vector_field_name')->end()
63+
->booleanNode('bulk_write')->end()
6164
->end()
6265
->end()
6366
->end()

src/DependencyInjection/LlmChainExtension.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform;
1414
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
1515
use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore;
16+
use PhpLlm\LlmChain\Store\MongoDB\Store as MongoDBStore;
1617
use PhpLlm\LlmChain\Store\StoreInterface;
1718
use PhpLlm\LlmChain\Store\VectorStoreInterface;
1819
use PhpLlm\LlmChain\ToolBox\AsTool;
@@ -164,5 +165,17 @@ private function processStoreConfig(string $name, array $stores, ContainerBuilde
164165

165166
$container->setDefinition('llm_chain.store.'.$name, $definition);
166167
}
168+
169+
if ('mongodb' === $stores['engine']) {
170+
$definition = new ChildDefinition(MongoDBStore::class);
171+
$definition
172+
->replaceArgument('$databaseName', $stores['databaseName'])
173+
->replaceArgument('$collectionName', $stores['collection_name'])
174+
->replaceArgument('$indexName', $stores['index_name'])
175+
->replaceArgument('$vectorFieldName', $stores['vector_field_name'])
176+
->replaceArgument('$bulkWrite', $stores['bulk_write']);
177+
178+
$container->setDefinition('llm_chain.store.'.$name, $definition);
179+
}
167180
}
168181
}

src/Resources/config/services.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI as OpenAIPlatform;
1414
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
1515
use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore;
16+
use PhpLlm\LlmChain\Store\MongoDB\Store as MongoDBStore;
1617
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
1718
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1819
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -71,6 +72,15 @@
7172
->args([
7273
'$collectionName' => abstract_arg('Name of ChromaDB collection'),
7374
])
75+
->set(MongoDBStore::class)
76+
->abstract()
77+
->args([
78+
'$databaseName' => abstract_arg('The name of the database'),
79+
'$collectionName' => abstract_arg('The name of the collection'),
80+
'$indexName' => abstract_arg('The name of the Atlas Search index'),
81+
'$vectorFieldName' => abstract_arg('The name of the field int the index that contains the vector'),
82+
'$bulkWrite' => abstract_arg('Use bulk write operations'),
83+
])
7484

7585
// tools
7686
->set(ToolBox::class)

0 commit comments

Comments
 (0)