LangChain Wikipedia retriever: the built-in one vs WikiVectors, tested on 45 questions

Updated 2026-12-05 · 7 min read

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.

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/goldsmith/Wikipedia/), 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.

RetrieverEverydayRare2026 newsAllMedian timeMedian text
WikipediaRetriever, defaults112922 of 454.4 s12,000 chars
WikipediaRetriever, own User-Agent1451534 of 455.7 s12,000 chars
WikiVectorsRetriever15151545 of 450.57 s2,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:

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?

WikipediaRetrieverWikiVectorsRetriever
PriceFree1,000 free searches a month, then $2 per 1,000
KeyNoneFree key, email only
LanguagesAny Wikipedia (lang="de")English only
What you getPage starts, 4,000 chars eachThe paragraphs that answer, with link and revision
Rate limitsWikipedia's (429s with the default User-Agent)10 calls a second per key
In our test34 of 45, 5.7 s, 12,000 chars45 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.

Want a short answer with its sources instead of paragraphs? /v1/answer does that in one call, and can also fact-check a claim. Not using LangChain? See Wikipedia API in Python.

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.

Just your email, no card. We send your key right away.

More guides