# Wikipedia and local semantic search The findings and decisions behind `server/wiki.ts`, `server/embed.ts` and `server/links/` (the model reviewer that judges what the scanner finds is §9). Sources were read on 14 November 2026. The Wikimedia rate limits are new this year and its own page calls them "subject to experimentation and change", so check the links again before relying on the numbers. ## 1. What an unauthenticated client may do **Rate limits.** [Wikimedia APIs/Rate limits](https://www.mediawiki.org/wiki/Wikimedia_APIs/Rate_limits) (last edited 8 Nov 2026). The limits apply per user across the Action API and the REST APIs: | Client | Requests per minute | |---|---| | Unidentified ("no identifying traits beyond IP address") | 10 | | Unauthenticated browser requests | 200 | | Unauthenticated bots with a compliant User-Agent | 200 | | Authenticated, new account or few edits | 200 | | Authenticated, established editor | 2000 | | Bot-flagged accounts, Toolforge with compliant UA, granted exemptions | exempt (robot policy still applies) | The same page says to "limit concurrency to 3 or fewer requests" and to "respect the Retry-After header on 429 responses". 429 and 503 "typically include Retry-After"; without one, "wait at least five seconds or use exponential back-off". It mentions no headers that report remaining quota, and the live responses had none. The limits are not split by endpoint family: one budget covers the Action API and REST together. The [changelog](https://www.mediawiki.org/wiki/Wikimedia_APIs/Changelog) dates the rollout: Phase 1 enforcement from 12 Mar 2026, Phase 2 for identified requests from the week of 28 Apr 2026, and the API Portal (api.wikimedia.org) sunset in June 2026. **The User-Agent is parsed by machine, and the contact in it decides the tier.** [User-Agent policy](https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy) (edited 27 Mar 2026): a client should identify itself "in a way that isn't going to be confused with many other bots, and supplying some way of contacting you, the operator". The format is `/ () /`, and the contact is "an email address, a website, or a wiki user", e.g. `(wikipedia:de; User:DuesenBot)`. On the [rate-limit talk page](https://www.mediawiki.org/wiki/Talk:Wikimedia_APIs/Rate_limits) WMF staff explain how it is enforced. A contact the gateway did not recognise "dropped you to the lowest rate limit tier". The contact must match "the regex used for extracting the contact info", which reads the parenthesised part as a semicolon-separated list with no spaces inside an element, and only the last element is used (15 Apr 2026). A client that sent `(wikipedia:en User:Name)` without the semicolon was throttled after about 500 requests; with the semicolon it ran 2,500 requests at 1/s without a 429. Browser requests are limited by IP or user id, "not based on the user agent at all". *Consequence for this app.* The privacy rule (no name, email or host in the UA) and the policy pull in opposite directions. With no contact, the default UA `Explicata/0.1 (personal knowledge tool)` should be expected to fall in the 10/min "unidentified" tier. I did not provoke a 429 to check this. The client therefore spaces requests 6.5 s apart when there is no contact. If the owner sets `EX_WIKI_CONTACT` to an email address, an `https://` URL or `User:Name`, the UA becomes `Explicata/0.1 ()` and the spacing drops to 1 s, a third of the 200/min budget. The policy does expect a contact. A throwaway address or a wiki user page is enough, and either keeps the owner's real identity out of the UA. **maxlag.** [Manual:Maxlag parameter](https://www.mediawiki.org/wiki/Manual:Maxlag_parameter): `maxlag=5` is the recommended value on Wikimedia wikis. It applies to any `api.php` request: "Interactive tasks … may omit it. Noninteractive tasks should always use it." A lag error comes back as HTTP 200 with `error.code = "maxlag"` and a `Retry-After` header. The client sends it on bulk work only. **Serial requests and batching.** [API:Etiquette](https://www.mediawiki.org/wiki/API:Etiquette) (edited 13 May 2026) asks for requests "in series rather than in parallel", says "there is no hard speed limit on read requests", and recommends `Accept-Encoding: gzip`, the pipe (`titles=A|B|C`) "whenever possible", and caching. **Authentication** only raises a new account to the same 200/min a compliant UA already gets (the 2000/min tier needs an established editor account), and Wikimedia Enterprise is overkill for one user, so neither is used. ## 2. Endpoints used, and why | Need | Request | Notes | |---|---|---| | Batch title check | `GET /w/api.php?action=query&format=json&formatversion=2&redirects=1&prop=pageprops\|description&ppprop=disambiguation&titles=A\|B\|…` | "limited to 50 titles per query, or 500 for those with the `apihighlimits` right" ([API:Query](https://www.mediawiki.org/wiki/API:Query)). The answer has `normalized`, `redirects` (with `tofragment`), and `pages` with `missing`/`invalid`. A disambiguation page carries `pageprops.disambiguation`. The short description is in `description`. Pages are not returned in request order, so inputs are mapped back through normalized → redirects. | | Senses of a disambiguation page | same, with `generator=links&gplnamespace=0&gpllimit=max` on the one title | One request gives every linked article with its description. "Set" returned 73. | | Title autocomplete | `GET /w/rest.php/v1/search/title?q=…&limit=…` | Documented for this: "a typeahead search that automatically suggests relevant pages by title" ([REST reference](https://www.mediawiki.org/wiki/API:REST_API/Reference)). Returns title, description and thumbnail, limit 1–100. `action=opensearch` returns empty descriptions on Wikimedia wikis ([API:Opensearch](https://www.mediawiki.org/wiki/API:Opensearch)). `list=prefixsearch` gives titles only. The completion index is "updated once a day" ([Help:CirrusSearch](https://www.mediawiki.org/wiki/Help:CirrusSearch)). | | Preview | `GET /api/rest_v1/page/summary/{title}?redirect=true` | Extract, description, thumbnail, `revision`, `type: "disambiguation"`. Edge-cached (`s-maxage=1209600`), so it is cheap for Wikimedia. rest_v1 is RESTBase, which is being retired: there is no date for `page/summary` ([RESTBase/deprecation](https://www.mediawiki.org/wiki/RESTBase/deprecation)). The client falls back to `prop=extracts\|pageimages\|description\|info` if it disappears. | | Article by section | `GET /w/api.php?action=parse&page=…&redirects=1&prop=text\|tocdata\|revid\|displaytitle\|properties&disableeditsection=1&disablelimitreport=1&disabletoc=1` | One request for the whole page (Octopus: 480 KB raw, 69 KB after sanitising), split on the server at `div.mw-heading` boundaries and cached for 7 days. A section then costs nothing. `prop=sections` now warns "deprecated … use prop=tocdata". With `section=N`, both come back empty, so the section list cannot be had alongside one section's text. REST `/page/{title}/html` (Parsoid, with `
` wrappers) also works; the splitter flattens either. | Two route parameters (`server/wikiRoutes.ts`) shape the answers for the UI. `article?full=1` returns every section's sanitised HTML along with the section list and the `disambiguation` flag (read from `prop=properties`), so a whole article costs the browser one request and the server at most one. `summary?cached=1` answers from the server's cache only, fresh or expired, and never waits on Wikipedia: 404 `reason: "uncached"` when nothing is cached. The UI uses it to put a summary in a model prompt without delaying the prompt. What gets stripped (seen in real output): inline `