Example

Install wikipedia if needed using this guide

knowledge_base.py
from phi.knowledge.wikipedia import WikipediaKnowledgeBase
from phi.vectordb.pgvector import PgVector

from resources import vector_db

knowledge_base = WikipediaKnowledgeBase(
    topics=["Manchester United", "Real Madrid"],
    # Table name: ai.wikipedia_documents
    vector_db=PgVector(
        table_name="wikipedia_documents",
        db_url=vector_db.get_db_connection_local(),
    ),
)

WikipediaKnowledgeBase Params

ParameterTypeDefaultDescription
topicsList[str][]Topics to read

AgentKnowledge Params

WikipediaKnowledgeBase is a subclass of the AgentKnowledge class and has access to the same params

ParameterTypeDefaultDescription
readerOptional[Reader]NoneReader to read the documents
vector_dbOptional[VectorDb]NoneVector db to store the knowledge base
num_documentsint2Number of relevant documents to return on search
optimize_onOptional[int]1000Number of documents to optimize the vector db on
driverstr"knowledge"Driver for the Assistant knowledge