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() like entity:node/3:nl
  • extraData('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_search RagTool) primarily consumes extraData('content').
  • It does not require drupal_entity_id to 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

  1. Install and configure ai_search_block.
  2. Configure a Search API index backed by Solr + search_api_solr_dense_vector.
  3. Set the AI Search block to use that index (database setting).
  4. Ensure Search API query returns hits with content and item IDs (e.g. entity:node/3:nl) but without drupal_entity_id extra data.
  5. 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.

Command icon 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

emielb created an issue. See original summary.

  • emielb committed 58cf3a01 on 1.0.x
    Issue #3576759: Fallback to Search API item ID when drupal_entity_id is...
emielb’s picture

Posted 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.

  • emielb authored 15f4e480 on 2.0.x
    Issue #3576759: Fallback to Search API item ID when drupal_entity_id is...
wouters_f’s picture

Status: Active » Fixed

Merged. Also pushed on the 2.0 branch.
Thanks

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.