pub struct SessionView { /* private fields */ }Expand description
A session-scoped, ephemeral semantic view over this conversation’s chain chunks (ADR-058 Phase 3.1).
Holds a per-session HNSW (so queries are structurally scoped) plus a
manifest of chain_seq → [ChunkMeta]. Disposable: drop it at session end;
rebuild it from the chain by re-inserting this session’s events.
Implementations§
Source§impl SessionView
impl SessionView
Sourcepub fn for_embedder(
session_id: impl Into<String>,
embedder: &dyn EmbeddingProvider,
) -> Self
pub fn for_embedder( session_id: impl Into<String>, embedder: &dyn EmbeddingProvider, ) -> Self
Create an empty session view sized to embedder’s output dimension
(ADR-059 Qwen3 = 512; Mock fallback = its own dim). Preferred
constructor so the index and the embedder can never disagree on width.
Sourcepub fn new(session_id: impl Into<String>, dims: usize) -> Self
pub fn new(session_id: impl Into<String>, dims: usize) -> Self
Create an empty session view whose ephemeral index expects dims-wide
vectors (use the embedder’s dimensions;
ADR-059 Qwen3 = 512, Mock fallback = its own dim).
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The conversation/session id this view is scoped to.
Sourcepub fn chain_seqs(&self) -> Vec<u64>
pub fn chain_seqs(&self) -> Vec<u64>
The chain sequences indexed in this view (the rebuild manifest).
Sourcepub fn chunk(&self, chain_seq: u64) -> Option<ChunkMeta>
pub fn chunk(&self, chain_seq: u64) -> Option<ChunkMeta>
Fetch a chunk’s metadata by chain sequence.
Sourcepub fn insert_vector(&self, vector: Vec<f32>, meta: ChunkMeta) -> bool
pub fn insert_vector(&self, vector: Vec<f32>, meta: ChunkMeta) -> bool
Insert a pre-embedded chunk into the ephemeral index, keyed by chain
sequence. Low-level building block: 3.3 wraps this with the embedder and
blob externalization. Replaces any existing chunk for the same
chain_seq (idempotent re-graft / rebuild).
Returns false (and does not index) when vector does not match the
view’s dimensionality — callers must embed with the configured model.
Sourcepub fn query(&self, query: &[f32], top_k: usize) -> Vec<ScopedHit>
pub fn query(&self, query: &[f32], top_k: usize) -> Vec<ScopedHit>
Query the session-scoped index for the top_k nearest chunks.
Because the index holds only this session’s chunks, results are structurally scoped — a hit can only be from this conversation.
Sourcepub fn graft(&self, query: &[f32], top_k: usize) -> Vec<GraftedItem>
pub fn graft(&self, query: &[f32], top_k: usize) -> Vec<GraftedItem>
Graft the top_k most relevant chunks into the working set (ADR-058
Phase 3.2).
Scoped query → candidate branches → COW-reference graft: returns
chain-sequence-keyed GraftedItems with provenance backrefs
(chain_seq + content_hash) and a content reference (inline / blob /
bare). Candidates are deduplicated by content hash — identical tool
outputs or repeated file reads collapse to one item (the highest-scoring
occurrence). The origin is never removed; this only references it.
Sourcepub async fn index_chunk(
&self,
embedder: &dyn EmbeddingProvider,
store: Option<&ArtifactStore>,
chain_seq: u64,
kind: impl Into<String>,
text: &str,
inline_max: usize,
) -> Result<bool, EmbeddingError>
pub async fn index_chunk( &self, embedder: &dyn EmbeddingProvider, store: Option<&ArtifactStore>, chain_seq: u64, kind: impl Into<String>, text: &str, inline_max: usize, ) -> Result<bool, EmbeddingError>
Embed and index one chain event into the session view (ADR-058 Phase 3.3).
Embeds text with the ADR-059 embedder (store f32; Qwen3 = @512)
and indexes the vector keyed by chain_seq. When text exceeds
inline_max bytes and an ArtifactStore is supplied, the full text is
written as an RVF content-addressed blob and the chunk holds only the
blob hash (no chain bloat, free dedup); otherwise the text rides inline.
The chunk enters as NodeState::Frontier (live in the window).
Returns Ok(false) only if the embedder produced a vector whose width
disagrees with the view (guarded against; use for_embedder).
Sourcepub async fn index_chunk_with_embed(
&self,
embedder: &dyn EmbeddingProvider,
store: Option<&ArtifactStore>,
chain_seq: u64,
kind: impl Into<String>,
text: &str,
embed_input: &str,
inline_max: usize,
) -> Result<bool, EmbeddingError>
pub async fn index_chunk_with_embed( &self, embedder: &dyn EmbeddingProvider, store: Option<&ArtifactStore>, chain_seq: u64, kind: impl Into<String>, text: &str, embed_input: &str, inline_max: usize, ) -> Result<bool, EmbeddingError>
Like index_chunk, but embeds embed_input while
storing / hashing text (WEFT-640).
Used when the passage lane is a verbalized atom (text +
classification + voice cues) but the grafted payload must remain the
original turn text for the prompt. Content hash is over text so
dedup stays content-stable across verbalizer format bumps.
Sourcepub async fn graft_text(
&self,
embedder: &dyn EmbeddingProvider,
query_text: &str,
top_k: usize,
) -> Result<Vec<GraftedItem>, EmbeddingError>
pub async fn graft_text( &self, embedder: &dyn EmbeddingProvider, query_text: &str, top_k: usize, ) -> Result<Vec<GraftedItem>, EmbeddingError>
Convenience: embed a free-text query with embedder and graft the
top_k nearest chunks (ADR-058 Phase 3.2 + 3.3, query side).
Uses EmbeddingProvider::embed_query (not plain embed) so asymmetric
providers (e5 query: prefix, Qwen3 instruction) land queries in the
correct half of the space (WEFT-640). Symmetric backends default
embed_query → embed.
Sourcepub fn set_state(&self, chain_seq: u64, state: NodeState) -> bool
pub fn set_state(&self, chain_seq: u64, state: NodeState) -> bool
Set a chunk’s causal-model NodeState unconditionally. Returns
false if the chunk is unknown. Prefer transition
on the per-turn path so illegal lifecycle jumps are rejected.
Sourcepub fn state(&self, chain_seq: u64) -> Option<NodeState>
pub fn state(&self, chain_seq: u64) -> Option<NodeState>
The current causal-model state of a chunk, if known.
Sourcepub fn set_speculative(&self, chain_seq: u64) -> bool
pub fn set_speculative(&self, chain_seq: u64) -> bool
Mark a chunk NodeState::Speculative — above the wavefront, mutable,
not yet hash-chained (ADR-062 D2). This is the per-turn entry state the
kernel never assigned before P0.2. Returns false if unknown.
Sourcepub fn transition(&self, chain_seq: u64, next: NodeState) -> bool
pub fn transition(&self, chain_seq: u64, next: NodeState) -> bool
Advance a chunk through a validated lifecycle transition
(NodeState::can_transition_to, ADR-062 D2). Returns false if the
chunk is unknown or the transition is illegal (the chunk is left
unchanged in that case).
Sourcepub fn commit(&self, chain_seq: u64) -> bool
pub fn commit(&self, chain_seq: u64) -> bool
Commit a chunk to the durable trunk (NodeState::Committed) — the
Frontier→Committed step fired at EOU (ADR-062 D5). Validated; returns
false if unknown or not currently Frontier.
Sourcepub fn prune(&self, chain_seq: u64) -> bool
pub fn prune(&self, chain_seq: u64) -> bool
Prune a chunk from the live window (ADR-058 Phase 4.1).
Marks it NodeState::Stale but keeps it in the index — the origin
stays on the chain and the chunk is re-graftable via retrieval. This is
the application-level eviction that bounds L1 with no engine
--context-shift. Returns false if the chunk is unknown.
Sourcepub fn regraft(&self, chain_seq: u64) -> bool
pub fn regraft(&self, chain_seq: u64) -> bool
Re-graft a previously pruned chunk back into the live window
(NodeState::Frontier). The chunk was never removed from the index, so
this only flips its state. Returns false if unknown.
Sourcepub fn live_seqs(&self) -> Vec<u64>
pub fn live_seqs(&self) -> Vec<u64>
Chain sequences currently live in the window (NodeState::Frontier),
sorted ascending.
Sourcepub fn mark_important(&self, chain_seq: u64) -> bool
pub fn mark_important(&self, chain_seq: u64) -> bool
Mark a chunk “important to remember” — an explicit promotion signal
(ADR-058 Phase 4.2, e.g. from a memory_store tool call). Returns
false if the chunk is unknown.
Sourcepub fn is_important(&self, chain_seq: u64) -> bool
pub fn is_important(&self, chain_seq: u64) -> bool
Whether a chunk was explicitly marked important.
Auto Trait Implementations§
impl !Freeze for SessionView
impl !RefUnwindSafe for SessionView
impl Send for SessionView
impl Sync for SessionView
impl Unpin for SessionView
impl UnsafeUnpin for SessionView
impl UnwindSafe for SessionView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more