> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LightRAG Vector Database

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

## Setup

```shell theme={null}
uv pip install -U agno pypdf openai
```

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

```shell theme={null}
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:

```shell theme={null}
export OPENAI_API_KEY=xxx
```

## Example

```python agent_with_knowledge.py theme={null}
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"]`.

> [!NOTE]
>
> 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.
>
> ```python async_lightrag_db.py theme={null}
> 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)
>     )
> ```
>
> > [!TIP]
> >
> > Use `ainsert()` and `aprint_response()` methods with `asyncio.run()` for non-blocking operations in high-throughput applications.

## LightRag Params

<Snippet file="vectordb_lightrag_params.mdx" />


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.