dedup nodes across seed neighborhoods in prompt building

Track which nodes have already been included and skip duplicates.
High-degree seed nodes with overlapping neighborhoods were pulling
the same big nodes dozens of times, inflating prompts to 878KB.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kent Overstreet 2026-03-22 12:33:06 -04:00
parent a8b560b5e1
commit b402746070

View file

@ -268,9 +268,12 @@ fn resolve(
"siblings" | "neighborhood" => { "siblings" | "neighborhood" => {
let mut out = String::new(); let mut out = String::new();
let mut all_keys: Vec<String> = Vec::new(); let mut all_keys: Vec<String> = Vec::new();
let mut included_nodes: std::collections::HashSet<String> = std::collections::HashSet::new();
const MAX_NEIGHBORS: usize = 25; const MAX_NEIGHBORS: usize = 25;
for key in keys { for key in keys {
if included_nodes.contains(key) { continue; }
included_nodes.insert(key.clone());
let Some(node) = store.nodes.get(key.as_str()) else { continue }; let Some(node) = store.nodes.get(key.as_str()) else { continue };
let neighbors = graph.neighbors(key); let neighbors = graph.neighbors(key);
@ -325,6 +328,8 @@ fn resolve(
let mut budget_exceeded = false; let mut budget_exceeded = false;
for (nbr, strength, _score) in &included { for (nbr, strength, _score) in &included {
if included_nodes.contains(nbr) { continue; }
included_nodes.insert(nbr.clone());
if let Some(n) = store.nodes.get(nbr.as_str()) { if let Some(n) = store.nodes.get(nbr.as_str()) {
if budget_exceeded || out.len() > NEIGHBORHOOD_BUDGET { if budget_exceeded || out.len() > NEIGHBORHOOD_BUDGET {
// Header-only: key + first non-empty line // Header-only: key + first non-empty line