Page MenuHomePhabricator

[SPIKE] Validate summary delivery strategy for simple summary experiment
Closed, ResolvedPublic3 Estimated Story Points

Description

Background

As part of T376374, we need to deliver pre-generated simplified summaries for a list of about 10,000 articles. The goal of this task is to validate the proposed implementation strategy for storing and delivering those summaries.

Technical Proposal

In order to present simplified summaries through the browser extension, we can do the following:

Storage

  • Inside the browser extension, create a folder with 10,000 plain text files.
  • Each file name should correspond to an article title.
  • The content of each file contains the simplified summary for the title.
in-extension summary storage
- summaries/
    - Dog.txt
    - Earth.txt
    - Dopamine.txt

Browser extension Retrieval

  • In a background script, create a postMessage event listener.
  • Using the chrome APIs, retrieve the specific summary file for the given title, via URL, and read the contents of that file.
    • e.g. const url = chrome.runtime.getURL('/summaries/Dopamine.txt'); fetch(url);
  • Respond to the postMessage event with the contents of that file.

On-page script retrieval

  • On the on-page script, create a window.postMessage call that provides the page title.
  • The postMessage response should contain the simplified summary.

Acceptance criteria

The goal of this task is to validate the approach suggested above. Some open questions include:

  • Is it ok to upload a directory with 10,000 files?
  • Does the proposed approach affect the chrome store approval process in any way?
  • What is the bytesize payload of the summaries (it's estimated to be about 10-15mb, is that true?)
  • Can the browser extension read the file contents? Do we need special permissions to do that?
  • Does the window.postMessage between the browser extension and on-page script work as expected?

IF It turns out the suggested approach is not viable, propose an alternative strategy, e.g. Should we host the summaries on a static server instead of inside the browser extension? or use a web-based database like IndexedDB instead?

QA

This does not need QA.

Details

Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
Add Pre-generated summaries & delivery mechanismrepos/web/web-experiments-extension!15jdrewniaksummary-demomain
Customize query in GitLab

Event Timeline

Jdrewniak renamed this task from [SPIKE] Validate summarization delivery strategy for simple summary experiment to [SPIKE] Validate summary delivery strategy for simple summary experiment.Oct 10 2024, 3:33 PM

What is the bytesize payload of the summaries (it's estimated to be about 10-15mb, is that true?

I simulated the output size of the summaries by creating a folder with 10,000 files. Each file is given the name of the article, and the contents of each file is the first 100 words of the original intro text.

data source: https://gitlab.wikimedia.org/repos/web/simple-summary-server/-/blob/main/output.csv?ref_type=heads

On disk, on a Mac, it looks like the amount of summary data is closer to 40mb. This is about twice as large as the original CSV file. probably due to the overhead of filesystem metadata associated with individual files.
Regardless, this is too big! Adding 40mb to the browser extension is too much. It can affect download as well as update times.
> IF It turns out the suggested approach is not viable, propose an alternative strategy,
I just uploaded the test summaries to a WMF static file server called people.wikimedia.org:
e.g: https://people.wikimedia.org/~jdrewniak/test-summaries/0

The open question now is: are there CORS restrictions preventing us from accessing the summaries from people.wikimedia.org on a Wikipedia page? If so, there a different or better place to host these summaries?

EDIT:

After further investigation, it turns out that, although a directory full of summaries is 40Mb, a single JSON file with that same data is only 6Mb, and, the directory size gzipped is only 3Mb. The reason for this large initial size is still unknown. I'm linking both the JSON file and the directory for comparison:

Screenshot 2024-10-16 at 1.16.50 PM.png (814×110 px, 22 KB)

I think for the purpose of this experiment, 6Mb of JSON is acceptable to load into memory, so I think we can get away using a single file as a data store for the extension.

I created a patch that integrates 10,000 article demo summaries into the extension here:
https://gitlab.wikimedia.org/repos/web/web-experiments-extension/-/commit/17c1ef2e777f5946cf17fe77d01ff9f057ca06cd#ca642a22686971b261b60de81d8ff554fdd91e2e
This adds 6.2mb to the extension, but the summaries are only loaded as necessary based on the article title.

The patch introduces a new content script file, summaryDispatcher.js this file is loaded as a content script in the 'isolated' context, which means it's only loaded when someone visits certain domains like https://*.wikipedia.org. The script initiates a window.postMessage handler that responds to postMessage requests in the form of:

// code to request an article summary
window.postMessage( { action: 'SUMMARY_REQUEST', title: 'Cleopatra' } );

The summaryDispatcher.js script reads the extension specific summary files and returns a postMessage response with the summary content.

The on-page script can the retrieve a summary with the following code (testable in the browser console):

// add a listener to capture responses
window.addEventListener( 'message', ( message ) => {
	if ( message.data.action === 'SUMMARY_RESPONSE' ) {
		console.log( 'got the summary:', message.data.content );
	}
} );
// send requests for summaries based on title
window.postMessage( { action: 'SUMMARY_REQUEST', title: 'Cleopatra' } );
window.postMessage( { action: 'SUMMARY_REQUEST', title: 'Andes' } );

next steps here: sync with @bwang to review this approach and see how we can integrate the summary source with the UI component.