Skip to main content

SessionView

Struct SessionView 

Source
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

Source

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.

Source

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).

Source

pub fn session_id(&self) -> &str

The conversation/session id this view is scoped to.

Source

pub fn dims(&self) -> usize

Vector dimensionality of the ephemeral index.

Source

pub fn len(&self) -> usize

Number of chunks indexed in this session view.

Source

pub fn is_empty(&self) -> bool

true when no chunks have been indexed yet.

Source

pub fn chain_seqs(&self) -> Vec<u64>

The chain sequences indexed in this view (the rebuild manifest).

Source

pub fn chunk(&self, chain_seq: u64) -> Option<ChunkMeta>

Fetch a chunk’s metadata by chain sequence.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn state(&self, chain_seq: u64) -> Option<NodeState>

The current causal-model state of a chunk, if known.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn live_seqs(&self) -> Vec<u64>

Chain sequences currently live in the window (NodeState::Frontier), sorted ascending.

Source

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.

Source

pub fn is_important(&self, chain_seq: u64) -> bool

Whether a chunk was explicitly marked important.

Source

pub fn ref_count(&self, chain_seq: u64) -> u32

How many times a chunk has been grafted/recalled (a promotion signal).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more