pub struct DeserializedGrain {
pub header: MgHeader,
pub grain_type: GrainType,
pub fields: HashMap<String, Value>,
pub hash: Hash,
}Expand description
Deserialized grain data from an .mg blob.
Fields§
§header: MgHeader§grain_type: GrainType§fields: HashMap<String, Value>§hash: HashImplementations§
Source§impl DeserializedGrain
impl DeserializedGrain
Sourcepub fn base_text(&self) -> String
pub fn base_text(&self) -> String
Base text used by the recall reranker (query::extract_grain_text
delegates here). This is a cross-encoder scoring projection, NOT the
embedding projection — it intentionally differs from the typed
crate::types::Grain::text for non-Fact types (it scans a fixed
content-field list rather than reconstructing each type’s text()).
Fact → "subject relation object"; every other type → the first
non-empty of a fixed content-field list, falling back to the grain-type
name. Do NOT route the embedding backfill through this — use
Self::embedding_text, which reconstructs the typed grain and calls
the real crate::types::Grain::embedding_text for per-type parity
with the inline write path.
Sourcepub fn embedding_text(&self) -> String
pub fn embedding_text(&self) -> String
Reconstruct the embedding-input text for this stored grain, matching
crate::types::Grain::embedding_text of the live typed grain EXACTLY
so the backfill embeds the SAME text the inline write path embeds
(write.rs calls grain.embedding_text(); design §PR-3b step 4 / §R-6).
Parity is guaranteed by construction: instead of hand-replicating each
type’s text() projection (which silently drifts as types evolve), we
reconstruct the concrete typed grain from the deserialized fields and
delegate to its real Grain::embedding_text(). That trait method already
handles the explicit embedding_text override and the text() + [tags] + (namespace) auto-enrichment uniformly for all 11 grain types.
Returns an empty string when there is no text to embed (the caller then skips the grain — an empty projection must never be embedded).
Sourcepub fn to_tool(&self) -> Result<Tool>
pub fn to_tool(&self) -> Result<Tool>
Reconstruct an Tool from deserialized fields. Phase 1 (2026-04-19):
reads typed definition fields (input_schema, executor_uri,
locked_params, examples, annotations, spec_hash,
tool_description, strict, tool_call_id, call_batch_id,
kind) plus existing execution-record fields (tool_name, input,
content/tool_content, is_error, error, duration_ms,
parent_task_id, output_schema).
kind defaults to Execution when absent — preserves
backward-compatibility for any pre-Phase-1 grain that lacks the
discriminator.
Sourcepub fn to_event(&self) -> Result<Event>
pub fn to_event(&self) -> Result<Event>
Reconstruct an Event from deserialized fields, including the OMS 1.2 §8.2 chat-extension fields (role, session_id, parent_message_id, content_blocks, model_id, stop_reason, token_usage, run_id).
Sourcepub fn to_skill(&self) -> Result<Skill>
pub fn to_skill(&self) -> Result<Skill>
Reconstruct a Skill from deserialized fields (OMS 1.4 §8.11).
proficiency aliases common.confidence (D3): we read prof if
present, else fall back to cf (confidence), and write the result
into common.confidence. A writer that emits prof ≠ cf
is taken at its prof word for a Skill (spec is SHOULD, not MUST)
with a debug log — the only place the two could disagree.
Trait Implementations§
Source§impl Clone for DeserializedGrain
impl Clone for DeserializedGrain
Source§fn clone(&self) -> DeserializedGrain
fn clone(&self) -> DeserializedGrain
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more