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

Method gather_candidates

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

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

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