MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resolve_and_rank

Function resolve_and_rank

atomic-cli/src/commands/vault/context.rs:471–542  ·  view source on GitHub ↗

Load candidate bodies from the vault, score, and rank them.

(
    repo: &Repository,
    candidates: HashMap<String, CandidateScore>,
    limit: usize,
    include_body: bool,
)

Source from the content-addressed store, hash-verified

469
470/// Load candidate bodies from the vault, score, and rank them.
471fn resolve_and_rank(
472 repo: &Repository,
473 candidates: HashMap<String, CandidateScore>,
474 limit: usize,
475 include_body: bool,
476) -> CliResult<Vec<MemoryItem>> {
477 let now = chrono::Utc::now();
478 let mut items: Vec<MemoryItem> = Vec::new();
479
480 for (node_id, candidate) in candidates {
481 let Some(path) = candidate
482 .path
483 .clone()
484 .or_else(|| legacy_memory_node_id_to_path(&node_id))
485 else {
486 continue;
487 };
488 let Some(entry) = repo.vault_retrieve(&path).map_err(CliError::Repository)? else {
489 continue; // stale KG node — the entry no longer exists
490 };
491
492 if !is_eligible_memory(&entry) {
493 continue;
494 }
495 let kind = frontmatter_kind(&entry.frontmatter_json);
496 let Some(status) = frontmatter_status(&entry.frontmatter_json) else {
497 continue;
498 };
499
500 let memory_id =
501 frontmatter_memory_id(&entry.frontmatter_json).unwrap_or_else(|| node_id.clone());
502 let name = frontmatter_name(&entry.frontmatter_json).unwrap_or_else(|| {
503 node_id
504 .rsplit_once(':')
505 .map(|(_, n)| n)
506 .unwrap_or(&node_id)
507 .to_string()
508 });
509 let recency = recency_score(&entry.updated_at, now);
510 items.push(MemoryItem {
511 memory_id,
512 kg_node_id: node_id,
513 revision_hash: vault_entry_revision_hash(&entry),
514 content_hash: Hash::from_bytes(entry.content_hash).to_base32(),
515 path,
516 name,
517 kind,
518 status,
519 updated_at: entry.updated_at.clone(),
520 introduced_by: entry.introduced_by,
521 score: final_score(&candidate, recency),
522 why_matched: why_matched(&candidate).to_string(),
523 body: if include_body {
524 String::from_utf8_lossy(&entry.content_bytes)
525 .trim()
526 .to_string()
527 } else {
528 String::new()

Calls 15

is_eligible_memoryFunction · 0.85
frontmatter_kindFunction · 0.85
frontmatter_statusFunction · 0.85
frontmatter_memory_idFunction · 0.85
frontmatter_nameFunction · 0.85
recency_scoreFunction · 0.85
final_scoreFunction · 0.85
why_matchedFunction · 0.85
vault_retrieveMethod · 0.80
partial_cmpMethod · 0.80