> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-service-account.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 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
```

## 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.
</Note>

<Card title="Async Support ⚡">
  <div className="mt-2">
    <p>
      LightRAG also supports asynchronous operations, enabling concurrency and leading to better performance.
    </p>

    ```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 className="mt-4">
      Use <code>ainsert()</code> and <code>aprint\_response()</code> methods with <code>asyncio.run()</code> for non-blocking operations in high-throughput applications.
    </Tip>
  </div>
</Card>

## LightRag Params

<Snippet file="vectordb_lightrag_params.mdx" />
