Skip to content

contextual: expose named entities via ctxEntities() and the ctx_ent key-value - #386

Merged
mosherBT merged 2 commits into
masterfrom
feat/ctx-entities
Nov 12, 2026
Merged

mosherBT merged 2 commits into
masterfrom
feat/ctx-entities

Conversation

@pierluc-codes

Copy link
Copy Markdown
Contributor

Why

/v1beta1/contextual now returns classifications.entities, but the SDK doesn't surface it. Publishers have no way to read it or target on it.

What Changed

  • contextual_segments: new ContextualEntityKind and ContextualEntity types (name, kind, score) and an entities field on ContextualClassifications.
  • sdk: new ctxEntities() accessor. It reads the cached ctxSegments() response and returns [] when the page has no entities, including when the DCN omits the field.
  • ctxTargetingKeyValues: emits the multi-value key ctx_ent with the entity names, highest score first, sanitized like keywords and capped at 10. Kinds and scores aren't sent. The key is omitted when the page has no entities. options.entityKey renames the key and "" opts out; options.maxEntities changes the cap.
  • Docs: README and lib/addons/gpt.md.
  • Demos: both ctx_segments pages show the entities.

How to Test

  • Tested
  • Docs updated — if this adds, changes or removes anything a consumer calls, update the module's .md alongside the code (for example lib/addons/<addon>.md) and the matching README section. New addons ship with a new .md.

Notes

  • Breaking change
  • Requires release

🤖 Generated with Claude Code

…ey-value

Read the entities the DCN serves on /v1beta1/contextual ({ name, kind,
score }) and emit their names under ctx_ent, highest score first,
sanitized like keywords and capped at 10. entityKey renames or disables
the key and maxEntities changes the cap. A response without the field
reads as no entities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierluc-codes
pierluc-codes requested review from a team as code owners November 11, 2026 16:50

@willmacd willmacd 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.

LGTM just a couple nits

Comment thread lib/edge/contextual_segments.ts Resolved
Comment thread lib/edge/contextual_segments.ts Resolved
The DCN serves "product", never "brand_product". A NaN score sorted
unpredictably and could drop a high-score entity past the cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mosherBT
mosherBT merged commit 8769623 into master Nov 12, 2026
7 checks passed
@mosherBT
mosherBT deleted the feat/ctx-entities branch November 12, 2026 14:09
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.

4 participants