Seed query terms and graph-neighbor candidates from an intent.
(
repo: &Repository,
intent_id: &str,
seed_terms: &mut Vec<String>,
candidates: &mut HashMap<String, CandidateScore>,
)
| 458 | |
| 459 | /// Seed query terms and graph-neighbor candidates from an intent. |
| 460 | fn seed_from_intent( |
| 461 | repo: &Repository, |
| 462 | intent_id: &str, |
| 463 | seed_terms: &mut Vec<String>, |
| 464 | candidates: &mut HashMap<String, CandidateScore>, |
| 465 | ) -> Result<(), Status> { |
| 466 | let manifest = repo.vault_manifest().map_err(repository_error)?; |
| 467 | let Some((resolved_id, summary)) = manifest |
| 468 | .intents |
| 469 | .iter() |
| 470 | .find(|(id, _)| id.eq_ignore_ascii_case(intent_id)) |
| 471 | else { |
| 472 | return Err(domain_status( |
| 473 | ErrorCode::NotFound, |
| 474 | format!("vault intent '{intent_id}' not found"), |
| 475 | )); |
| 476 | }; |
| 477 | |
| 478 | seed_terms.push(summary.title.clone()); |
| 479 | |
| 480 | // Legacy manifest entries may not carry `vault_path`; resolve the |
| 481 | // path rather than querying the empty and meaningless KG node. |
| 482 | let intent_path = repo |
| 483 | .vault_intent_path(resolved_id) |
| 484 | .map_err(repository_error)? |
| 485 | .ok_or_else(|| { |
| 486 | domain_status( |
| 487 | ErrorCode::NotFound, |
| 488 | format!("vault intent '{intent_id}' not found"), |
| 489 | ) |
| 490 | })?; |
| 491 | |
| 492 | if let Some(entry) = repo |
| 493 | .vault_retrieve(&intent_path) |
| 494 | .map_err(repository_error)? |
| 495 | { |
| 496 | seed_terms.extend(frontmatter_labels(&entry.frontmatter_json)); |
| 497 | let body = String::from_utf8_lossy(&entry.content_bytes); |
| 498 | let body = truncate_chars(body.trim(), INTENT_BODY_SEED_CHARS); |
| 499 | if !body.is_empty() { |
| 500 | seed_terms.push(body); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | if let Ok(node_id) = iri::mint_intent( |
| 505 | &repo.project_id().map_err(repository_error)?, |
| 506 | &summary.uid.to_uppercase(), |
| 507 | ) { |
| 508 | add_memory_neighbors(repo, &node_id, 2, candidates)?; |
| 509 | } |
| 510 | Ok(()) |
| 511 | } |
| 512 | |
| 513 | /// Load candidate bodies from the vault, score, and rank them — the |
| 514 | /// final ranked context items, truncated to `limit`. |
no test coverage detected