feat(context): CAM Phase 2-C/2-D — LLM compress + embedding semantic scoring#4626
Merged
Conversation
This was referenced May 29, 2026
This was
linked to
issues
May 29, 2026
Closed
16599e9 to
f02eb27
Compare
59cbe70 to
be5006e
Compare
…scoring Add two deferred CAM Phase 2 features to FidelityScorer: Phase 2-C (closes #4551): LLM-assisted Compressed rendering via `compress_provider`. When set, `render_compressed()` calls the named provider to generate a summary instead of truncating. The result is cached in `MessageMetadata.deferred_summary` and reused on subsequent turns. A 30 s timeout and a 2× token cost guard fall back to truncation on failure. Phase 2-D (closes #4552): embedding-based semantic scoring via `semantic_scoring_provider`. FidelityScorer embeds the query once per turn and computes cosine similarity against per-message embeddings cached in `MessageMetadata.embedding` (#[serde(skip)], in-memory only). Keyword-overlap remains the fallback when no provider is configured. `w_keyword` accepted as a deprecated alias for `w_semantic` in config. Both LLM/embed awaits are wrapped with `tokio::time::timeout(30s)`. `score_and_apply()` is now async and accepts separate `embed_provider` and `compress_provider` parameters. Also add disambiguation doc notes to `ContentFidelity` (zeph-memory optical forgetting) and `ContextFidelity` (zeph-common CAM) to prevent confusion between the two near-identical enum names (closes #4556).
be5006e to
fbb4803
Compare
…in fidelity tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Compressedrendering viaFidelityConfig.compress_provider. When set,render_compressed()calls the named provider to generate a high-quality summary instead of truncating. The result is cached inMessageMetadata.deferred_summaryand reused on subsequent turns. A 30 s timeout and a 2× token cost guard fall back to truncation silently on failure.FidelityConfig.semantic_scoring_provider.FidelityScorerembeds the current query once per turn and computes cosine similarity against per-message embeddings cached inMessageMetadata.embedding(#[serde(skip)], in-memory only). Keyword-overlap remains the fallback when no provider is configured.w_keywordaccepted as a deprecated alias forw_semantic.ContentFidelity(zeph-memory optical forgetting) andContextFidelity(zeph-common CAM) to prevent confusion between the near-identical enum names.Closes #4551, #4552, #4556.
Changes
zeph-config:FidelityConfiggainscompress_provider: Option<String>andsemantic_scoring_provider: Option<String>;w_semanticacceptsw_keywordaliaszeph-llm:MessageMetadatagainsembedding: Option<Vec<f32>>with#[serde(skip)]zeph-context:score_and_apply()is nowasync, split intoembed_provider+compress_providerparams; pre-pass embed loop;cosine_similarity+semantic_overlapfunctions; 30 s timeouts on all external awaitszeph-agent-context: call sites updated (await, separate provider handles wired from config)zeph-memory:embedding: Noneadded to 3MessageMetadatastruct literals;ContentFidelitydoc note addedzeph-common:ContextFidelitydoc note addedfidelity_scorer.rsupdated for new two-provider signatureTest plan
cargo nextest run -p zeph-config -p zeph-context -p zeph-llm -p zeph-agent-context -p zeph-memory -p zeph-common— 3176 tests passcargo clippy -p ... -- -D warnings— cleanRUSTFLAGS="-D warnings" cargo check --all-targets— cleanRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps— cleancompress_providerandsemantic_scoring_providerset (blocked pending available provider in test env)Follow-up issues (P3, not in this PR)
compressed_max_tokenspost-processingmax_scored_messagessequential awaits; considerbuffer_unordered)