mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
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:
parent
a22d502248
commit
b0d0338f21
@ -138,7 +138,7 @@ class ResultItem(BaseModel, ABC, extra=Extra.allow):
|
|||||||
"""Abstract class that represents a result item."""
|
"""Abstract class that represents a result item."""
|
||||||
|
|
||||||
Id: Optional[str]
|
Id: Optional[str]
|
||||||
"""The ID of the item."""
|
"""The ID of the relevant result item."""
|
||||||
DocumentId: Optional[str]
|
DocumentId: Optional[str]
|
||||||
"""The document ID."""
|
"""The document ID."""
|
||||||
DocumentURI: Optional[str]
|
DocumentURI: Optional[str]
|
||||||
@ -156,8 +156,13 @@ class ResultItem(BaseModel, ABC, extra=Extra.allow):
|
|||||||
|
|
||||||
def get_additional_metadata(self) -> dict:
|
def get_additional_metadata(self) -> dict:
|
||||||
"""Document additional metadata dict.
|
"""Document additional metadata dict.
|
||||||
This returns any extra metadata except these values:
|
This returns any extra metadata except these:
|
||||||
['source', 'title', 'excerpt' and 'document_attributes'].
|
* result_id
|
||||||
|
* document_id
|
||||||
|
* source
|
||||||
|
* title
|
||||||
|
* excerpt
|
||||||
|
* document_attributes
|
||||||
"""
|
"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@ -173,6 +178,8 @@ class ResultItem(BaseModel, ABC, extra=Extra.allow):
|
|||||||
metadata = self.get_additional_metadata()
|
metadata = self.get_additional_metadata()
|
||||||
metadata.update(
|
metadata.update(
|
||||||
{
|
{
|
||||||
|
"result_id": self.Id,
|
||||||
|
"document_id": self.DocumentId,
|
||||||
"source": self.DocumentURI,
|
"source": self.DocumentURI,
|
||||||
"title": self.get_title(),
|
"title": self.get_title(),
|
||||||
"excerpt": self.get_excerpt(),
|
"excerpt": self.get_excerpt(),
|
||||||
|
Loading…
Reference in New Issue
Block a user