|
11 | 11 | use PhpLlm\LlmChain\OpenAI\Runtime; |
12 | 12 | use PhpLlm\LlmChain\OpenAI\Runtime\Azure as AzureRuntime; |
13 | 13 | 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; |
14 | 17 | use PhpLlm\LlmChain\ToolBox\AsTool; |
15 | 18 | use Symfony\Component\Config\FileLocator; |
16 | 19 | use Symfony\Component\DependencyInjection\ChildDefinition; |
@@ -50,6 +53,14 @@ public function load(array $configs, ContainerBuilder $container): void |
50 | 53 | $container->setAlias(EmbeddingModel::class, 'llm_chain.embeddings.'.$name); |
51 | 54 | } |
52 | 55 |
|
| 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 | + |
53 | 64 | $container->registerAttributeForAutoconfiguration(AsTool::class, static function (ChildDefinition $definition, AsTool $attribute): void { |
54 | 65 | $definition->addTag('llm_chain.tool', [ |
55 | 66 | 'name' => $attribute->name, |
@@ -102,4 +113,14 @@ private function processEmbeddingsConfig(string $name, mixed $embeddings, Contai |
102 | 113 |
|
103 | 114 | $container->setDefinition('llm_chain.embeddings.'.$name, $definition); |
104 | 115 | } |
| 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 | + } |
105 | 126 | } |
0 commit comments