VDB: Unable to index items after index was cleared
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3578014. -->
Reported by: [mxr576](https://www.drupal.org/user/315522)
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>[One-line status update for stakeholders]<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<strong>Blocked by: </strong>[#XXXXXX] (New issues on new lines)<br>
<strong>Additional Collaborators: </strong> @username1, @username2<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>
Using <strong>“Clear all indexed data”</strong> on a VDB search index that uses<br>
<strong>pgvector</strong> via Amazee consistently causes indexing errors afterwards.<br>
This happens because the collection schema is dropped from the database but is not<br>
fully recreated.
</p>
<p>
Although<br>
<code>\Drupal\ai\Base\AiVdbProviderClientBase::deleteAllItems()</code> calls<br>
<code>\Drupal\ai_provider_amazeeio\Vdb\Postgres\Plugin\VdbProvider\PostgresProvider::createCollection()</code>,<br>
the method only creates a minimal schema:
</p>
<pre><pre>create table amazee_ai<br>(<br> id bigserial<br> primary key,<br> content varchar,<br> drupal_entity_id varchar,<br> drupal_long_id varchar,<br> server_id varchar,<br> index_id varchar,<br> embedding vector(1024)<br>)</pre></pre><p>
The full collection schema is restored only after editing the index configuration<br>
and clicking <strong>“Save”</strong>. This triggers<br>
<code>\Drupal\ai_provider_amazeeio\Vdb\Postgres\PostgresPgvectorClient::updateFields()</code>,<br>
which creates the missing fields:
</p>
<pre><pre>create table amazee_ai<br>(<br> id bigserial<br> primary key,<br> content varchar,<br> drupal_entity_id varchar,<br> drupal_long_id varchar,<br> server_id varchar,<br> index_id varchar,<br> embedding vector(1024),<br> description varchar,<br> http_method varchar,<br> operation_id varchar,<br> path varchar,<br> servers varchar,<br> summary varchar,<br> tags varchar,<br> title varchar<br>);</pre></pre><p>
As a result, indexing fails after clearing indexed data until the index<br>
configuration is manually saved, which recreates the missing fields.
</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<h3 id="summary-remaining-tasks">Target date or deadline</h3>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ai-usage">AI usage (if applicable)</h3>
<p>[ ] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[ ] AI Assisted Code<br>
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p>
<p>[ ] AI Generated Code<br>
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p>
<p>[ ] Vibe Coded<br>
This code was generated by an AI and has only been functionally tested.</p>
> Related issue: [Issue #3535073](https://www.drupal.org/node/3535073)
> Related issue: [Issue #3538122](https://www.drupal.org/node/3538122)
issue