# WikipediaRetriever

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/retrievers/wikipedia/WikipediaRetriever)

`Wikipedia API` retriever.

## Signature

```python
WikipediaRetriever()
```

## Description

**Setup:**

Install the ``wikipedia`` dependency:

.. code-block:: bash

    pip install -U wikipedia

**Instantiate:**

.. code-block:: python

from langchain_community.retrievers import WikipediaRetriever

retriever = WikipediaRetriever()

**Usage:**

.. code-block:: python

    docs = retriever.invoke("TOKYO GHOUL")
    print(docs[0].page_content[:100])

.. code-block:: none

    Tokyo Ghoul (Japanese: 東京喰種（トーキョーグール）, Hepburn: Tōkyō Gūru) is a Japanese dark fantasy

**Use within a chain:**

.. code-block:: python

    from langchain_core.output_parsers import StrOutputParser
    from langchain_core.prompts import ChatPromptTemplate
    from langchain_core.runnables import RunnablePassthrough
    from langchain_openai import ChatOpenAI

    prompt = ChatPromptTemplate.from_template(
        """Answer the question based only on the context provided.

    Context: {context}

    Question: {question}"""
    )

    llm = ChatOpenAI(model="gpt-3.5-turbo-0125")

    def format_docs(docs):
        return "\n\n".join(doc.page_content for doc in docs)

    chain = (
        {"context": retriever | format_docs, "question": RunnablePassthrough()}
        | prompt
        | llm
        | StrOutputParser()
    )

    chain.invoke(
        "Who is the main character in `Tokyo Ghoul` and does he transform into a ghoul?"
    )

.. code-block:: none

     'The main character in Tokyo Ghoul is Ken Kaneki, who transforms into a ghoul after receiving an organ transplant from a ghoul named Rize.'

## Extends

- `BaseRetriever`
- `WikipediaAPIWrapper`

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/4b280287bd55b99b44db2dd849f02d66c89534d5/libs/community/langchain_community/retrievers/wikipedia.py#L10)