-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: reduce rerank payload size and timeout #1262
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
Open
Suidge
wants to merge
1
commit into
volcengine:main
Choose a base branch
from
Suidge:fix/rerank-latency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+29
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import heapq | ||
| import logging | ||
| import math | ||
| import os | ||
| import time | ||
| from datetime import datetime | ||
| from typing import Any, Dict, List, Optional, Tuple | ||
|
|
@@ -48,7 +49,13 @@ class HierarchicalRetriever: | |
| MAX_RELATIONS = 5 # Maximum relations per resource | ||
| SCORE_PROPAGATION_ALPHA = 0.5 # Score propagation coefficient | ||
| DIRECTORY_DOMINANCE_RATIO = 1.2 # Directory score must exceed max child score | ||
| GLOBAL_SEARCH_TOPK = 10 # Global retrieval count (more candidates = better rerank precision) | ||
| GLOBAL_SEARCH_TOPK = max(1, int(os.getenv("OPENVIKING_GLOBAL_SEARCH_TOPK", "6"))) | ||
| RECURSIVE_PREFILTER_MULTIPLIER = max( | ||
| 1, int(os.getenv("OPENVIKING_RECURSIVE_PREFILTER_MULTIPLIER", "2")) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest using config instead of env |
||
| ) | ||
| RECURSIVE_PREFILTER_MIN = max(1, int(os.getenv("OPENVIKING_RECURSIVE_PREFILTER_MIN", "8"))) | ||
| RERANK_MAX_DOC_CHARS = max(128, int(os.getenv("OPENVIKING_RERANK_MAX_DOC_CHARS", "600"))) | ||
| RERANK_MAX_QUERY_CHARS = max(64, int(os.getenv("OPENVIKING_RERANK_MAX_QUERY_CHARS", "500"))) | ||
| HOTNESS_ALPHA = 0.2 # Weight for hotness score in final ranking (0 = disabled) | ||
| LEVEL_URI_SUFFIX = {0: ".abstract.md", 1: ".overview.md"} | ||
|
|
||
|
|
@@ -247,6 +254,13 @@ async def _global_vector_search( | |
| telemetry.count("vector.scanned", len(results)) | ||
| return results | ||
|
|
||
| @classmethod | ||
| def _truncate_rerank_text(cls, text: str, max_chars: int) -> str: | ||
| text = str(text or "").strip() | ||
| if len(text) <= max_chars: | ||
| return text | ||
| return text[:max_chars].rstrip() | ||
|
|
||
| def _rerank_scores( | ||
| self, | ||
| query: str, | ||
|
|
@@ -257,8 +271,13 @@ def _rerank_scores( | |
| if not self._rerank_client or not documents: | ||
| return fallback_scores | ||
|
|
||
| truncated_query = self._truncate_rerank_text(query, self.RERANK_MAX_QUERY_CHARS) | ||
| truncated_documents = [ | ||
| self._truncate_rerank_text(doc, self.RERANK_MAX_DOC_CHARS) for doc in documents | ||
| ] | ||
|
|
||
| try: | ||
| scores = self._rerank_client.rerank_batch(query, documents) | ||
| scores = self._rerank_client.rerank_batch(truncated_query, truncated_documents) | ||
| except Exception as e: | ||
| logger.warning( | ||
| "[HierarchicalRetriever] Rerank failed, fallback to vector scores: %s", e | ||
|
|
@@ -418,7 +437,10 @@ def passes_threshold(score: float) -> bool: | |
| visited.add(current_uri) | ||
| logger.info(f"[RecursiveSearch] Entering URI: {current_uri}") | ||
|
|
||
| pre_filter_limit = max(limit * 2, 20) | ||
| pre_filter_limit = max( | ||
| limit * self.RECURSIVE_PREFILTER_MULTIPLIER, | ||
| self.RECURSIVE_PREFILTER_MIN, | ||
| ) | ||
|
|
||
| results = await vector_proxy.search_children_in_tenant( | ||
| parent_uri=current_uri, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be too small, any benchmark validated?