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

Merged
HAL9000 merged 6 commits from feat/context-semantic-chunking-strategy into master 2026-06-06 19:49:59 +00:00

6 Commits

Author SHA1 Message Date
HAL9000 a757633e27 fix(context): resolve AmbiguousStep crash in semantic_chunking feature
CI / lint (pull_request) Successful in 44s
CI / build (pull_request) Successful in 43s
CI / helm (pull_request) Successful in 1m10s
CI / quality (pull_request) Successful in 1m15s
CI / typecheck (pull_request) Successful in 1m17s
CI / security (pull_request) Successful in 1m18s
CI / push-validation (pull_request) Successful in 25s
CI / unit_tests (pull_request) Successful in 6m34s
CI / docker (pull_request) Successful in 1m45s
CI / integration_tests (pull_request) Successful in 10m37s
CI / coverage (pull_request) Successful in 11m31s
CI / status-check (pull_request) Successful in 3s
The `{count:d} semantic chunking fragments should be returned` step
patterns collided with the pre-existing `{count} fragments should be
returned` step in advanced_context_strategies_steps.py:365 — behave's
default `{count}` parser matches `.+?` (non-greedy any char) and
captured "N semantic chunking", failing the registry's ambiguity
check at module-load time. The crash aborted load_step_definitions
for the entire unit_tests session, errored all 8 features in the
behave-parallel worker, and produced the CI failure with verdict
"0 features passed, 0 failed, 8 errored".

Rephrase the two ambiguous step patterns to put unique anchor words
first ("the semantic chunking result should contain {count:d}
fragments" / "...should contain at most {count:d} fragments") and
update the feature file's three call sites to match. Also mark two
defensive private-helper early-return branches with `# pragma: no
cover` — they are unreachable through the public ContextStrategy API
(`_default_embedding("")` is gated by `if not self._anchor` in
`assemble`; `_cosine_similarity` size mismatch is impossible because
all `_get_embedding` callers receive same-length vectors from the
same `embedding_fn`).

Local gates: lint, typecheck, full unit_tests (16 scenarios / 56
steps in the semantic_chunking feature pass; full suite passes),
integration_tests — all green.

ISSUES CLOSED: #9996
2026-06-06 15:31:12 -04:00
HAL9000 64d8277b8c style(context): add __all__ export list to semantic_chunking_strategy module
Adds a public __all__ list to semantic_chunking_strategy.py to explicitly declare the module's public API, consistent with the project's module documentation conventions.

This commit also triggers a fresh CI run to clear stale CI statuses that were incorrectly associated with this PR's head SHA from an unrelated issues-event CI run (run 14959, commit 658b86c9).
2026-06-06 15:31:12 -04:00
HAL9000 4c277be6a9 fix(context): remove type: ignore comments from ACMSPipeline strategy registration
Replace BUILTIN_STRATEGIES ClassVar type annotation with dict[str, type[Any]]
to eliminate type: ignore[dict-item] suppressions on RelevanceStrategy, RecencyStrategy, and TieredStrategy entries.

Replace SpecStrategyAdapter type: ignore[assignment] with cast(ContextStrategy, ...)
for proper structural subtype annotation, consistent with the SemanticChunkingStrategy
registration fix applied in the previous commit.

All type: ignore comments are now removed from acms_service.py.
Pyright strict: 0 errors, 3 warnings (pre-existing langchain import warnings).
2026-06-06 15:31:12 -04:00
HAL9000 0fa592f24e fix(context): replace type: ignore with cast() in ACMSPipeline semantic_chunking registration
Use typing.cast(ContextStrategy, _sc_cls()) instead of a # type: ignore[assignment]
comment when registering SemanticChunkingStrategy in ACMSPipeline.__init__.
This eliminates the type suppression comment and makes the structural subtype
relationship explicit to the type checker.
2026-06-06 15:31:12 -04:00
HAL9000 7568007e9e style(context): apply ruff formatting to semantic_chunking_strategy_steps.py
Applied ruff auto-formatting to fix CI lint gate failure. The format check (ruff format --check) was failing on features/steps/semantic_chunking_strategy_steps.py due to list formatting and line length violations.

ISSUES CLOSED: #9996
2026-06-06 15:31:12 -04:00
HAL9000 67caf9fe26 feat(context): implement SemanticChunkingStrategy using embedding-based similarity
Implementation summary:
- Created semantic_chunking_strategy.py with SemanticChunkingStrategy implementing
  the ContextStrategy protocol with configurable embedding_model and top_k,
  cosine similarity ranking against anchor message, embedding caching, token
  budget enforcement, and relevance fallback when no anchor is provided
- Updated acms_service.py to register SemanticChunkingStrategy in ACMSPipeline
  under key 'semantic_chunking' via lazy import
- Added features/semantic_chunking_strategy.feature with 16 BDD scenarios
  covering all acceptance criteria from issue #9996
- Added features/steps/semantic_chunking_strategy_steps.py with step definitions

ISSUES CLOSED: #9996
2026-06-06 15:31:11 -04:00