|
107 | 107 | use Symfony\AI\Store\Bridge\Weaviate\Store as WeaviateStore; |
108 | 108 | use Symfony\AI\Store\Distance\DistanceCalculator; |
109 | 109 | use Symfony\AI\Store\Distance\DistanceStrategy; |
| 110 | +use Symfony\AI\Store\Document\Loader; |
| 111 | +use Symfony\AI\Store\Document\SourceLoaderInterface; |
110 | 112 | use Symfony\AI\Store\Document\Vectorizer; |
111 | 113 | use Symfony\AI\Store\Document\VectorizerInterface; |
112 | 114 | use Symfony\AI\Store\Indexer; |
@@ -312,6 +314,9 @@ public function loadExtension(array $config, ContainerConfigurator $container, C |
312 | 314 | $builder->registerForAutoconfiguration(ResultConverterInterface::class) |
313 | 315 | ->addTag('ai.platform.result_converter'); |
314 | 316 |
|
| 317 | + $builder->registerForAutoconfiguration(SourceLoaderInterface::class) |
| 318 | + ->addTag('ai.store.source_loader'); |
| 319 | + |
315 | 320 | if (!ContainerBuilder::willBeAvailable('symfony/security-core', AuthorizationCheckerInterface::class, ['symfony/ai-bundle'])) { |
316 | 321 | $builder->removeDefinition('ai.security.is_granted_attribute_listener'); |
317 | 322 | $builder->registerAttributeForAutoconfiguration( |
@@ -2063,18 +2068,43 @@ private function processIndexerConfig(int|string $name, array $config, Container |
2063 | 2068 | $filters[] = new Reference($filter); |
2064 | 2069 | } |
2065 | 2070 |
|
| 2071 | + $loaders = []; |
| 2072 | + if (isset($config['loaders'])) { |
| 2073 | + /** @var class-string<SourceLoaderInterface> $sourceLoader */ |
| 2074 | + foreach ($config['loaders'] as $sourceLoader) { |
| 2075 | + $loaders[$sourceLoader::supportedSource()] = new Reference($sourceLoader); |
| 2076 | + } |
| 2077 | + } else { |
| 2078 | + foreach ($container->findTaggedServiceIds('ai.store.source_loader') as $id => $tags) { |
| 2079 | + $loaders[$tags[0]['supports']] = new Reference($id); |
| 2080 | + } |
| 2081 | + } |
| 2082 | + $loader = new Definition(Loader::class, [$loaders]); |
| 2083 | + |
2066 | 2084 | $definition = new Definition(Indexer::class, [ |
2067 | | - new Reference($config['loader']), |
| 2085 | + $loader, |
2068 | 2086 | new Reference($config['vectorizer']), |
2069 | 2087 | new Reference($config['store']), |
2070 | | - $config['source'], |
2071 | 2088 | $filters, |
2072 | 2089 | $transformers, |
2073 | 2090 | new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), |
2074 | 2091 | ]); |
2075 | 2092 | $definition->addTag('ai.indexer', ['name' => $name]); |
2076 | 2093 |
|
| 2094 | + // Register input object for ai:store:index command |
| 2095 | + if (isset($config['input'])) { |
| 2096 | + /** @var class-string<SourceLoaderInterface> $loader */ |
| 2097 | + $sourceLoader = $config['input']['loader']; |
| 2098 | + $sourceId = 'ai.indexer.'.$name.'.input'; |
| 2099 | + $source = (new Definition($sourceLoader::supportedSource())) |
| 2100 | + ->addTag('ai.indexer.source', ['indexer' => $name]) |
| 2101 | + ->setFactory([$sourceLoader, 'createSource']) |
| 2102 | + ->setArguments([$config['input']['source']]); |
| 2103 | + $container->setDefinition($sourceId, $source); |
| 2104 | + } |
| 2105 | + |
2077 | 2106 | $serviceId = 'ai.indexer.'.$name; |
| 2107 | + $container->setDefinition($serviceId.'.loader', $loader); |
2078 | 2108 | $container->setDefinition($serviceId, $definition); |
2079 | 2109 | $container->registerAliasForArgument($serviceId, IndexerInterface::class, (new Target((string) $name))->getParsedName()); |
2080 | 2110 | } |
|
0 commit comments