Install

Works with Drupal: ^10.3 || ^11.0

Using Composer to manage Drupal site dependencies

Alternative installation files

Download tar.gz 15.86 KB
MD5: 3b23a055b10d8ea958c29b1bfa4c5eaa
SHA-1: 5060424f0ac3e14f9a4ba6036561196fd5e2fa9b
SHA-256: 6296b35c629d64ac65a3dac0b54a7d0a661c423e33f9433ac0ff44ea0cef6844
Download zip 27.81 KB
MD5: 07ee3bfeafc478f367582366a9335bef
SHA-1: f7acb198594bee5560d8e56964126bf2d85cb11c
SHA-256: 40bee3358bf632f736e121d13ebb4601daa0a34aac9acfd5639eab40200af844

Release notes

Fixes:

This release contains improvements and introduces an plugin interface.

There is no way to satisfy everyones ranking, querying or re-ranking needs under semantic search as every site and search relevancy is unique to them.

Instead, this release introduces a plugin system to implement your own ranking algorithm. It ships with "PureVector", which is the code that was hard coded in the event subscriber in previous releases:

/**
 * Pure vector search ranker.
 *
 * This plugin overwrites the main query for a vector search comparison.
 */
#[DenseVectorRanker(
  id: 'pure_vector',
  label: new TranslatableMarkup('Pure Vector'),
)]
class PureVector extends DenseVectorRankerPluginBase {

  /**
   * {@inheritdoc}
   */
  public function apply(SolariumQueryInterface $query, string $solr_field, int $top_k, array $vectors): SolariumQueryInterface {
    return $query->setQuery('{!knn f=' . $solr_field . ' topK=' . $top_k . '}[' . implode(', ', $vectors[0]) . ']');
  }

}

The event subscriber will now dispatch that call to the selected plugin configured on the Solr index:

            if (isset($index_settings['dense_vector']['enable_vector_rerank']) && (bool) $index_settings['dense_vector']['enable_vector_rerank']) {
              try {
                $plugin = $this->denseVectorRankerPluginManager->createInstance($index_settings['dense_vector']['dense_vector_rank_plugin']);
                $plugin->apply($solarium_query, $solr_field, (int) $index_settings['dense_vector']['top_k'], $vectors);
              }
              catch (\Exception $e) {
                $this->loggerFactory->get('search_api_solr_dense_vector')->error('There was an issue loading or executing the dense vector reranker @plugin: @message', ['@message' => $e->getMessage(), '@plugin' => $index_settings['dense_vector']['dense_vector_rank_plugin']]);
              }
            }

Here is an example of such a plugin you could make:

/**
 * Blended rerank rank plugin.
 */
#[DenseVectorRanker(
  id: 'blended_rerank',
  label: new TranslatableMarkup('Blended Rerank'),
)]
class BlendedRerank extends DenseVectorRankerPluginBase implements ContainerFactoryPluginInterface {
  use AutowirePluginTrait;

  public function __construct(
    array $configuration,
    $plugin_id,
    $plugin_definition,
    protected ConfigFactoryInterface $configFactory,
  ) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public function apply(SolariumQueryInterface $query, string $solr_field, int $top_k, array $vectors): SolariumQueryInterface {
    $query->addParam('mm', '2<63%');
    $query->addParam('tie', '0.1');
    // Solr reranking logic here
    return $query;
  }

}

New settings now exist on the Solr index for every Solr index you have configured. The top_k setting has been moved here as well. This is where you can set which plugin to use per index. This should allow flexibility for most developers to augment or implement what they want to do. The Solarium query passed to the plugin can be modified in ways beyond what Views or the original query object could be made to do. Here you have almost full access to changing what you want before it is executed in Solr granting you a lot of control.

Note that the interface may change in the alpha series as we make improvements.

Created by: kevinquillen
Created on: 4 Oct 2025 at 20:58 UTC
Last updated: 4 Oct 2025 at 21:04 UTC
New features

Other releases