Install
Works with Drupal: ^10.3 || ^11.0Using Composer to manage Drupal site dependencies
Alternative installation files
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.