-
Notifications
You must be signed in to change notification settings - Fork 74
feat: retrival add raw api metrics calculate #437
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -131,6 +131,34 @@ def compute_query_metrics( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def build_raw_api_ranked_doc_ids( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| top_api_results: list[dict[str, Any]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> list[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Build a ranked doc-id list that preserves raw API ranks for metrics. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Unmatched hits and duplicate resolved corpus IDs are kept as unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| non-relevant placeholders so later API hits do not move upward. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ranked: list[str] = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seen_resolved_ids: set[str] = set() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for index, result in enumerate(top_api_results, start=1): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rank = result.get("rank") or index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resolved_id = str(result.get("resolved_corpus_id") or "").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not resolved_id: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ranked.append(f"__raw_api_unmatched__{rank}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if resolved_id in seen_resolved_ids: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ranked.append(f"__raw_api_duplicate__{rank}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seen_resolved_ids.add(resolved_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ranked.append(resolved_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+142
to
+154
Contributor
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. In
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ranked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def prefix_metrics(metrics: dict[str, Any], prefix: str) -> dict[str, Any]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {f"{prefix}{key}": value for key, value in metrics.items()} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def resolve_hit( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hit: dict[str, Any], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title_index: dict[str, list[str]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Using
trace.get("queries", [])can raise aTypeError: 'NoneType' object is not iterableif the"queries"key is explicitly set toNonein the trace dictionary. Usingtrace.get("queries") or []is more robust and consistent with the defensive pattern used on line 350 (query.get("raw_api_metrics") or {}).