LightRAG
Insert a PDF and a Wikipedia page into a LightRAG knowledge base and query it with an agent.
Prepare the sample input files in the directory where you will run the Python example:
mkdir -p data
curl --fail --location https://raw.githubusercontent.com/agno-agi/agno/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/07_knowledge/testing_resources/cv_1.pdf --output data/cv_1.pdfCode
from os import getenv
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.wikipedia_reader import WikipediaReader
from agno.vectordb.lightrag import LightRag
vector_db = LightRag(
api_key=getenv("LIGHTRAG_API_KEY"),
)
knowledge = Knowledge(
name="My LightRag Knowledge Base",
description="This is a knowledge base that uses a LightRag Vector DB",
vector_db=vector_db,
)
knowledge.insert(
name="CV",
path="data/cv_1.pdf",
metadata={"doc_type": "cv"},
)
knowledge.insert(
name="Manchester United",
topics=["Manchester United"],
reader=WikipediaReader(),
)
knowledge.insert(
name="Manchester United",
url="https://en.wikipedia.org/wiki/Manchester_United_F.C.",
)
agent = Agent(
knowledge=knowledge,
search_knowledge=True,
read_chat_history=False,
)
agent.print_response("What skills does Jordan Mitchell have?", markdown=True)
agent.print_response(
"In what year did Manchester United change their name?", markdown=True
)Usage
This example requires a running LightRAG server. LightRag connects to http://localhost:9621 by default. Pass server_url to use a different address.
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno pypdf wikipedia beautifulsoup4 openaiSet environment variables
export LIGHTRAG_API_KEY="your-lightrag-api-key"
export OPENAI_API_KEY=xxxRun Agent
python lightrag_db.py