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,
)
| 190 | /// With no seeds at all, falls back to the most recently updated |
| 191 | /// memories so a bare `atomic vault context` is still useful. |
| 192 | fn gather_candidates( |
| 193 | &self, |
| 194 | repo: &Repository, |
| 195 | limit: usize, |
| 196 | ) -> CliResult<HashMap<String, CandidateScore>> { |
| 197 | let mut candidates: HashMap<String, CandidateScore> = HashMap::new(); |
| 198 | let mut seed_terms: Vec<String> = self.query.clone(); |
| 199 | |
| 200 | if let Some(intent_id) = &self.intent { |
| 201 | self.seed_from_intent(repo, intent_id, &mut seed_terms, &mut candidates)?; |
| 202 | } |
| 203 | |
| 204 | for file in &self.files { |
| 205 | let node_id = format!("file:{}", file.trim_start_matches("./")); |
| 206 | add_memory_neighbors(repo, &node_id, 1, &mut candidates)?; |
| 207 | } |
| 208 | |
| 209 | let seed_query = seed_terms.join(" "); |
| 210 | if !seed_query.trim().is_empty() { |
| 211 | let pool = limit.saturating_mul(SEARCH_POOL_MULTIPLIER); |
| 212 | let nodes = repo |
| 213 | .vault_kg_search_by_kind(&seed_query, pool, "memory") |
| 214 | .map_err(CliError::Repository)?; |
| 215 | for (rank, node) in nodes.iter().enumerate() { |
| 216 | let base = rank_score(rank); |
| 217 | merge_candidate( |
| 218 | &mut candidates, |
| 219 | &node.id, |
| 220 | memory_path_from_node(node), |
| 221 | base, |
| 222 | false, |
| 223 | ); |
| 224 | } |
| 225 | self.scan_memory_bodies(repo, &seed_query, &mut candidates)?; |
| 226 | } |
| 227 | |
| 228 | // No seeds of any kind: fall back to the most recent memories. |
| 229 | if candidates.is_empty() && !self.has_explicit_seeds() { |
| 230 | let mut metas = repo |
| 231 | .vault_list("memory/", Some(VaultEntryType::Memory)) |
| 232 | .map_err(CliError::Repository)?; |
| 233 | metas.sort_by(|a, b| b.updated_at.cmp(&a.updated_at)); |
| 234 | for meta in metas { |
| 235 | let Some(entry) = repo |
| 236 | .vault_retrieve(&meta.path) |
| 237 | .map_err(CliError::Repository)? |
| 238 | else { |
| 239 | continue; |
| 240 | }; |
| 241 | if !is_eligible_memory(&entry) { |
| 242 | continue; |
| 243 | } |
| 244 | if let Some(node_id) = memory_path_to_node_id(&meta.path) { |
| 245 | merge_candidate(&mut candidates, &node_id, Some(meta.path), 0.0, false); |
| 246 | } |
| 247 | if candidates.len() >= limit { |
| 248 | break; |
| 249 | } |