Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional id_field to VertexRank #217

Merged
merged 7 commits into from
May 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion libs/community/langchain_google_community/vertex_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class VertexAIRank(BaseDocumentCompressor):
If true, the response will contain only
record ID and score. By default, it is false,
the response will contain record details.
id_field (Optional[str]): Specifies a unique document metadata field
to use as an id.
title_field (Optional[str]): Specifies the document metadata field
to use as title.
credentials (Optional[Credentials]): Google Cloud credentials object.
Expand All @@ -55,6 +57,7 @@ class VertexAIRank(BaseDocumentCompressor):
model: str = Field(default="semantic-ranker-512@latest")
top_n: int = Field(default=10)
ignore_record_details_in_response: bool = Field(default=False)
id_field: Optional[str] = Field(default=None)
title_field: Optional[str] = Field(default=None)
credentials: Optional[Credentials] = Field(default=None)
credentials_path: Optional[str] = Field(default=None)
Expand Down Expand Up @@ -114,7 +117,11 @@ def _rerank_documents(

records = [
discoveryengine_v1alpha.RankingRecord(
id=str(idx),
id=(
doc.metadata.get(self.id_field)
lkuligin marked this conversation as resolved.
Show resolved Hide resolved
if self.id_field
else str(idx)
),
content=doc.page_content,
**(
{"title": doc.metadata.get(self.title_field)}
Expand Down
Loading