Problem/Motivation
Currently, the module triggers a re-computation of vector embeddings whenever the index configuration is saved or updated, even if the changes do not affect the content being embedded. This behavior is inefficient and costly because:
- Generating embeddings (e.g., via external APIs like OpenAI) often incurs financial costs per token.
- The process is computationally expensive and slows down the indexing operation.
- It is unnecessary to regenerate embeddings if the source fields (e.g., title, body) and the embedding configuration (e.g., model selection) have not changed.
Steps to reproduce
- Configure a Search API index using the Typesense backend with embeddings enabled on specific fields (e.g.,
body). - Index the content to generate the initial embeddings.
- Go to the index schema configuration page and change a setting unrelated to embeddings (e.g., change the "Batch size" or disable a different, unrelated processor).
- Save the configuration.
- Observe that the system marks the items for re-indexing and subsequently re-computes the embeddings, leading to unnecessary API calls.
Proposed resolution
Modify the logic to detect whether the configuration changes actually impact the embedding generation. The system should only trigger a re-computation of embeddings if:
- The fields selected for embedding have been modified.
- The embedding configuration itself (e.g., the chosen model or strategy) has changed.
If the configuration change is irrelevant to the embeddings (e.g., changing a different processor), the existing embeddings should be preserved to save resources.
Remaining tasks
- Review the code changes in the merge request.
- Test to ensure that changing unrelated index configuration does not trigger embedding re-computation.
- Test to verify that changing the embedding settings does trigger a re-computation as expected.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork search_api_typesense-3568250
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 #3
giuseppe87 commentedComment #5
robertoperuzzoComment #6
robertoperuzzoComment #7
robertoperuzzoComment #8
robertoperuzzoThanks @lussoluca and @giuseppe87 for what you've done so far!
I sum up here what I did in my latest commits:
If someone can review that, I'd appreciate it.
Comment #9
robertoperuzzoComment #11
lussolucaCommitted to 1.2.0-beta1. Thanks!