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

Function resolve_and_rank

libatomic/src/daemon/services_agent.rs:515–589  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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),

Callers 1

context_itemsFunction · 0.70

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

Tested by

no test coverage detected