Skip to main content

Documentation Index

Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

The Wikipedia Reader with asynchronous processing allows you to search and read Wikipedia articles efficiently, converting them into vector embeddings for your knowledge base.

Code

examples/concepts/knowledge/readers/wikipedia_reader_async.py
import asyncio

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.arxiv_reader import ArxivReader
from agno.knowledge.reader.wikipedia_reader import WikipediaReader
from agno.vectordb.pgvector import PgVector

# Create Knowledge Instance
knowledge = Knowledge(
    name="Multi-Source Knowledge Base",
    description="Knowledge base combining Wikipedia and ArXiv content",
    vector_db=PgVector(
        table_name="multi_vectors", 
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"
    ),
)

async def main():
    # Add topics from Wikipedia
    await knowledge.add_content_async(
        metadata={"source": "wikipedia", "type": "encyclopedia"},
        topics=["Manchester United", "Machine Learning"],
        reader=WikipediaReader(),
    )

    # Add topics from ArXiv
    await knowledge.add_content_async(
        metadata={"source": "arxiv", "type": "academic"},
        topics=["Carbon Dioxide", "Neural Networks"],
        reader=ArxivReader(),
    )

    # Create an agent with the knowledge
    agent = Agent(
        knowledge=knowledge,
        search_knowledge=True,
    )

    # Query the knowledge base
    await agent.aprint_response(
        "What can you tell me about Machine Learning from both general and academic sources?",
        markdown=True
    )

if __name__ == "__main__":
    asyncio.run(main())

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2

Install libraries

pip install -U wikipedia arxiv sqlalchemy psycopg pgvector agno openai
3

Set environment variables

export OPENAI_API_KEY=xxx
4

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  -v pgvolume:/var/lib/postgresql/data \
  -p 5532:5432 \
  --name pgvector \
  agno/pgvector:16
5

Run Agent

python examples/concepts/knowledge/readers/wikipedia_reader_async.py

Params

ParameterTypeDefaultDescription
topicstrNoneTopic to read from Wikipedia