perf: bound graph-memory recall token injection - #73
Open
Liyuk wants to merge 1 commit into
Open
Conversation
The recall context is injected on every prompt assembly. Several unbounded inputs let it grow with graph size: - tokenBudget was accepted but ignored (hardcoded 0): every recalled node was injected in full regardless of budget. - Node content was injected verbatim, including a leading name line that duplicates the XML name attribute. - Precise and generalized recall paths each ran to the full limit and were merged with only dedup, doubling node count (12 instead of 6). - Episodic provenance pulled top-3 nodes x 2 sessions at up to 500 chars. - System prompt boilerplate and per-node updated timestamps were verbose. Changes: - assemble.ts: enforce tokenBudget (greedy, highest-priority node first, always keeps >=1 node); strip the leading content name line; truncate content to contentMaxChars (default 400); tighten episodic to top-2 x 300 chars x 150 chars/msg; drop updated timestamps; condense the system prompt boilerplate. - recall.ts: precise path wins; the generalized path only backfills communities the precise path missed, capped at recallMaxNodes. - types.ts + dsh.ts + index.ts: wire recallTokenBudget (default 2000) and contentMaxChars (default 400) through config; 0 = unbounded (backward compatible). Measured on a real 897-node graph: 12->6 nodes/query and ~49% fewer injected tokens per query (2781->1424 avg). Recall quality is preserved because full node content stays available via gm_search.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
graph-memory:recall上下文在每轮 prompt 组装时都会注入。现有实现里有几处「无上限」的输入,让它随图谱规模线性膨胀:tokenBudget是死参数:dsh.ts/index.ts写死tokenBudget: 0,assembleContext收了参数却全量放入、不裁剪。name(XML 标签已有name=属性,首行纯冗余)。updated时间戳冗长。改动
assemble.tstokenBudget(贪心裁剪,最高优先级先保留,至少保留 1 个节点)stripLeadingName)contentMaxChars(默认 400)截断,附省略号updated时间戳、精简系统提示模板recall.ts:精确路径优先,泛化路径只回填精确路径未覆盖的社区,总量封顶recallMaxNodestypes.ts+dsh.ts+index.ts:通过 config 接线recallTokenBudget(默认 2000)与contentMaxChars(默认 400);传0= 不限制(向后兼容)实测
在真实 897 节点、923 边、250 社区的图谱上跑 5 条查询:
召回质量不降:完整节点 content 仍可通过
gm_search按需取回。兼容性
tokenBudget/contentMaxChars传0即回到旧行为。