feat: graph context injection — the session's prior knowledge, steered in at session start (vision-context-injection.md)
One shot per chat, fired at the first turn's onFinish: the session's topic (its only typed message) is embedded as an EmbeddingGemma retrieval query; the semantically closest graph propositions are selected under the session's token budget (pure budget, no similarity threshold — the decided doctrine) and delivered as a marker-only steer through the wake pipeline, queuing behind pending questions like every sub-agent result. - contracts: ChatSettings.graphContextTokens (default 1024, max 4096, step 128, 0 = off); GraphContextData + graphContextText; the graph-context JobKind + buildGraphContextSteer (id steer_ctx_<chatId>) - core/graph-context.ts: brute-force cosine top-K, greedy chars/4 fill under budget, most-recent UnderstandingLevel fold, count cap 64, parse-don't-cast at the marker seam - server: embedQuery (role-asymmetric query format, same warm singleton — vector-space parity by construction); the runner (startGraphContext- Injection one-shot gates; runGraphContextJob validates ledger parity); wake branches (chatIdOf/jobIdOf, finalizeJob done, recoverStaleJobs re-deliver or contextRespawn); abortJob kills context jobs SILENTLY (nothing was promised in the lesson); turn-service trigger seam - adapter: data-graph-context flattens to the canonical block (malformed parts have no model face) - UI: the budget slider (home dock + /chat/new draft, the session-data strip); the quiet SystemLine "~537 · 10 propositions"; dock kind "Knowledge context"; model-picker PUT now spreads settings (a model pick can no longer clear the sibling override) Live-smoked end to end on the real embedder + real GLM: seeded ledger (10 propositions), session on "modal logic: possible worlds and the necessity box" — job in the dock, queued behind the prober's question, delivered on the answer, SystemLine in the transcript, wake turn reads the block and continues the probe. Gates: tsc, lint, 459/459, build.
This commit is contained in:
@@ -21,6 +21,7 @@ import { pendingQuizAnswers } from "../core/graph.ts";
|
||||
import type { ChatStore, GraphStore } from "../core/ports.ts";
|
||||
import { EXTRACTION } from "../../config.ts";
|
||||
import type { ExtractionPipeline } from "../agent/subagents/extraction.ts";
|
||||
import { startGraphContextInjection, type GraphContextDeps } from "../agent/subagents/graph-context.ts";
|
||||
|
||||
/**
|
||||
* The canonical state write: the client owns the message list between turns
|
||||
@@ -98,3 +99,22 @@ export function triggerExtraction(
|
||||
console.error(`[chat ${chatId}] extraction trigger failed:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The graph READ channel (vision-context-injection.md): one shot per chat,
|
||||
* at session start — the first typed message is the session's topic; the
|
||||
* semantically closest propositions are selected under the session's token
|
||||
* budget and steered in through the wake pipeline. Fire-and-forget like
|
||||
* triggerExtraction; the one-shot gates (topic, budget, prior injection)
|
||||
* live in the runner module, not here — this seam only decides WHEN to ask.
|
||||
* Skipped under tests, same doctrine: the runner is tested directly with a
|
||||
* scripted embedder.
|
||||
*/
|
||||
export function triggerGraphContext(deps: GraphContextDeps, chatId: string): void {
|
||||
if (process.env.NODE_ENV === "test") return;
|
||||
try {
|
||||
startGraphContextInjection(deps, chatId);
|
||||
} catch (err) {
|
||||
console.error(`[chat ${chatId}] graph-context trigger failed:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user