Skip to content

Python context layer: fold source prose into retrieval - #285

Open
jat255 wants to merge 3 commits into
jat255/context-layer-dictionary-chunksfrom
jat255/context-layer-augment
Open

Python context layer: fold source prose into retrieval#285
jat255 wants to merge 3 commits into
jat255/context-layer-dictionary-chunksfrom
jat255/context-layer-augment

Conversation

@jat255

@jat255 jat255 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Last of four PRs for M4, the Python context layer (kata c8a0). Stacked on #284, which adds the chunks this folds in.

augment_context_layer(layer, sources) appends each source's dictionary chunks and returns a new layer, so a dictionary alone is searchable context even when the caller passed no context files. It is internal, as it is in pkg-r; the agent constructor in M5 is what calls it.

The returned layer is always a new object with a fresh index. Source enrichment belongs to the agent that owns the sources, so mutating the caller's layer would leak one agent's sources into the next agent built from the same layer. With nothing to add the argument comes back unchanged, None included, so an agent with neither context files nor dictionary prose gets no layer rather than an empty one.

One deliberate gap. pkg-r also folds in each source's warehouse semantic models here, the Snowflake semantic views and Databricks metric views. The python side package has no surface for those yet (tracked locally as kata gcgj, and notes that porting the reader alone would produce records nothing consumes), so that half is a comment at the point where it will go rather than code.

R changes

@simonpcouch

Tests-only.

The behaviour this PR adds in Python already existed in R, and each package was testing it separately. tests/shared/context_layer.json gains an augment_context_layer section and test-context-layer.R gains a runner for it. The cases cover where source chunks land relative to the caller's documents, source ordering, skipping a dictionary-less source, and the distinct outcomes for an absent layer, an empty layer, and all-empty prose.

The runner replaces two hand-written tests in test-data-dictionary.R, with a comment at the deletion site pointing at the fixture. "dictionary prose is searchable via the context layer" stays, because it exercises BM25 ranking, which is engine-specific. The fresh-index assertion is Python-only, as the fixture notes: R holds documents in an R6 object, where the equivalent would be object identity rather than behaviour.

The runner is guarded against being vacuous (expect_gt(length(cases), 0)), and I verified the three-source case really builds three sources with the dictionary-less middle one skipped. test-context-layer.R passes at 33; test-data-dictionary.R, test-definitions.R, and test-citations.R also pass. Not the full R suite, for the #268 hang. pkg-r/tests/testthat/fixtures/shared/context_layer.json is generated by scripts/sync-shared-fixtures.sh and needs no review.

@jat255 jat255 added this to the py-M4: context layer milestone Sep 6, 2026
@jat255 jat255 added py Affects the Python implementation needs-manual-review Agent-created work that needs a human review labels Sep 6, 2026
@jat255
jat255 force-pushed the jat255/context-layer-augment branch from 2d37841 to e012e80 Compare September 7, 2026 00:43
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Preview deployed to Connect (dogfood.team.pct.posit.it): https://dogfood.team.pct.posit.it/connect/#/apps/d7a36cae-8f27-448b-a478-61b81fbe3942/draft/368310

Deployed from commit c76ef72.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Preview deployed to Connect (connect.staging.pct.posit.it): https://connect.staging.pct.posit.it/connect/#/apps/ad662e1b-5048-4acc-9ad7-f9478c92274e/draft/2660

Deployed from commit c76ef72.

@jat255
jat255 force-pushed the jat255/context-layer-augment branch from e012e80 to b076ab2 Compare September 7, 2026 01:00
An agent's sources describe themselves, and that prose is worth
retrieving. augment_context_layer() appends each source's dictionary
chunks and hands back a new layer, so a dictionary alone is searchable
context even when the caller passed no context files at all.

The new layer is always a new object. Source enrichment belongs to the
agent that owns the sources; mutating the caller's layer would leak one
agent's sources into the next agent built from the same layer. With
nothing to add the argument comes back unchanged, None included, so an
agent with neither context nor a dictionary has no layer rather than an
empty one.

The milestone's acceptance check is a test rather than a one-off script,
and asserts equality rather than a match: the glossary term comes back
whole, not as a fragment.

pkg-r also folds in a warehouse's own semantic models here. This package
has no surface for those yet, so that half is a comment at the point
where it will go.
Both packages fold a source's dictionary prose into an agent's context
layer, and each was checking that on its own. Add an
augment_context_layer section to the shared context_layer fixture and a
runner in each suite.

Each case lists one entry per source, so the cases cover where the
sources' chunks land relative to the caller's own documents, that every
source contributes in the order given, and that a source carrying no
dictionary is skipped rather than counted. An absent layer, an empty
layer, and a dictionary whose prose is all empty are separate cases,
because they are separate outcomes.

Whether the returned layer is a new object with a fresh index stays out
of the fixture and out of R. It is what keeps one agent's sources from
leaking into the next, but it is not observable text, so it is asserted
in the Python suite only.

Two R tests in test-data-dictionary.R covered the same ground more
loosely, one asserting only that the document count grew. The fixture
runner replaces both.
@jat255
jat255 force-pushed the jat255/context-layer-augment branch from b076ab2 to 7c9a3f8 Compare September 7, 2026 01:07
@jat255
jat255 requested a review from simonpcouch September 7, 2026 02:00
@jat255 jat255 added r Affects the R implementation and removed needs-manual-review Agent-created work that needs a human review labels Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py Affects the Python implementation r Affects the R implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant