Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new MongoDB store #24

Merged
merged 7 commits into from
Sep 26, 2024
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
OskarStark marked this conversation as resolved.
Show resolved Hide resolved
->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()
Expand Down
13 changes: 13 additions & 0 deletions src/DependencyInjection/LlmChainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down