(user_id: str, question: str = "", limit: int = 8)
| 4286 | paper.get("categories"), |
| 4287 | metadata.get("category"), |
| 4288 | metadata.get("keywords"), |
| 4289 | metadata.get("subjects"), |
| 4290 | metadata.get("categories"), |
| 4291 | ] |
| 4292 | return " ".join( |
| 4293 | " ".join(_compact_list(piece, limit=12)) if isinstance(piece, (list, tuple)) else str(piece or "") |
| 4294 | for piece in pieces |
| 4295 | ).lower() |
| 4296 | |
| 4297 | |
| 4298 | def _recent_paper_context_nodes(user_id: str, question: str = "", limit: int = 8) -> List[Dict[str, Any]]: |
| 4299 | try: |
| 4300 | papers = db_ops.get_recent_pushes(user_id, limit=max(12, min(50, int(limit or 8) * 4))) or [] |
| 4301 | except Exception: |
| 4302 | papers = [] |
| 4303 | if not papers: |
| 4304 | try: |
| 4305 | latest = db_ops.get_latest_push(user_id) or {} |
| 4306 | except Exception: |
| 4307 | latest = {} |
| 4308 | papers = list(latest.get("papers") or [])[: max(12, min(50, int(limit or 8) * 4))] |
| 4309 | query_tokens = _local_paper_query_tokens(question) |
| 4310 | if query_tokens: |
| 4311 | matched = [paper for paper in papers if isinstance(paper, dict) and any(token in _paper_query_haystack(paper) for token in query_tokens)] |
| 4312 | if matched: |
| 4313 | papers = matched |
| 4314 | |
| 4315 | nodes: List[Dict[str, Any]] = [] |
| 4316 | seen: Set[str] = set() |
| 4317 | for index, paper in enumerate(papers, start=1): |
| 4318 | if not isinstance(paper, dict): |
| 4319 | continue |
| 4320 | title = str(paper.get("title") or "").strip() |
| 4321 | if not title: |
| 4322 | continue |
| 4323 | arxiv_id = _paper_arxiv_id(paper) |
| 4324 | key = arxiv_id or str(paper.get("doi") or paper.get("id") or title).strip() |
| 4325 | node_id = f"paper:{hashlib.sha1(key.encode('utf-8')).hexdigest()[:16]}" |
| 4326 | if node_id in seen: |
| 4327 | continue |
| 4328 | seen.add(node_id) |
| 4329 | authors = _compact_list(paper.get("authors"), limit=6) |
| 4330 | subjects = _compact_list(paper.get("subjects") or paper.get("categories"), limit=8) |
| 4331 | abstract = str(paper.get("abstract") or paper.get("summary") or "").strip() |
| 4332 | raw_metadata = paper.get("metadata") or {} |
| 4333 | metadata = raw_metadata if isinstance(raw_metadata, dict) else _load_json(raw_metadata, {}) |
| 4334 | if not isinstance(metadata, dict): |
| 4335 | metadata = {} |
| 4336 | push_id = paper.get("push_id") or metadata.get("push_id") |
| 4337 | rank = paper.get("rank") or metadata.get("rank") |
| 4338 | score = paper.get("score") or paper.get("relevance") or metadata.get("score") |
| 4339 | category = paper.get("category") or metadata.get("category") |
| 4340 | body_parts = [ |
| 4341 | f"Recent PaperFlow pushed paper #{index}.", |
| 4342 | f"Title: {title}", |
| 4343 | f"Authors: {', '.join(authors)}" if authors else "", |
| 4344 | f"Subjects: {', '.join(subjects)}" if subjects else "", |
| 4345 | f"Category: {category}" if category else "", |
nothing calls this directly
no test coverage detected