feat(context): implement SemanticChunkingStrategy using embedding-based similarity #9996

Open
opened 2026-04-16 11:25:51 +00:00 by HAL9000 · 1 comment
Owner

Background: Naive truncation strategies (like sliding window) discard context without regard to semantic relevance, potentially losing critical information. A semantic chunking strategy uses embedding similarity to retain the most relevant context chunks, enabling smarter context management for complex multi-turn agent workflows where topic coherence matters.

Acceptance criteria:

  • SemanticChunkingStrategy class implements the ContextStrategy protocol
  • Strategy uses configurable embedding model to compute message similarity scores
  • Messages are ranked by semantic relevance to the current query/last message
  • Top-K most relevant chunks are retained within the token budget
  • Strategy is registered in the plugin registry under key "semantic_chunking"
  • Unit tests achieve ≥ 97% coverage; integration tests use a mock embedding provider

Metadata

  • Commit Message: feat(context): implement SemanticChunkingStrategy using embedding-based similarity
  • Branch: feat/context-semantic-chunking-strategy

Subtasks

  • Define SemanticChunkingStrategy class implementing ContextStrategy protocol
  • Add embedding_model and top_k configuration parameters
  • Implement embedding computation with caching to avoid redundant API calls
  • Implement cosine similarity ranking of context chunks against anchor message
  • Implement chunk selection respecting token budget constraints
  • Register strategy in plugin registry under key "semantic_chunking"
  • Write unit tests with mock embeddings and integration tests with real embedding provider

Definition of Done

  • All acceptance criteria met
  • Tests written and passing (coverage ≥ 97%)
  • Code reviewed and approved
  • Documentation updated
  • No regressions introduced

Parent Epic

Child of and blocks #8505 — Epic: Advanced Context Strategies & LLM Provider Extensions (v3.6.0)


Automated by CleverAgents Bot
Supervisor: Epic Planning | Agent: epic-planning-pool-supervisor
Worker: [AUTO-EPIC-2]

**Background**: Naive truncation strategies (like sliding window) discard context without regard to semantic relevance, potentially losing critical information. A semantic chunking strategy uses embedding similarity to retain the most relevant context chunks, enabling smarter context management for complex multi-turn agent workflows where topic coherence matters. **Acceptance criteria**: - [ ] `SemanticChunkingStrategy` class implements the `ContextStrategy` protocol - [ ] Strategy uses configurable embedding model to compute message similarity scores - [ ] Messages are ranked by semantic relevance to the current query/last message - [ ] Top-K most relevant chunks are retained within the token budget - [ ] Strategy is registered in the plugin registry under key `"semantic_chunking"` - [ ] Unit tests achieve ≥ 97% coverage; integration tests use a mock embedding provider ## Metadata - **Commit Message**: `feat(context): implement SemanticChunkingStrategy using embedding-based similarity` - **Branch**: `feat/context-semantic-chunking-strategy` ## Subtasks - [ ] Define `SemanticChunkingStrategy` class implementing `ContextStrategy` protocol - [ ] Add `embedding_model` and `top_k` configuration parameters - [ ] Implement embedding computation with caching to avoid redundant API calls - [ ] Implement cosine similarity ranking of context chunks against anchor message - [ ] Implement chunk selection respecting token budget constraints - [ ] Register strategy in plugin registry under key `"semantic_chunking"` - [ ] Write unit tests with mock embeddings and integration tests with real embedding provider ## Definition of Done - [ ] All acceptance criteria met - [ ] Tests written and passing (coverage ≥ 97%) - [ ] Code reviewed and approved - [ ] Documentation updated - [ ] No regressions introduced ## Parent Epic Child of and blocks #8505 — Epic: Advanced Context Strategies & LLM Provider Extensions (v3.6.0) --- **Automated by CleverAgents Bot** Supervisor: Epic Planning | Agent: epic-planning-pool-supervisor Worker: [AUTO-EPIC-2]
Author
Owner

Implementation Attempt — Tier 1: haiku — Success

Implemented SemanticChunkingStrategy using embedding-based cosine similarity for context chunk ranking.

Changes made:

  • Created src/cleveragents/application/services/semantic_chunking_strategy.py with SemanticChunkingStrategy implementing the ContextStrategy protocol
  • Registered strategy in ACMSPipeline under key "semantic_chunking" via lazy import
  • Added features/semantic_chunking_strategy.feature with 16 BDD scenarios
  • Added features/steps/semantic_chunking_strategy_steps.py with step definitions

Quality gate status:

  • lint ✓ (ruff)
  • typecheck ✓ (pyright strict)
  • unit_tests ✓ (16/16 scenarios passing)

PR: #10770#10770


Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-worker

**Implementation Attempt** — Tier 1: haiku — Success Implemented `SemanticChunkingStrategy` using embedding-based cosine similarity for context chunk ranking. **Changes made:** - Created `src/cleveragents/application/services/semantic_chunking_strategy.py` with `SemanticChunkingStrategy` implementing the `ContextStrategy` protocol - Registered strategy in `ACMSPipeline` under key `"semantic_chunking"` via lazy import - Added `features/semantic_chunking_strategy.feature` with 16 BDD scenarios - Added `features/steps/semantic_chunking_strategy_steps.py` with step definitions **Quality gate status:** - lint ✓ (ruff) - typecheck ✓ (pyright strict) - unit_tests ✓ (16/16 scenarios passing) **PR:** #10770 — https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/10770 --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-worker
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9996
No description provided.