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

Method gather_candidates

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

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

Calls 15

seed_from_intentMethod · 0.80
scan_memory_bodiesMethod · 0.80
has_explicit_seedsMethod · 0.80
vault_listMethod · 0.80
vault_retrieveMethod · 0.80
add_memory_neighborsFunction · 0.70
rank_scoreFunction · 0.70
merge_candidateFunction · 0.70
memory_path_from_nodeFunction · 0.70
is_eligible_memoryFunction · 0.70
memory_path_to_node_idFunction · 0.70