LightRAG Vector Database

Connect your Knowledge Base to a LightRAG server for graph-based retrieval.

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.pdf

Setup

uv pip install -U agno pypdf openai

LightRag connects to a running LightRAG server over HTTP. The default server URL is http://localhost:9621.

export LIGHTRAG_SERVER_URL="http://localhost:9621"
export LIGHTRAG_API_KEY="your-api-key"  # if your server requires one

The example uses OpenAI for the agent model, so set your API key:

export OPENAI_API_KEY=xxx

Example

agent_with_knowledge.py
from os import getenv

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lightrag import LightRag

vector_db = LightRag(
    server_url=getenv("LIGHTRAG_SERVER_URL", "http://localhost:9621"),
    api_key=getenv("LIGHTRAG_API_KEY"),
)

knowledge = Knowledge(
    name="LightRAG Knowledge Base",
    vector_db=vector_db,
)

knowledge.insert(
    name="CV",
    path="data/cv_1.pdf",
)

agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
)
agent.print_response("What skills does Jordan Mitchell have?", markdown=True)

Inserted content is uploaded to the LightRAG server for indexing. Searches query the server in hybrid mode and return its response as a document, with source references preserved in meta_data["references"].

Search filters are not supported. Indexing happens on the server after upload, so documents may take a moment to become searchable.

Async Support ⚡

LightRAG also supports asynchronous operations, enabling concurrency and leading to better performance.

async_lightrag_db.py
import asyncio
from os import getenv

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lightrag import LightRag

vector_db = LightRag(
    server_url=getenv("LIGHTRAG_SERVER_URL", "http://localhost:9621"),
    api_key=getenv("LIGHTRAG_API_KEY"),
)

knowledge = Knowledge(
    name="LightRAG Knowledge Base",
    vector_db=vector_db,
)

agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
)

if __name__ == "__main__":
    asyncio.run(
        knowledge.ainsert(
            name="CV",
            path="data/cv_1.pdf",
        )
    )

    asyncio.run(
        agent.aprint_response("What skills does Jordan Mitchell have?", markdown=True)
    )

Use ainsert() and aprint_response() methods with asyncio.run() for non-blocking operations in high-throughput applications.

LightRag Params

ParameterTypeDefaultDescription
server_urlstr"http://localhost:9621"URL of the LightRAG server.
api_keystrNoneAPI key for the LightRAG server.
auth_header_namestr"X-API-KEY"Name of the authentication header.
auth_header_formatstr"{api_key}"Format string for the authentication header value.
namestrNoneName of the vector database.
descriptionstrNoneDescription of the vector database.

Native Agno user_id scoping is not applied by this wrapper. Configure user-specific retrieval in the external retriever or server when needed.