Skip to content

feat(context): CAM Phase 2-C/2-D — LLM compress + embedding semantic scoring#4626

Merged
bug-ops merged 3 commits into
mainfrom
4551-cam-fidelity-providers
May 29, 2026
Merged

feat(context): CAM Phase 2-C/2-D — LLM compress + embedding semantic scoring#4626
bug-ops merged 3 commits into
mainfrom
4551-cam-fidelity-providers

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented May 29, 2026

Summary

Closes #4551, #4552, #4556.

Changes

  • zeph-config: FidelityConfig gains compress_provider: Option<String> and semantic_scoring_provider: Option<String>; w_semantic accepts w_keyword alias
  • zeph-llm: MessageMetadata gains embedding: Option<Vec<f32>> with #[serde(skip)]
  • zeph-context: score_and_apply() is now async, split into embed_provider + compress_provider params; pre-pass embed loop; cosine_similarity + semantic_overlap functions; 30 s timeouts on all external awaits
  • zeph-agent-context: call sites updated (await, separate provider handles wired from config)
  • zeph-memory: embedding: None added to 3 MessageMetadata struct literals; ContentFidelity doc note added
  • zeph-common: ContextFidelity doc note added
  • Benchmark: fidelity_scorer.rs updated for new two-provider signature

Test 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 pass
  • cargo clippy -p ... -- -D warnings — clean
  • RUSTFLAGS="-D warnings" cargo check --all-targets — clean
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps — clean
  • Live session test with compress_provider and semantic_scoring_provider set (blocked pending available provider in test env)

Follow-up issues (P3, not in this PR)

  • No hard cap on embed/LLM compress input size
  • LLM compress output not bounded by compressed_max_tokens post-processing
  • Sequential embed loop (up to max_scored_messages sequential awaits; consider buffer_unordered)
  • Benchmark covers fast path only; no bench for embed/compress paths

@github-actions github-actions Bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate enhancement New feature or request size/XL Extra large PR (500+ lines) labels May 29, 2026
@bug-ops bug-ops force-pushed the 4551-cam-fidelity-providers branch from 16599e9 to f02eb27 Compare May 29, 2026 14:14
@bug-ops bug-ops enabled auto-merge (squash) May 29, 2026 14:17
@bug-ops bug-ops force-pushed the 4551-cam-fidelity-providers branch from 59cbe70 to be5006e Compare May 29, 2026 14:17
bug-ops added 2 commits May 29, 2026 16:20
…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).
@bug-ops bug-ops force-pushed the 4551-cam-fidelity-providers branch from be5006e to fbb4803 Compare May 29, 2026 14:20
@bug-ops bug-ops merged commit e6a30da into main May 29, 2026
32 checks passed
@bug-ops bug-ops deleted the 4551-cam-fidelity-providers branch May 29, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

1 participant