Skip to content

Add 0092 embed chunk-and-stitch (TEI + shared helper)#217

Merged
chris-colinsky merged 4 commits into
mainfrom
feature/0092-embed-chunk-and-stitch
Jul 13, 2026
Merged

Add 0092 embed chunk-and-stitch (TEI + shared helper)#217
chris-colinsky merged 4 commits into
mainfrom
feature/0092-embed-chunk-and-stitch

Conversation

@chris-colinsky

Copy link
Copy Markdown
Member

Implements the general retrieval-provider §8 Batch chunking rule and its TEI /embed realization (fixture 038), and folds the shared chunk-and-stitch orchestration into _wire.py so TEI and Cohere embed share one implementation.

The rule

When an embedding provider enforces a per-call input cap and the caller exceeds it, the mapping splits into consecutive ≤ cap slices (preserving order), issues one request per slice with every field except the chunked input identical, concatenates the per-chunk vectors in input order, sums EmbeddingUsage.input_tokens when the provider reports usage (else usage = null), and takes response_id from the first chunk.

Changes

  • Shared chunk_and_stitch_embed helper in retrieval/_wire.py — owns the loop, the per-chunk vector-count validation, the input-order concat, the None-aware input_tokens sum, the first-chunk response_id, the raw dict-or-list discriminator (0096), and the §4 validation on the stitched result. A per-mapping embed_chunk closure owns the wire shaping / POST / parse and returns (vectors, input_tokens, response_id, raw_body) per slice.
  • TEI /embed now chunks by its chunk_size (the existing construction param — TEI's max-client-batch-size, previously bound but unused for embed). TEI reports no usage and no id, so the stitch yields usage = null and a null response_id. The single-request path (len(input) ≤ chunk_size) is preserved.
  • Cohere /v2/embed migrates its own chunk-and-stitch onto the shared helper — a pure refactor (fixture 037 and its tests are unchanged).

Tests

Un-defers fixture 038 (retrieval conformance now has no deferred fixtures); 4 TEI embed chunk unit tests (chunk boundaries, input-order stitch, usage/id null, per-chunk-count mismatch, single-request path); and an env-gated live TEI embed chunk test, verified against the local endpoint.

Implement the general section 8 embed batch-chunking rule and TEI /embed
chunk-and-stitch (fixture 038). TeiEmbeddingProvider.embed() now chunks by
its chunk_size (TEI's max-client-batch-size) over consecutive slices,
concatenates vectors in input order, and produces usage null / response_id
null (TEI reports neither).

Lift the shared chunk_and_stitch_embed helper into retrieval/_wire.py: the
loop, per-chunk count validation, input-order concat, None-aware
input_tokens sum, first-chunk response_id, and section 4 validation, driven
by a per-mapping embed_chunk closure. TEI /embed and Cohere /v2/embed both
adopt it; Cohere's own chunk path migrates onto it unchanged. Un-defer
fixture 038 and flip conformance.toml.
Copilot AI review requested due to automatic review settings July 13, 2026 01:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements retrieval-provider §8 embedding Batch chunking (proposal 0092) and applies it to TEI /embed (fixture 038) while refactoring Cohere /v2/embed to share the same orchestration helper.

Changes:

  • Added a shared chunk_and_stitch_embed() helper in retrieval/_wire.py to chunk requests, stitch vectors in input order, combine nullable usage, and validate stitched invariants.
  • Updated TeiEmbeddingProvider.embed() to chunk by construction chunk_size and stitch responses (preserving the single-request path when within the cap).
  • Migrated Cohere embed chunking onto the shared helper and enabled conformance fixture 038 (no deferred retrieval fixtures remain).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/openarmature/retrieval/_wire.py Adds shared embedding chunk-and-stitch helper implementing the §8 rule.
src/openarmature/retrieval/providers/tei.py Routes TEI /embed through shared chunking helper with cap = chunk_size.
src/openarmature/retrieval/providers/cohere.py Refactors Cohere /v2/embed chunking to use the shared helper.
tests/unit/test_retrieval_provider.py Adds unit tests covering TEI embed chunking/stitching behaviors and edge cases.
tests/integration/test_tei_wire.py Adds live integration test exercising TEI embed chunk-and-stitch with small chunk_size.
tests/conformance/test_retrieval_provider.py Removes deferral for fixture 038 (retrieval conformance fully enabled).
conformance.toml Marks proposal 0092 as implemented and documents the behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/openarmature/retrieval/_wire.py
The shared helper assumed cap was positive; a cap <= 0 (a caller
misconfiguration) surfaced as a raw range() error (0) or a misleading
empty-stitch validation failure (< 0). Raise ValueError eagerly with a
clear message, mirroring the chunk_size guard TeiEmbeddingProvider
already applies at construction.
Copilot AI review requested due to automatic review settings July 13, 2026 01:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/openarmature/retrieval/_wire.py
An empty input reaching the shared helper fell through to
validate_embedding_response and raised provider_invalid_response
("provider returned no vectors"), misclassifying a caller-side invalid
request as an invalid response. Call validate_embedding_input up front so
an empty (or non-string) input raises provider_invalid_request. Providers
already validate before the helper; this protects a direct/future caller.
Copilot AI review requested due to automatic review settings July 13, 2026 01:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/openarmature/retrieval/_wire.py Outdated
The up-front validate_embedding_input() comment claimed the guard
covers empty and non-string inputs, but the validator only rejects an
empty list. Drop the non-string claim so the comment matches the code.
Copilot AI review requested due to automatic review settings July 13, 2026 02:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@chris-colinsky
chris-colinsky merged commit af228ad into main Jul 13, 2026
7 checks passed
@chris-colinsky
chris-colinsky deleted the feature/0092-embed-chunk-and-stitch branch July 13, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants