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

Method gather_candidates

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

Gather candidate memory nodes from all seeds. Returns a map of memory node id -> accumulated candidate score. With no seeds at all, falls back to the most recently updated memories so a bare `atomic vault context` is still useful.

(
        &self,
        repo: &Repository,
        limit: usize,
    )

Source from the content-addressed store, hash-verified

224 /// With no seeds at all, falls back to the most recently updated
225 /// memories so a bare `atomic vault context` is still useful.
226 fn gather_candidates(
227 &self,
228 repo: &Repository,
229 limit: usize,
230 ) -> CliResult<HashMap<String, CandidateScore>> {
231 let mut candidates: HashMap<String, CandidateScore> = HashMap::new();
232 let mut seed_terms: Vec<String> = self.query.clone();
233
234 if let Some(intent_id) = &self.intent {
235 self.seed_from_intent(repo, intent_id, &mut seed_terms, &mut candidates)?;
236 }
237
238 for file in &self.files {
239 let node_id = format!("file:{}", file.trim_start_matches("./"));
240 add_memory_neighbors(repo, &node_id, 1, &mut candidates)?;
241 }
242
243 let seed_query = seed_terms.join(" ");
244 if !seed_query.trim().is_empty() {
245 let pool = limit.saturating_mul(SEARCH_POOL_MULTIPLIER);
246 let nodes = repo
247 .vault_kg_search_by_kind(&seed_query, pool, "memory")
248 .map_err(CliError::Repository)?;
249 for (rank, node) in nodes.iter().enumerate() {
250 let base = rank_score(rank);
251 merge_candidate(
252 &mut candidates,
253 &node.id,
254 memory_path_from_node(node),
255 base,
256 false,
257 );
258 }
259 self.scan_memory_bodies(repo, &seed_query, &mut candidates)?;
260 }
261
262 // No seeds of any kind: fall back to the most recent memories.
263 if candidates.is_empty() && !self.has_explicit_seeds() {
264 let mut metas = repo
265 .vault_list("memory/", Some(VaultEntryType::Memory))
266 .map_err(CliError::Repository)?;
267 metas.sort_by(|a, b| b.updated_at.cmp(&a.updated_at));
268 for meta in metas {
269 let Some(entry) = repo
270 .vault_retrieve(&meta.path)
271 .map_err(CliError::Repository)?
272 else {
273 continue;
274 };
275 if !is_eligible_memory(&entry) {
276 continue;
277 }
278 if let Some(node_id) = memory_path_to_node_id(&meta.path) {
279 merge_candidate(&mut candidates, &node_id, Some(meta.path), 0.0, false);
280 }
281 if candidates.len() >= limit {
282 break;
283 }

Calls 15

add_memory_neighborsFunction · 0.85
rank_scoreFunction · 0.85
merge_candidateFunction · 0.85
memory_path_from_nodeFunction · 0.85
is_eligible_memoryFunction · 0.85
memory_path_to_node_idFunction · 0.85
seed_from_intentMethod · 0.80
scan_memory_bodiesMethod · 0.80
has_explicit_seedsMethod · 0.80
vault_listMethod · 0.80
cmpMethod · 0.80