Cache embedding lookups
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3552522. --> Reported by: [scott_euser](https://www.drupal.org/user/3267594) Related to !953 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Particularly with AI Search, now that hybrid search is getting more popular, changes to exposed filters trigger regeneration of embeddings. As done in <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-1"><a href="https://www.drupal.org/project/search_api_solr_dense_vector/issues/3543366" title="Status: Active">#3543366: Store resulting embedding from AI into local k/v for later lookup</a></span>, the wider AI Search can benefit from this.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Use a persistent cache that does not get cleared on cache rebuild (but still expires and gets cleared on cron cleanup after expiry</p> <h3 id="summary-proposed-resolution">Steps to test</h3> <ol> <li>Checkout this merge request</li> <li>Checkout the merge request in OpenAI provider <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-4"><a href="https://www.drupal.org/project/ai_provider_openai/issues/3552523" title="Status: Postponed">#3552523: Opt-in to cache embedding lookups</a></span></li> <li>Run the same embedding input twice, see the second time is cached</li> </ol> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ol> <li>Make the expiry configurable?</li> <li>Document how to clear it (i.e., <code>drush cache:clear ai_embeddings</code>)</li> <li>Create follow-ups in the various AI Providers that support embeddings to have them opt-in to this</li> </ol> <h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3> <p>Since the method won't exist, should be 2.x + AI Providers should be 2.x constraint (or we do method_exists call in providers?)</p>
issue