ai_search_block drops valid Search API results when drupal_entity_id extra data is missing (e.g. Solr dense vector)
Problem/Motivation
ai_search_block currently assumes every Search API result contains extraData('drupal_entity_id').
In AiSearchBlockHelper::renderRagResponseAsString(), results are filtered out if that value is empty. For some backends (notably search_api_solr_dense_vector), result items can be valid but only expose:
ResultItem::getId()likeentity:node/3:nlextraData('content')- no
extraData('drupal_entity_id')
This causes all hits to be discarded and the block returns the configured “no results” message, even when Search API returned matches.
Additional context
With the same Solr dense vector index, AI agents using ai_search:rag_search do return results correctly.
Reason:
- The agent flow (
ai_searchRagTool) primarily consumesextraData('content'). - It does not require
drupal_entity_idto accept a hit.
So this is not a Solr retrieval failure; it is a result-normalization mismatch in ai_search_block filtering logic.
Affected version
Observed on drupal/ai_search_block 1.0.0-rc21.
Steps to reproduce
- Install and configure
ai_search_block. - Configure a Search API index backed by Solr +
search_api_solr_dense_vector. - Set the AI Search block to use that index (
databasesetting). - Ensure Search API query returns hits with
contentand item IDs (e.g.entity:node/3:nl) but withoutdrupal_entity_idextra data. - Ask a question that should match indexed content.
Current result
The block shows the “no results” response because all result items are filtered out.
Expected result
The block should accept valid Search API item IDs as fallback when drupal_entity_id is not present.
Proposed resolution
In AiSearchBlockHelper::renderRagResponseAsString(), fallback to ResultItem::getId()
Related issue
There is already a related issue: Compatibility with other search api servers (#3547421).
If this still occurs, this may be a regression or release mismatch and should be tracked accordingly.
Issue fork ai_search_block-3576759
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
emielb commentedPosted a fix for this on the issue fork and opened an MR against `ai_search_block`:
MR: https://git.drupalcode.org/project/ai_search_block/-/merge_requests/37
Summary of the change:
- In `AiSearchBlockHelper::renderRagResponseAsString()`, when `drupal_entity_id` extra data is missing, we now fall back to `ResultItem::getId()`.
- This keeps current behavior for providers that already set `drupal_entity_id`, while allowing valid Search API backends (e.g. Solr dense vector) to pass entity resolution.
- Existing regex/entity/access checks remain unchanged, so invalid IDs are still filtered out.
This resolves the case where `ai_search_block` returned “no results” even though Search API returned valid hits.
Comment #6
wouters_f commentedMerged. Also pushed on the 2.0 branch.
Thanks