Could not load the items on Pinecone index following SearchApiPineconeBackend::search()

Created on 14 March 2024, 9 months ago

Problem/Motivation

When using the search function on SearchApiPineconeBackend, the result search item objects returned have use the ID of the chunked item, IE the ID in Pinecone.

This is not the ID that is tracked in the search_api index and the function Drupal\search_api\Entity\Index::loadItemsMultiple() does not transform them into an ID that can be loaded from a Drupal datasource.

Therefore, when Drupal\search_api\Entity\Index::loadItemsMultiple() is called on result items from SearchApiPineconeBackend::search(), it loads no items with the warning:
"Could not load the following items on index {index_name} ...".

Proposed resolution

Amend the SearchApiPineconeBackend::search() function to create one result item for every tracked item in the index. IE, combining all results from a single indexed Drupal entity that has been chunked into its fields in Pinecone, into one result item with the original Drupal entity's tracked ID.

The matches are ordered by 'score' descending to we should be able to take the first result of any given entity and know that is the most relevant result.

This allows search_api to load the items from the datasource.

API changes

Drupal\search_api\Item\Item::getId() will return the ID of the search_api tracked entity and not the ID of the item in Pinecone.

Other suggestions

This seemed like the best place to solve the issue, however, it may impact how the SearchApiPineconeBackend is being used on other sites and the metadata content that is returned with the result item will only contain the content from the most relevant chunk/field.

If anyone has suggestions of how I could better solve this, or if I'm looking at the problem wrong, please let me know. I am currently considering extending the SearchApiPineconeBackend to not chunk entities into fields and therefore keep the tracked ID in Pinecone. This will allow delete by ID too.

Thanks!

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024