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

Function resolve_and_rank

atomic-cli/src/commands/vault/context.rs:503–574  ·  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

501
502/// Load candidate bodies from the vault, score, and rank them.
503fn resolve_and_rank(
504 repo: &Repository,
505 candidates: HashMap<String, CandidateScore>,
506 limit: usize,
507 include_body: bool,
508) -> CliResult<Vec<MemoryItem>> {
509 let now = chrono::Utc::now();
510 let mut items: Vec<MemoryItem> = Vec::new();
511
512 for (node_id, candidate) in candidates {
513 let Some(path) = candidate
514 .path
515 .clone()
516 .or_else(|| memory_node_id_to_path(&node_id))
517 else {
518 continue;
519 };
520 let Some(entry) = repo.vault_retrieve(&path).map_err(CliError::Repository)? else {
521 continue; // stale KG node — the entry no longer exists
522 };
523
524 if !is_eligible_memory(&entry) {
525 continue;
526 }
527 let kind = frontmatter_kind(&entry.frontmatter_json);
528 let Some(status) = frontmatter_status(&entry.frontmatter_json) else {
529 continue;
530 };
531
532 let memory_id =
533 frontmatter_memory_id(&entry.frontmatter_json).unwrap_or_else(|| node_id.clone());
534 let name = frontmatter_name(&entry.frontmatter_json).unwrap_or_else(|| {
535 std::path::Path::new(&path)
536 .file_stem()
537 .unwrap_or_default()
538 .to_string_lossy()
539 .into_owned()
540 });
541 let recency = recency_score(&entry.updated_at, now);
542 items.push(MemoryItem {
543 memory_id,
544 kg_node_id: node_id,
545 revision_hash: vault_entry_revision_hash(&entry),
546 content_hash: Hash::from_bytes(entry.content_hash).to_base32(),
547 path,
548 name,
549 kind,
550 status,
551 updated_at: entry.updated_at.clone(),
552 introduced_by: entry.introduced_by,
553 score: final_score(&candidate, recency),
554 why_matched: why_matched(&candidate).to_string(),
555 body: if include_body {
556 String::from_utf8_lossy(&entry.content_bytes)
557 .trim()
558 .to_string()
559 } else {
560 String::new()

Calls 15

vault_retrieveMethod · 0.80
truncateMethod · 0.80
memory_node_id_to_pathFunction · 0.70
is_eligible_memoryFunction · 0.70
frontmatter_kindFunction · 0.70
frontmatter_statusFunction · 0.70
frontmatter_memory_idFunction · 0.70
frontmatter_nameFunction · 0.70
recency_scoreFunction · 0.70
final_scoreFunction · 0.70
why_matchedFunction · 0.70