diff --git a/web/modules/custom/materio_ai/materio_ai.info.yml b/web/modules/custom/materio_ai/materio_ai.info.yml
index c826da5f..f9e1e16a 100644
--- a/web/modules/custom/materio_ai/materio_ai.info.yml
+++ b/web/modules/custom/materio_ai/materio_ai.info.yml
@@ -8,4 +8,5 @@ dependencies:
- address:address
- drupal:node
- drupal:taxonomy
+ - search_api_solr:search_api_solr
- workflow:workflow
diff --git a/web/modules/custom/materio_ai/materio_ai.services.yml b/web/modules/custom/materio_ai/materio_ai.services.yml
index ef364471..13e3672f 100644
--- a/web/modules/custom/materio_ai/materio_ai.services.yml
+++ b/web/modules/custom/materio_ai/materio_ai.services.yml
@@ -22,3 +22,9 @@ services:
class: Drupal\materio_ai\Vectorizer
arguments: ['@entity_type.manager', '@config.factory', '@queue', '@materio_ai.corpus_builder', '@materio_ai.embedding_client', '@materio_ai.embedding_storage']
Drupal\materio_ai\Vectorizer: '@materio_ai.vectorizer'
+
+ materio_ai.solr_config_subscriber:
+ class: Drupal\materio_ai\EventSubscriber\SolrConfigSubscriber
+ arguments: ['@config.factory']
+ tags:
+ - { name: event_subscriber }
diff --git a/web/modules/custom/materio_ai/src/EventSubscriber/SolrConfigSubscriber.php b/web/modules/custom/materio_ai/src/EventSubscriber/SolrConfigSubscriber.php
new file mode 100644
index 00000000..ac7dd25f
--- /dev/null
+++ b/web/modules/custom/materio_ai/src/EventSubscriber/SolrConfigSubscriber.php
@@ -0,0 +1,59 @@
+ 'addVectorField'];
+ }
+
+ /**
+ * Appends the field type and the dynamic field to the schema_extra files.
+ */
+ public function addVectorField(PostConfigFilesGenerationEvent $event): void {
+ if (version_compare($event->getLuceneMatchVersion(), '9.1', '<')) {
+ return;
+ }
+ $dimension = (int) $this->configFactory->get('materio_ai.settings')->get('dimension');
+ if ($dimension <= 0) {
+ return;
+ }
+ $files = $event->getConfigFiles();
+ foreach ([
+ 'schema_extra_types.xml' => VectorField::typeXml($dimension),
+ 'schema_extra_fields.xml' => VectorField::dynamicFieldXml($dimension),
+ ] as $file => $xml) {
+ if (isset($files[$file]) && !str_contains($files[$file], $xml)) {
+ $files[$file] .= $xml;
+ }
+ }
+ $event->setConfigFiles($files);
+ }
+
+}
diff --git a/web/modules/custom/materio_ai/src/Solr/VectorField.php b/web/modules/custom/materio_ai/src/Solr/VectorField.php
new file mode 100644
index 00000000..23ba9cc3
--- /dev/null
+++ b/web/modules/custom/materio_ai/src/Solr/VectorField.php
@@ -0,0 +1,55 @@
+ for schema_extra_types.xml.
+ *
+ * Cosine: no assumption on the norm of the vectors sent by the model.
+ */
+ public static function typeXml(int $dimension): string {
+ return sprintf(
+ "\n",
+ self::typeName($dimension),
+ $dimension,
+ );
+ }
+
+ /**
+ * for schema_extra_fields.xml.
+ *
+ * Not stored: the vectors live in the materio_ai_embedding table.
+ */
+ public static function dynamicFieldXml(int $dimension): string {
+ return sprintf(
+ "\n",
+ $dimension,
+ self::typeName($dimension),
+ );
+ }
+
+}