(
paper: Dict[str, Any],
user_profile: Dict[str, Any],
parsed_pdf: Optional[Dict[str, Any]],
)
| 3349 | |
| 3350 | def _retrieve_report_evidence( |
| 3351 | paper: Dict[str, Any], |
| 3352 | user_profile: Dict[str, Any], |
| 3353 | parsed_pdf: Optional[Dict[str, Any]], |
| 3354 | ) -> Dict[str, Any]: |
| 3355 | chunks = _build_pdf_chunks(parsed_pdf) |
| 3356 | if not chunks: |
| 3357 | return {} |
| 3358 | |
| 3359 | profile_summary = _summarize_profile_for_embedding(user_profile) |
| 3360 | title = _clean_text(paper.get("title")) |
| 3361 | abstract = _clean_text(paper.get("abstract")) |
| 3362 | |
| 3363 | query_specs = [ |
| 3364 | { |
| 3365 | "bucket": "background", |
| 3366 | "query": f"{title}\n{abstract}\nresearch background motivation problem challenge prior work", |
| 3367 | "preferred_sections": ("abstract", "introduction", "background"), |
| 3368 | }, |
| 3369 | { |
| 3370 | "bucket": "method", |
| 3371 | "query": f"{title}\n{abstract}\ncore method approach model framework algorithm training pipeline", |
| 3372 | "preferred_sections": ("method", "approach", "model", "full_text"), |
| 3373 | }, |
| 3374 | { |
| 3375 | "bucket": "results", |
| 3376 | "query": f"{title}\n{abstract}\nmain results experiments evaluation outperform improvement benchmark ablation", |
| 3377 | "preferred_sections": ("results", "experiments", "evaluation"), |
| 3378 | }, |
| 3379 | { |
| 3380 | "bucket": "limitations", |
| 3381 | "query": f"{title}\n{abstract}\nlimitations future work discussion challenge failure case", |
| 3382 | "preferred_sections": ("discussion", "limitations", "conclusion"), |
| 3383 | }, |
| 3384 | { |
| 3385 | "bucket": "relevance", |
| 3386 | "query": ( |
| 3387 | f"{title}\n{abstract}\n" |
| 3388 | f"reader research interests relevance use cases methodology overlap {profile_summary}" |
| 3389 | ), |
| 3390 | "preferred_sections": ("abstract", "introduction", "method", "results"), |
| 3391 | }, |
| 3392 | ] |
| 3393 | |
| 3394 | try: |
| 3395 | embedding_module = _load_embedding_module() |
| 3396 | service = embedding_module.get_embedding_service() |
| 3397 | descriptor = getattr(service, "descriptor", "") |
| 3398 | cache_key = _build_evidence_cache_key(paper, user_profile, parsed_pdf, descriptor) |
| 3399 | cached = _load_cached_retrieved_evidence(cache_key) |
| 3400 | if cached: |
| 3401 | return cached |
| 3402 | query_texts = [item["query"] for item in query_specs] |
| 3403 | chunk_texts = [chunk["text"] for chunk in chunks] |
| 3404 | profile_query_text = profile_summary or title or abstract |
| 3405 | vectors = service.embed_batch(query_texts + chunk_texts + [profile_query_text]) |
| 3406 | query_vectors = vectors[: len(query_specs)] |
| 3407 | chunk_vectors = vectors[len(query_specs):len(query_specs) + len(chunk_texts)] |
| 3408 | profile_vector = vectors[-1] |
no test coverage detected