Vector DB Explorer fails with TypeError when search results contain array values in extra data
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3557904. -->
Reported by: [gxleano](https://www.drupal.org/user/3591999)
Related to !9
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>The Vector DB Explorer (<code>vector_db_generator </code>plugin) in the AI Search module throws a <code>Twig\Error\RuntimeError</code> when search results contain array values in their extra data.<br>
The error occurs because the code assumes all extra data values are strings, but search results can contain complex data structures such as arrays.</p>
<p>Error message: </p>
<p><code>Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("strlen(): Argument #1 ($string) must be of type string, array given") in "__string_template__36eeab8377919817875a18c90610bda7" at line 1.</code></p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>1. Install and enable the AI Search module<br>
2. Configure a Search API index with the <code>search_api_ai_search</code> backend<br>
3. Index content that includes complex metadata or field values<br>
4. Navigate to <code>/admin/config/ai/explorers/vector_db_generator</code><br>
5. Enter a search query and submit the form<br>
6. See the Twig runtime error when the results contain array values in extra data</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Add type checking in the <code>getResponse()</code> method to handle non-string values:</p>
<ul>
<li>Convert array values to JSON strings for display</li>
<li>Cast other non-string types to strings</li>
<li>Ensure all values are strings before passing to the Markdown converter or renderer</li>
</ul>
issue