LangChain Wikipedia retriever: the built-in one vs WikiVectors, tested on 45 questions
LangChain's built-in WikipediaRetriever searches Wikipedia, then returns the first 4,000 characters of the top 3 pages. It is free and needs no key, but call wikipedia.set_user_agent() first: with its default settings, 18 of our 45 test questions crashed on Wikipedia's 429 Too Many Requests. With that fix it found the answer for 34 of 45 questions, in about 5.7 seconds each. WikiVectorsRetriever found 45 of 45 in 0.57 seconds, with a fifth of the text.
Want the answer paragraph, not the first 4,000 characters of a page?
WikiVectors is a drop-in LangChain retriever for today's English Wikipedia. Ask in plain English, get the paragraphs that answer it, each with its link, revision and license.
Everything below was run on 5 December 2026 with langchain-community 0.4.2, wikipedia 1.4.0 and wikivectors 0.5.0, on the same 45 questions we use in our grounding test: 15 everyday facts, 15 rare facts and 15 about this year's news. Both retrievers ran with their default settings, one question every 2 seconds. Outputs are copied as they came back. Script, questions and every result: langchain-retriever-test.zip.
How do I use LangChain's Wikipedia retriever?
Install langchain-community and the wikipedia package, then call invoke with your question. You get LangChain Documents: one per page, each holding the page's text up to doc_content_chars_max (4,000 by default).
# pip install langchain-community wikipedia import wikipedia from langchain_community.retrievers import WikipediaRetriever wikipedia.set_user_agent("MyApp/1.0 (https://example.com; me@example.com)") # see the next section retriever = WikipediaRetriever() # top_k_results=3, doc_content_chars_max=4000, lang="en" docs = retriever.invoke("Who succeeded Keir Starmer as UK Prime Minister in 2026?") print([d.metadata["title"] for d in docs], sum(len(d.page_content) for d in docs))
['Keir Starmer', 'Victoria Starmer', '2026 Labour Party leadership crisis'] 12000
That one worked: the answer is in the first page. But your model now reads 12,000 characters (about 3,000 tokens) for a one-name answer, and the call took 5.7 seconds, because the retriever makes a search call and then several calls per page. Importing it also prints a warning that langchain-community “is being sunset and is no longer actively maintained”.
Why does WikipediaRetriever fail with JSONDecodeError?
Because Wikipedia answered 429 Too Many Requests, and the wikipedia package tries to read that error page as JSON. You see JSONDecodeError: Expecting value: line 1 column 1 (char 0), not the 429. Here is what Wikipedia actually sent back in our run:
429 Retry-After: 2 You are making too many requests to the API. Please follow the best practices at https://www.mediawiki.org/wiki/Wikimedia_APIs/Rate_limits.
The wikipedia package (last release 2014) sends the same User-Agent for everyone who uses it, wikipedia (https://github.com/, so all its users share one budget with Wikimedia. With the defaults, 18 of our 45 questions crashed this way, at a gentle pace of one question every 2 seconds. Setting your own User-Agent with wikipedia.set_user_agent(...), as in the code above, brought that down to 1 error (a dropped connection) in 45. More on the limits: Wikipedia API rate limits, 403 and 429.
How often does it find the answer?
We counted a hit when an accepted answer (for example “Munich Philharmonic”) appears anywhere in the documents a retriever returns. That is generous to the built-in retriever, which returns about 5 times more text.
| Retriever | Everyday | Rare | 2026 news | All | Median time | Median text |
|---|---|---|---|---|---|---|
WikipediaRetriever, defaults | 11 | 2 | 9 | 22 of 45 | 4.4 s | 12,000 chars |
WikipediaRetriever, own User-Agent | 14 | 5 | 15 | 34 of 45 | 5.7 s | 12,000 chars |
WikiVectorsRetriever | 15 | 15 | 15 | 45 of 45 | 0.57 s | 2,287 chars |
Each group has 15 questions. For WikiVectors the answer was in the first paragraph for 43 of 45. Slowest WikiVectors call: 1.1 s. Slowest built-in call: 17.3 s.
Why does the built-in retriever miss rare facts?
Two reasons, both visible in the results file:
- Wikipedia's search is word search. It looks for pages that hold your words, and a whole question often matches nothing. For 4 of the 15 rare questions it found no page at all, so the retriever returned an empty list. Example: “Arnold F. Riedhammer is principal percussionist of which orchestra?” finds 0 pages on Wikipedia today; “Arnold F. Riedhammer orchestra” finds his page. The retriever sends your question as it is.
- It returns pages, not answers. When the right page isn't first, or the answer is past the first 4,000 characters, the model never sees it. “Which region did Lloyd Quinan represent as an MSP?” returned a list of party members, Kenny MacAskill and Alex Salmond.
On this year's news it did well once the User-Agent was fixed (15 of 15). It reads live Wikipedia, so it is as fresh as Wikipedia itself.
How do I use WikiVectors as a LangChain retriever?
Install the wikivectors package with the LangChain extra and put your key in WIKIVECTORS_KEY. It is a normal LangChain BaseRetriever, so it works anywhere a retriever does: in a chain, as a tool, in LangGraph.
# pip install "wikivectors[langchain]" from wikivectors.langchain import WikiVectorsRetriever retriever = WikiVectorsRetriever(k=3) # reads WIKIVECTORS_KEY for d in retriever.invoke("Arnold F. Riedhammer is principal percussionist of which orchestra?"): print(d.metadata["title"], "|", d.page_content[:120])
Arnold F. Riedhammer | Arnold F. Riedhammer (born 1947 in Somerville, New Jersey, USA) is a German-American musician,
composer, and songwriter. He is Principal Percussionist of the Munich Philharmonic Orchestra ...
Arnold F. Riedhammer | Arnold F. Riedhammer, percussionist and composer much sought after in the fields of classical
music as well as rock, pop and jazz, was born in Somerville, New Jersey ...
Arnold F. Riedhammer | As a classical percussionist he has performed, for example, with Leonard Bernstein, Sergiu
Celebidache, Herbert von Karajan ...
The same question gave [] from the built-in retriever. Each document's metadata carries what you need to cite it:
{'title': 'Arnold F. Riedhammer',
'url': 'https://en.wikipedia.org/wiki/Arnold_F._Riedhammer',
'permalink': 'https://en.wikipedia.org/w/index.php?oldid=1385698703',
'revision_id': 1385698703,
'attribution': '"Arnold F. Riedhammer" by Wikipedia contributors, CC BY-SA 4.0, https://en.wikipedia.org/w/index.php?oldid=1385698703',
'score': 2.05, 'passage_id': 71488265}
Behind it, English Wikipedia is already cut into paragraphs, with meaning search and word search together, and updated within the hour of each edit. One invoke is one search. LangChain.js and LlamaIndex versions: frameworks.
Which one should I use?
WikipediaRetriever | WikiVectorsRetriever | |
|---|---|---|
| Price | Free | 1,000 free searches a month, then $2 per 1,000 |
| Key | None | Free key, email only |
| Languages | Any Wikipedia (lang="de") | English only |
| What you get | Page starts, 4,000 chars each | The paragraphs that answer, with link and revision |
| Rate limits | Wikipedia's (429s with the default User-Agent) | 10 calls a second per key |
| In our test | 34 of 45, 5.7 s, 12,000 chars | 45 of 45, 0.57 s, 2,287 chars |
Use the built-in one for other languages, for whole page intros, or for a hobby project where a few misses are fine. Set your own User-Agent and catch the errors. Use WikiVectors when a wrong or empty answer costs you, when speed matters, or when you pay per prompt token: about 600 tokens per question instead of about 3,000.
Wikipedia for your AI app, without the limits
WikiVectors searches all of English Wikipedia and returns short, cited paragraphs, fresh within the hour. 1,000 free searches a month, then $2 per 1,000.
More guides
- Qwen 4 35B on a home PC: 35 of 60 facts alone, 60 of 60 with one WikiVectors searchWe ran Qwen 4 35B-A3B in Ollama on an RTX 4070 and asked 60 fact questions. Alone: every easy and medium one, but 5 of 15 rare facts and 0 of 15 from 2026. Thinking mode didn't fix it. With 5 WikiVectors paragraphs: 60 of 60, none wrong. Code and every answer.
- Wikipedia MCP server for Claude, Cursor and VS Code (tested in Claude Code)Add Wikipedia to Claude Code, Claude Desktop, claude.ai, Cursor or VS Code with one line or one JSON file. A real Claude Code run went from "I don't know" to the right 2026 answer in 7 s. 8 questions vs Wikipedia's own search, speed, cost, no-key tries.
- Fact-check API: check a claim against Wikipedia in one call (31 claims tested)Send a claim to one API call and get True, False or no answer, with the Wikipedia paragraphs as proof. We tested 31 claims: 28 right, 3 no answer, 0 wrong. Code, real output, and what to do when it can't tell.