Repository navigation
Show indexed Commons files in search only as the image store vouches for them - #637
Open
daoudclarke wants to merge 1 commit into
Open
daoudclarke wants to merge 1 commit into
daoudclarke wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… for them ServedImagesRanker wraps both served rankers (inside anything that counts images, such as the coming per-list cap): a result that is a Commons File: page is looked up in CommonsImage with one batched query, and kept only if unrevoked and rechecked within IMAGE_SERVE_MAX_CHECK_AGE (48h: a daily recheck plus the search path's day rounding); otherwise it is dropped and the results below move up. No query when no result is a Commons file page. A kept file becomes an ImageDocument with the judged title and description and the store's thumbnail and licence, which /api/v2/search/ and Combined Search return as a nullable `image` with `engine: "commons"`. Super Search checks its sources and merged list too. Combined Search and Super Search's index source rank with sync_to_async so the lookup runs on a thread Django cleans up. commons_file_key checks for "wikimedia.org" before parsing. No functional changes to the crawler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
daoudclarke
force-pushed
the
seed-images-prod-standard-display
branch
from
November 11, 2026 11:33
215b168 to
35e19e7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From Claude:
Stack: builds on #635 (
seed-images-prod-index), which builds on #634 and #633. PR 9 of the #610 plan. #636 (seed-images-prod-ltr, the 2-images-per-list cap) will be rebased on top of this PR so that itsImageCapRankerwrapsServedImagesRanker.What changed
ServedImagesRanker(mwmbl/imagesearch/serving.py) is a decorator. It wraps the outermost served ranker:search_setup.ranker(around MMR) andcombined_ranker(around Jev). Any result whose URL is a CommonsFile:page, in any spellingcommons_file_keyaccepts, is looked up inCommonsImage. The lookup is one batchedin_bulkquery per search.revoked_atis null andlast_checked_atis within the newIMAGE_SERVE_MAX_CHECK_AGE(48 hours). Otherwise it is dropped, and the results below it move up.ImageDocument, which carries theimagefields from the store row to the formatting step. Formatting needs no second query, and the image survives any decorator that keeps document objects, such as Seed images: ship the LTR retrained with image pages, and cap images at 2 per list #636's cap.SearchHit.imageis a new nullable object:thumbnail_url,thumbnail_width,thumbnail_height,license_name,license_url,attribution. Served files haveengine: "commons"; every other hit hasimage: null.enginewill meet the new valuecommons./api/v2/search/and/api/v1/search/(v1 only drops files and has noimagefield), the HTML search page, and Combined Search's web results. The strip de-dup from Show Seed Search's images on Combined Search with images=true #631 stays.serving.served.sync_to_asyncinstead ofasyncio.to_thread. Underto_thread, a worker thread's database connection is never closed at the end of a request, and it would break for good after a database restart. Ranking still overlaps the Staan index write and the image phase, which run into_thread.commonsmeans, and that the only safety check is an LLM reading the text, with no pixel checkreferrerpolicy="no-referrer"license_urlis set by the uploader: link it withrel="noopener noreferrer nofollow"commons_file_keynow checks for the substring"wikimedia.org"before parsing. It returns exactly what it did before, because every Commons hostname contains that string and a URL contains its hostname in some case. A non-Commons URL now costs about 0.2 µs instead of about 1.6 µs.Why 48 hours
recheck_imagesrun adds up to 24 hours more.IMAGE_STORE_RECHECK_LIMIT = 2000per run, a daily run covers up to about 4,000 files. A larger store needs more frequent runs or a higher limit.User-facing change: crawled Commons file pages disappear
This is not gated on
IMAGE_SEARCH_ENABLED. With an empty store, which is production today, every CommonsFile:result is dropped, including those the crawler found on its own. The judge never saw them, and they could be anything. Category, gallery and other Commons pages are unaffected.How much this affects today:
devdata/index-v2.tinysearch): 0 of 90,690 documents are Commons file pages./api/v1/search/rawresponses (devdata/request_cache), 4,228,266 retrieved documents, of which 9 are Commons file pages, in 7 term lookups (e.g.Lyme_Regis_beach_04.JPGfor "regis beach",Leeds_UK_location_map.svgfor "uk location").So the change in today's results is negligible.
Cost on the hot path
Measured with the serving code on dev-index URLs and local Postgres. Times are p50 / p95.
When no result is a Commons file page there is no query at all; this is tested with
django_assert_num_queries(0). Before the substring check, 500 results took 2.4 ms.Verification
make checkpasses.make testpasses: 1980 passed, 10 skipped.test/test_image_serving.py:wikimedia.org/wiki/File:are kept/api/v2/search/schema:engine,image,scoreandnumber_of_resultsafter a dropimageandengine: "commons"ServedImagesRanker, so the check runs in every Combined Search testReview
One subagent did a combined code, security, trust-and-safety and holistic review of the first version.
Fixed:
The design also changed after review. At the orchestrator's request the filter moved from formatting into the ranker chain, so that #636's cap counts only files that will be shown, and it now covers Super Search.
Not changed, for you:
IMAGE_STORE_RECHECK_LIMITand the schedule with the store.Ranker.complete'sgo:suggestions can still name a Commons file URL (text only)./api/v1/crawler,get_raw_results) and/api/v1/search/rawreturn index items as they are. They are index-sync endpoints, not display endpoints.no-referrer. A front-end PR is needed before thumbnails are shown on mwmbl.org; the HTML search page shows none yet.Part of #610
🤖 Generated with Claude Code