Load candidate bodies from the vault, score, and rank them — the final ranked context items, truncated to `limit`.
(
repo: &Repository,
candidates: HashMap<String, CandidateScore>,
limit: usize,
include_body: bool,
)
| 513 | /// Load candidate bodies from the vault, score, and rank them — the |
| 514 | /// final ranked context items, truncated to `limit`. |
| 515 | fn resolve_and_rank( |
| 516 | repo: &Repository, |
| 517 | candidates: HashMap<String, CandidateScore>, |
| 518 | limit: usize, |
| 519 | include_body: bool, |
| 520 | ) -> Result<Vec<ContextItem>, Status> { |
| 521 | let now = chrono::Utc::now(); |
| 522 | let mut items: Vec<ContextItem> = Vec::new(); |
| 523 | |
| 524 | for (node_id, candidate) in candidates { |
| 525 | let Some(path) = candidate |
| 526 | .path |
| 527 | .clone() |
| 528 | .or_else(|| memory_node_id_to_path(&node_id)) |
| 529 | else { |
| 530 | continue; |
| 531 | }; |
| 532 | let Some(entry) = repo.vault_retrieve(&path).map_err(repository_error)? else { |
| 533 | continue; // stale KG node — the entry no longer exists |
| 534 | }; |
| 535 | |
| 536 | if !is_eligible_memory(&entry) { |
| 537 | continue; |
| 538 | } |
| 539 | let kind = frontmatter_kind(&entry.frontmatter_json); |
| 540 | let Some(status) = frontmatter_status(&entry.frontmatter_json) else { |
| 541 | continue; |
| 542 | }; |
| 543 | |
| 544 | let memory_id = |
| 545 | frontmatter_memory_id(&entry.frontmatter_json).unwrap_or_else(|| node_id.clone()); |
| 546 | let name = frontmatter_name(&entry.frontmatter_json).unwrap_or_else(|| { |
| 547 | std::path::Path::new(&path) |
| 548 | .file_stem() |
| 549 | .unwrap_or_default() |
| 550 | .to_string_lossy() |
| 551 | .into_owned() |
| 552 | }); |
| 553 | let recency = recency_score(&entry.updated_at, now); |
| 554 | let body = if include_body { |
| 555 | String::from_utf8_lossy(&entry.content_bytes) |
| 556 | .trim() |
| 557 | .to_string() |
| 558 | } else { |
| 559 | String::new() |
| 560 | }; |
| 561 | items.push(ContextItem { |
| 562 | memory_id, |
| 563 | kg_node_id: node_id, |
| 564 | revision_hash: vault_entry_revision_hash(&entry), |
| 565 | content_hash: atomic_core::types::Hash::from_bytes(entry.content_hash).to_base32(), |
| 566 | path, |
| 567 | name, |
| 568 | kind, |
| 569 | status, |
| 570 | updated_at: entry.updated_at.clone(), |
| 571 | introduced_by: entry.introduced_by, |
| 572 | score: final_score(&candidate, recency), |
no test coverage detected