Skip to content

Context engine

Status: Current architecture guide for the implemented core.

The context engine is the typed retrieval substrate under newer context work. It does not replace ACA. ACA is the workspace control and knowledge plane; contextengine provides domain types, lane retrieval, evidence packs, and durable episode records that ACA and other callers can use.

The storage package defines a SQLite-backed store for nine entity families:

EntityPurpose
context_eventsAppend-only records of code, task, session, retrieval, and memory events
evidence_packsBundles returned by retrieval lanes
evidence_nodesIndividual pieces of evidence with typed refs
memory_claimsDurable claims and proposed memory facts
impact_edgesForward and reverse impact relationships
staleness_markersEvidence that may need refresh or invalidation
projectionsRebuilt views derived from events
retrieval_episodesAppend-only records of retrieval runs
retrieval_feedbackAppend-only feedback about retrieval quality

Large payloads can be stored in CAS instead of inline database rows.

Contextengine uses typed evidence refs instead of raw strings:

Ref typeExample use
pathSource file or document path
symbolCode symbol
taskTask or issue
sessionAgent or CLI session
memory_claimDurable memory claim
noteVault or docs note
artifactCAS artifact
trajectoryCaptured run or training episode
commitGit commit
eventContext event
runJob or command run
tool_callTool-call evidence

Evidence nodes also carry a node type and grounding value. Grounding separates loaded, indexed, semantic, inferred, and validated evidence so retrieval can show how strong the evidence is.

The context engine organizes retrieval into lanes:

LaneRole
codeCode search hits and snippets
memoryMemory claims and durable facts
contextTop-of-mind, handoffs, and ACA context packets
taskTask-local context and related tasks
mixedConcurrent lane fan-out and typed ref fusion

RetrieveMixed fans out to code, memory, context, and task lanes, then fuses results by EvidenceRef.Type plus EvidenceRef.Ref. Partial lane failures are recorded in metadata so callers can degrade instead of losing all evidence.

ACA owns workspace continuity and the knowledge-plane workflow:

  • .foxctl/runtime/top_of_mind.json
  • handoffs, observations, tensions, and proposals
  • Obsidian vault search and bridge reconciliation
  • retrieval inspection and correction proposals

Contextengine provides the typed retrieval representation:

  • EvidencePack
  • EvidenceNode
  • RetrievalEpisode
  • RetrievalFeedback
  • impact edges and stale markers

The clean boundary is:

ACA and callers decide what context is useful
-> contextengine records typed evidence and retrieval telemetry
-> stores keep episodes, feedback, projections, and large payload CAS refs
  • Events, retrieval episodes, and feedback are append-only.
  • Writes are serialized in-process to avoid local SQLite writer contention.
  • Clocks are injected for deterministic tests.
  • The storage layer imports domain types from internal/context/contextengine; the domain package stays pure.
  • Impact graph traversal is explicit through forward and reverse edge queries.

Use contextengine when a feature needs:

  • a typed evidence bundle instead of a loose prompt string
  • retrieval telemetry and feedback
  • cross-lane context fusion
  • impact or staleness records
  • repeatable retrieval evaluation

Use repoindex when the question is graph-shaped around code relationships. Use semantic search when the first problem is meaning-based candidate discovery.