Repository navigation
Chrome AI RTD Provider: IAB categories, publisher questions and keywords with the Classifier, Decisions and Prompt APIs - #16271
patmmccann wants to merge 6 commits into
Conversation
…rds with the Classifier, Decisions and Prompt APIs - categories: Classifier API IAB Content Taxonomy 3.1 IDs to site.pagecat with site.cattax 9, filtered by minScore/maxCategories; opt-in Prompt API fallback constrained to the tier 1 IDs - decisions: publisher questions in the DecisionModel schema shape, answered by the Decisions API or a Prompt API JSON schema built from the same questions, written to site.content.data as a chromeAi entry - keywords: Prompt API structured output to site.content.keywords, with the Summarizer as fallback; summarizer-only configs are unchanged - shared user activation gate before downloads, download progress via the monitor option, per-URL localStorage cache, no overwriting of publisher data - types for the module params Closes prebid#14285 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR introduces changes that may not work on all browsers. According to Babel, the following polyfills may be needed, and they are not automatically included:
The best way to address this is to provide good test coverage, as normal PR checks run unit tests on older browsers. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22969c8226
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else { | ||
| logMessage(`${CONSTANTS.LOG_PRE_FIX} Enriching site.pagecat with categories:`, categories); | ||
| deepSetValue(global, 'site.pagecat', categories); | ||
| deepSetValue(global, 'site.cattax', CONSTANTS.CATTAX_IAB_CONTENT_3_1); |
There was a problem hiding this comment.
Preserve publisher taxonomy when cattax is absent
🤖 This comment was written by an AI agent (Codex) on behalf of the review requester.
When a publisher supplies site.cat or site.sectioncat without site.cattax, this branch still sets cattax: 9. An omitted cattax denotes taxonomy 1, so a publisher value such as cat: ['IAB1-1'] survives but is now incorrectly advertised as IAB Content Taxonomy 3.1. This corrupts existing publisher FPD sent to bidders. Before adopting taxonomy 9, also guard against nonempty cat and sectioncat arrays whose taxonomy is implicit, preserving the publisher's control as required by AGENTS.md.
AGENTS.md reference: AGENTS.md:L129-L129
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🤖 This comment was written by an AI agent (Claude Code) on behalf of @patmmccann.
Fixed in ceb5a28. The module now treats an omitted site.cattax as taxonomy 1 (the OpenRTB 2.6 default) whenever site.cat or site.sectioncat is present. In that case it skips the category enrichment entirely, the same as for an explicit cattax other than 9.
I also looked at writing the IDs to site.content.cat with site.content.cattax: 9, which has its own taxonomy field. I didn't do it: it would change where bidders find the categories only on some pages, and few adapters read content.cat. When the publisher already supplies site categories, keeping their data untouched is the safer choice.
When the publisher's cat is already in taxonomy 9, pagecat is still added next to it. New tests cover cat and sectioncat without cattax, and cat with cattax: 9.
There was a problem hiding this comment.
🤖 This comment was written by an AI agent (Claude Code) on behalf of @patmmccann.
Done in de65ea2. The taxonomy is now set in config.
categories.taxonomytakes the AdCOMcattaxvalue:6(IAB Content Taxonomy 2.2, the default) or1(Content Category Taxonomy 1.0). Any other value logs a warning and turns categories off.- There is no Content Taxonomy 2.3. The IAB Taxonomies repo and the AdCOM list have 1.0 (1), 2.0 (2), 2.1 (5), 2.2 (6), 3.0 (7) and 3.1 (9), so 2.2 stands in for "2.3".
- As you decided afterwards, 3.1 (
cattax9) and the Classifier API are gone. The Classifier explainer says it is no longer pursued.
- The Prompt API is now the only source of categories. It is restricted by a JSON schema to the bundled tier 1 IDs, and the module also drops any other ID it returns. Since categories need the Prompt API anyway,
promptFallbackis removed;categories.enabledstays off by default. - The bundled lists come from the IAB Tech Lab files, tier 1 only:
- 2.2: the 29 topical rows, with numeric IDs from 1 to 680 and nothing above 680. Left out: Sensitive Topics (
v9i3On), Brand Suitability and Risk (MRkz4Q), and the Content Channel/Type/Source/Media Format/Language/Source Geo extension rows (1000–1219). The 2.2 file's header still says v2.1; the rows are the 2.2 ones. - 1.0:
IAB1–IAB23.IAB24Uncategorized,IAB25Non-Standard Content andIAB26Illegal Content are left out. - Together they come to 601 B gzipped.
- 2.2: the 29 topical rows, with numeric IDs from 1 to 680 and nothing above 680. Left out: Sensitive Topics (
- Publisher categories:
site.pagecatis added only when the publisher's taxonomy matches the configured one. That taxonomy issite.cattax, or 1 when it is absent andcat/sectioncatare present.site.cattaxis only set when it is absent, socat: ['IAB1-1']with nocattaxnow gets taxonomy 1 categories whentaxonomy: 1is configured. - Cache: the taxonomy is part of the settings hash, so changing it triggers detection again.
- Tests: there are tests for each taxonomy, the 1–680 cap (in the list and in the schema), matching and mismatched publisher taxonomies, unsupported values, the Classifier never being called, and the cache. The docs PR (Chrome AI RTD Provider: categories, publisher questions and Prompt API keywords prebid.github.io#6988) is updated too.
There was a problem hiding this comment.
🤖 This comment was written by an AI agent (Claude Code) on behalf of @patmmccann.
Follow-ups on top of de65ea2:
- 3a97311, custom prompts and GAM:
keywords.promptandcategories.promptreplace the default instruction. The module still appends the category list (for categories) and the page text, and keeps the JSON schema, so a custom prompt can't produce invalid IDs or shapes. A value that isn't a non-empty string logs a warning and the default is used. The prompt is part of the cache key.- With taxonomy 6, the categories are also written as
{ name: 'chromeAi', ext: { segtax: 6 }, segment: [{ id }] }insite.content.data.gptPreAuctionalready sends these to GPT asIAB_CONTENT_2_2Publisher Provided Signals, and this module never callsgoogletag. It's on by default;categories.gamPps: falseturns it off. GAM PPS has no 1.0 taxonomy, so taxonomy 1 has no PPS output. - A test runs
gptUtils.getSignalson the result. The decisions entry stays separate (nosegtax).
- 1196396, Summarizer removed:
- It runs on the same on-device model as the Prompt API, which has been stable on the web since Chrome 148, and its one-sentence summary made a poor keyword. Removing it saves 203 B gzipped.
params.summarizernow logs a warning.summarizer.enabled: trueturns onkeywords, carrying over itsortb2Path/cacheInLocalStorage.
The module is now 5,734 B gzipped (master: 3,037 B), and the tier 1 lists are 601 B of that. The full suite passes locally (29,539 tests).
| const cached = _getChromeAiDataFromLocalStorage()?.[key]; | ||
| if (isUsable(cached)) { | ||
| detected[key] = cached; |
There was a problem hiding this comment.
Validate cached results against the current feature settings
🤖 This comment was written by an AI agent (Codex) on behalf of the review requester.
On a later visit to the same URL with updated publisher settings, this cache path bypasses the new limits and confidence thresholds. For example, three cached categories are still emitted after changing maxCategories to 1; a cached 0.4-confidence DecisionModel answer is still emitted after raising minConfidence to 0.95 because isUsableDecisions checks only the questions hash. Caching is enabled by default, and the stored results retain neither scores nor the relevant configuration, so these publisher restrictions can remain ineffective indefinitely. Include result-affecting settings in cache validation, or retain raw results and reapply filtering before reuse, rather than ignoring publisher settings contrary to AGENTS.md.
AGENTS.md reference: AGENTS.md:L129-L129
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🤖 This comment was written by an AI agent (Claude Code) on behalf of @patmmccann.
Fixed in ceb5a28 by invalidating the cache when the settings change, rather than re-filtering. Re-filtering would need every raw score stored, and it still couldn't bring back results that a lower threshold now allows.
Cache entries for these features are now { settings: <cyrb53 hash>, value }. The hash covers the settings that shape the result:
extractedKeywords:maxKeywordscategories:minScoreandmaxCategoriesdecisions: the valid questions andminConfidence(this replaces the questions-only hash)
When the hash doesn't match, the feature detects again. The legacy summarizer keywords entry keeps its bare-array format, so caches written by earlier releases still work.
New tests change maxCategories, minConfidence and maxKeywords between runs and check that detection runs again with the new limits.
…t when settings change - don't set site.cattax 9 when the publisher has site.cat or site.sectioncat without site.cattax, which OpenRTB reads as taxonomy 1 - store keywords, categories and decisions with a hash of the settings that shape them, and detect again when those settings change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e Prompt API - new categories.taxonomy (AdCOM cattax), 6 (Content Taxonomy 2.2, default) or 1 (Content Category Taxonomy 1.0); other values log a warning and disable categories - the Prompt API is the only source, restricted by the JSON schema to the bundled tier 1 IDs, and IDs outside them are dropped; promptFallback goes - 2.2 list: the 29 topical tier 1 rows, numeric IDs 1 - 680 only; 1.0 list: IAB1 - IAB23 (no Uncategorized, Non-Standard or Illegal Content) - drop Content Taxonomy 3.1 and the Classifier API, whose explainer is no longer pursued - pagecat is added when the publisher's site categories are in the same taxonomy; site.cattax is only set when absent; the cache depends on the taxonomy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nals - keywords.prompt and categories.prompt replace the default instruction; the module still appends the category list and page text and keeps the JSON schema; invalid values log a warning; the prompt is part of the cache key - with taxonomy 6, categories are also written to site.content.data with ext.segtax 6 so gptPreAuction sends them to GAM as IAB_CONTENT_2_2 Publisher Provided Signals; on by default, categories.gamPps: false turns it off; nothing for taxonomy 1, which GAM PPS doesn't support - the decisions entry stays separate (no segtax) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Summarizer runs on the same on-device model as the Prompt API, which is stable on the web since Chrome 148, and its one-sentence summary made a poor keyword. Keywords now come only from the Prompt API. params.summarizer logs a warning; summarizer.enabled turns on keywords (unless keywords.enabled is set) with its ortb2Path and cacheInLocalStorage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
I tested the category classification in this PR against Chrome's built-in models (Chrome 158, Gemini Nano on GPU), using IAB Content Taxonomy 2.2 tier 1. Method
Results (top-1 = the first category returned is correct)
Latency is the median time of the Findings
Cost to the user Besides the latency above, enabling a feature can trigger a one-time model download. It starts on the user's first interaction with the page, without a prompt.
Measured on a fresh profile from Chrome's network log. The models are shared across sites, so a user who already has one doesn't download it again. A GPU/CPU switch or a model update can trigger a second Nano download. Caveats: with 79 pages the margin of error is about ±10 points, so only the gap between IDs and names is clearly significant. Labellers and graders are all the same model family (Claude). |
Following up on the category tests above: this time I tested what text to take from the page, the step the earlier tests skipped by feeding the model pre-cleaned text. Method
Results (top-1 = the first category returned is correct; read after
"Main content" is JSON-LD Findings
Suggestion Replace Caveats: with 79 pages the margin of error is about ±10 points, so only the drop for |
|
From my testing it looks like DecisionModel and LanguageModel perform about the same for picking categories; I'd expect the same to be true for publisher questions, but I don't have good data to test that. Given that both need relatively large downloads, one much larger than the other, I think it'd make sense to prefer whatever was already downloaded, if anything; if a download must be started, prefer DecisionModel when possible. |
…nly and model selection by availability Applies the category test findings on the PR: - categories: the prompt and the responseConstraint list tier 1 category names, which are mapped back to IDs; unknown names are dropped. No confidence scores: minScore is removed and logs a warning if set, and maxCategories defaults to 1. - page text: title, meta description, publisher section and tags, URL path words and the first 500 characters of the main content (JSON-LD articleBody, else the first article/main/[role=main] with 200+ characters, else the body), skipping script, style and hidden subtrees. Language detection gets the main content only. Detection waits for DOMContentLoaded and reads the page only after an API was found. - categories.articlesOnly (default true): categories only run on pages with a JSON-LD Article, NewsArticle or BlogPosting node, including @graph and array @type. - model selection: availability of DecisionModel and LanguageModel is checked together; an available model is preferred, then one downloading, then DecisionModel's smaller download. Categories can now use DecisionModel, as choice questions of at most 26 names, keeping the most probable answers across them. - cache: settings hashes include a version and articlesOnly, so results from the old prompts are detected again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…model selection Matches prebid/Prebid.js#16271: categories are picked by name with no confidence scores (minScore removed, maxCategories defaults to 1), categories.articlesOnly, the page text the models get, and how the module picks between the Decisions API and the Prompt API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thanks for the tests, @dgirardi. Your findings are applied in b891022:
Other changes in the same commit:
Not done, with reasons:
|
Type of change
Description of change
Closes #14285.
Moves the Chrome AI RTD provider onto Chrome's newer on-device APIs. Language detection is unchanged apart from its input text. Every new feature is off by default, so existing configurations download no new models.
categoriesDecisionModel) or Prompt API (LanguageModel), picked by availability, choosing from the tier 1 category names of the configured taxonomy; article pages only by defaultsite.pagecat(+site.cattaxwhen absent); with taxonomy 6, also asegtax: 6site.content.dataentry for GAM PPSdecisions(publisher questions)DecisionModel.availability(schema)/create(schema)/decide()) or the Prompt API with a JSON schema built from the same questions, picked by availability (promptFallback: falsekeeps it to the Decisions API)site.content.data:{ name: 'chromeAi', segment: [{ id: question, value: answer }] }keywordsresponseConstraintwith an array schemasite.content.keywordslanguageDetectorsite.content.languagePage text
dgirardi's tests (1, 2) found that
document.body.textContentbrought inline script and style text into the prompt. Keywords, categories and publisher questions now get one labelled line each, read synchronously from the DOM:Title,Description(meta description),Section and tags(article:section, JSON-LDarticleSectionandBreadcrumbListnames,article:tag, meta keywords) andURL path(path segments made only of words), each capped at 200 characters;Content: the first 500 characters of the main content, which is JSON-LDarticleBody, else the firstarticle,mainor[role=main]element with at least 200 characters, else the body.The text is read with a bounded
TreeWalkerthat skipsscript,style,noscript,template,svg,iframe,[hidden]and[aria-hidden=true]subtrees, instead ofinnerText, which the repo's lint rules forbid because it forces a layout. Language detection gets the first 1000 characters of the main content. Features wait forDOMContentLoadedwhen the page is still loading, and read the page only once an API has been found, so other browsers never run the extraction.Categories
enumlist the tier 1 category names, and the module maps the answer back to IDs and drops any name outside the list. With IDs, the model mostly picked from the top of the list (top-1 0.37 against 0.86 with names in dgirardi's test).minScoreis gone; a config that still sets it logs a warning and works.maxCategoriesdefaults to 1, since extra categories were often unrelated to the page; publishers can raise it.categories.articlesOnly(defaulttrue): categories only run on pages with a JSON-LD node of typeArticle,NewsArticleorBlogPosting(top level, in an array or in@graph, with a string or array@type). Home, section, search and tag pages rarely have one.og:typeisn't used, because WordPress themes set it on most pages.categories.taxonomyis the AdCOMcattaxvalue:6(IAB Content Taxonomy 2.2, the default) or1(Content Category Taxonomy 1.0). Other values log a warning and turn categories off. There is no Content Taxonomy 2.3: AdCOM has 1.0 (1), 2.0 (2), 2.1 (5), 2.2 (6), 3.0 (7) and 3.1 (9).v9i3On), Brand Suitability and Risk (MRkz4Q), and the Content Channel/Type/Source/Media Format/Language/Source Geo extension rows (1000–1219).IAB1–IAB23. Uncategorized (IAB24), Non-Standard Content (IAB25) and Illegal Content (IAB26) aren't page topics, so they're left out.site.pagecatis never overwritten.site.cattax, or 1 when it's absent andsite.cat/site.sectioncatare present, since OpenRTB reads an omittedcattaxas 1.site.cattaxis only set when it is absent.{ name: 'chromeAi', ext: { segtax: 6 }, segment: [{ id }] }insite.content.data.gptPreAuction(on by default when built) already sends segtax 6 entries to GPT asIAB_CONTENT_2_2ontargetingDone, so they reach GAM with no new GPT code; this module never callsgoogletag.categories.gamPps: falseturns it off. GAM PPS has no 1.0 taxonomy, so taxonomy 1 has no PPS output.chromeAientry already exists.getSegmentsfilters bysegtaxonly, so it doesn't conflict with the decisions entry, which has the samenameand nosegtax.categories.promptreplaces the default instruction. With the Prompt API, the module still appends the category names and the page text and keeps the schema, so an override can't produce unknown categories or shapes; with the Decisions API it is the choice question. A value that isn't a non-empty string logs a warning and the default is used.Model selection
Following dgirardi's suggestion, categories and publisher questions check the availability of both
DecisionModel(EmbeddingGemma, ~163 MB) andLanguageModel(Gemini Nano, ~3.5 GB), and pick the first of:available(the Decisions API if both are);downloading;downloadable, the smaller download;downloadable.For publisher questions, the Prompt API is only considered while
promptFallbackis on (the default). Keywords only use the Prompt API. The two APIs classified categories about equally well in dgirardi's tests; publisher questions haven't been compared on them, and the .md says so.Publisher questions
decisions.questionstakes the Decisions API question shape as is (id,typeofboolean/choice/score,prompt,options[{label, description}]), so{ questions }is passed straight toDecisionModel. Answers belowminConfidenceare dropped.enumproperty per question ('true'/'false', the option labels, or'1'–'5'for ascorewithout options). Publishers write one config, and the answers have the same labels whichever API produced them.site.content.dataentry namedchromeAiwithoutext.segtax, because the segments aren't from a standard taxonomy. It is merged after the publisher's own entries.Keywords
keywordsblock turns this on.summarizerconfigs:params.summarizerlogs a warning pointing tokeywords.summarizer.enabled: trueturns onkeywords(unlesskeywords.enabledis set), carrying oversummarizer.ortb2Pathandsummarizer.cacheInLocalStoragewhenkeywordsdoesn't set them;type/format/lengthare ignored. The output becomes a comma-separated keyword string instead of an array holding one summary. Old cached summaries aren't reused.keywords.promptreplaces the default instruction; the page text and schema are still added.Common behaviour
selfby name. A missing orunavailableAPI is skipped.downloadable/downloadingand the user isn't active, the feature retries on the next activation event. Language detection keeps its original flow.monitoroption ofcreate(), as all the explainers define it.chromeAi_detected_data, through the storage manager, so activity controls and consent apply. New entries are{ settings: <hash>, value }, and the feature detects again when the settings that shape the result change. The hash also covers a version of the model input, so results from earlier prompts aren't reused:maxKeywords,prompt;taxonomy,maxCategories,articlesOnly,prompt;minConfidence.getBidRequestDatastays synchronous and only uses results that are already available, so the auction never waits on a model.Setmethods the polyfill bot lists (union,difference, …) aren't used; the module only dedupes with[...new Set(array)], which is ES2015. The ES2017+ calls (Object.fromEntries,Array.prototype.flatMap) only run after an AI API has been found.modules/chromeAiRtdProvider.d.tsand registered in the RTDProviderConfig.Notes
keywordsfeature writessite.content.keywordsas a comma-separated string, since OpenRTB defineskeywordsas a string. Ifortb2Pathends inkwarray, it writes an array.Testing
npx gulp test-only --file test/spec/modules/chromeAiRtdProvider_spec.js: 118 passing. The new tests stubDecisionModelandLanguageModelwith the explainers' shapes. They cover:articleBodyfirst, thearticle/main/[role=main]choice and body fallback, the 500 character cap, title/description/section/tags/breadcrumbs, URL path words, invalid JSON-LD, language detection input;articlesOnly: skipped without an Article node (even withog:type=article), found in@graphwith an array@type, off witharticlesOnly: false;available/downloading/downloadable/unavailable/ missing, the user activation deferral, andpromptFallback: false;maxCategoriesdefaulting to 1, theminScorewarning, the DecisionModel split into choice questions of at most 26 options and the ranking across them, each taxonomy's names, the 1–680 cap and the excluded rows, and the Classifier never being called;pagecat/cattax/content.data/keywords;gamPps: falseand for taxonomy 1, andgetSignalsfromgptUtilsreturningIAB_CONTENT_2_2;summarizerconfigs, and that the default config never touches the new APIs.npx gulp precompile && npx gulp test-only-nobuild): 956 files, 29576 passing, 8 skipped.npx gulp lint --nolintfixon the changed files: no errors. The one warning (prebid/no-deep-access-import, for dynamicortb2Pathlookups) was already there.npx gulp tsandnpx gulp ts-strictpass.Other information
Docs: prebid/prebid.github.io#6988
🤖 Generated with Claude Code