feat: expose Kendra result item id and document id as document metadata (#8796)

- Description: we expose Kendra result item id and document id as
document metadata.
  - Tag maintainer: @3coins @baskaryan 
  - Twitter handle: wilsonleao

**Why**
The result item id and document id might be used to keep track of the
retrieved resources.
This commit is contained in:
Wilson Leao Neto 2023-08-06 02:21:24 +02:00 committed by GitHub
parent a22d502248
commit b0d0338f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,7 +138,7 @@ class ResultItem(BaseModel, ABC, extra=Extra.allow):
"""Abstract class that represents a result item."""
Id: Optional[str]
"""The ID of the item."""
"""The ID of the relevant result item."""
DocumentId: Optional[str]
"""The document ID."""
DocumentURI: Optional[str]
@ -156,8 +156,13 @@ class ResultItem(BaseModel, ABC, extra=Extra.allow):
def get_additional_metadata(self) -> dict:
"""Document additional metadata dict.
This returns any extra metadata except these values:
['source', 'title', 'excerpt' and 'document_attributes'].
This returns any extra metadata except these:
* result_id
* document_id
* source
* title
* excerpt
* document_attributes
"""
return {}
@ -173,6 +178,8 @@ class ResultItem(BaseModel, ABC, extra=Extra.allow):
metadata = self.get_additional_metadata()
metadata.update(
{
"result_id": self.Id,
"document_id": self.DocumentId,
"source": self.DocumentURI,
"title": self.get_title(),
"excerpt": self.get_excerpt(),