Skip to content

Commit d3b078f

Browse files
committed
feat: add store config with ChromaDB
1 parent 01e5d8e commit d3b078f

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public function getConfigTreeBuilder(): TreeBuilder
4747
->end()
4848
->end()
4949
->end()
50+
->arrayNode('stores')
51+
->normalizeKeys(false)
52+
->useAttributeAsKey('name')
53+
->arrayPrototype()
54+
->children()
55+
->scalarNode('engine')->isRequired()->end()
56+
->scalarNode('collection_name')->end()
57+
->end()
58+
->end()
5059
->end()
5160
;
5261

src/DependencyInjection/LlmChainExtension.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use PhpLlm\LlmChain\OpenAI\Runtime;
1212
use PhpLlm\LlmChain\OpenAI\Runtime\Azure as AzureRuntime;
1313
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI as OpenAIRuntime;
14+
use PhpLlm\LlmChain\Store\ChromaDb\Store as ChromaDbStore;
15+
use PhpLlm\LlmChain\Store\StoreInterface;
16+
use PhpLlm\LlmChain\Store\VectorStoreInterface;
1417
use PhpLlm\LlmChain\ToolBox\AsTool;
1518
use Symfony\Component\Config\FileLocator;
1619
use Symfony\Component\DependencyInjection\ChildDefinition;
@@ -50,6 +53,14 @@ public function load(array $configs, ContainerBuilder $container): void
5053
$container->setAlias(EmbeddingModel::class, 'llm_chain.embeddings.'.$name);
5154
}
5255

56+
foreach ($config['stores'] as $name => $store) {
57+
$this->processStoreConfig($name, $store, $container);
58+
}
59+
if (1 === count($config['stores'])) {
60+
$container->setAlias(VectorStoreInterface::class, 'llm_chain.store.'.$name);
61+
$container->setAlias(StoreInterface::class, 'llm_chain.store.'.$name);
62+
}
63+
5364
$container->registerAttributeForAutoconfiguration(AsTool::class, static function (ChildDefinition $definition, AsTool $attribute): void {
5465
$definition->addTag('llm_chain.tool', [
5566
'name' => $attribute->name,
@@ -102,4 +113,14 @@ private function processEmbeddingsConfig(string $name, mixed $embeddings, Contai
102113

103114
$container->setDefinition('llm_chain.embeddings.'.$name, $definition);
104115
}
116+
117+
private function processStoreConfig(string $name, mixed $stores, ContainerBuilder $container): void
118+
{
119+
if ('chroma-db' === $stores['engine']) {
120+
$definition = new ChildDefinition(ChromaDbStore::class);
121+
$definition->replaceArgument('$collectionName', $stores['collection_name']);
122+
123+
$container->setDefinition('llm_chain.store.'.$name, $definition);
124+
}
125+
}
105126
}

src/Resources/config/services.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
66

77
use PhpLlm\LlmChain\Chat;
8+
use PhpLlm\LlmChain\DocumentEmbedder;
89
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
910
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
1011
use PhpLlm\LlmChain\OpenAI\Runtime;
12+
use PhpLlm\LlmChain\OpenAI\Runtime\Azure as AzureRuntime;
13+
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI as OpenAIRuntime;
1114
use PhpLlm\LlmChain\RetrievalChain;
1215
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
1316
use PhpLlm\LlmChain\ToolBox\Registry;
1417
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1518
use PhpLlm\LlmChain\ToolChain;
16-
use PhpLlm\LlmChain\OpenAI\Runtime\Azure as AzureRuntime;
17-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI as OpenAIRuntime;
19+
use PhpLlm\LlmChain\Store\ChromaDb\Store as ChromaDbStore;
1820

1921
return static function (ContainerConfigurator $container) {
2022
$container->services()
@@ -54,6 +56,16 @@
5456
'$runtime' => service(Runtime::class),
5557
])
5658

59+
// stores
60+
->set(ChromaDbStore::class)
61+
->abstract()
62+
->args([
63+
'$collectionName' => abstract_arg('Name of ChromaDB collection'),
64+
])
65+
66+
// embedder
67+
->set(DocumentEmbedder::class)
68+
5769
// tools
5870
->set(Registry::class)
5971
->args([

0 commit comments

Comments
 (0)