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

# LightRAG Async

> Load and query a LightRAG knowledge base asynchronously with ainsert() and aprint_response().

## Code

```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.knowledge.reader.wikipedia_reader import WikipediaReader
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",
    description="Knowledge base using LightRAG for graph-based retrieval",
    vector_db=vector_db,
)

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


async def main() -> None:
    await knowledge.ainsert(
        name="CV",
        path="data/cv_1.pdf",
        metadata={"doc_type": "cv"},
    )
    await knowledge.ainsert(
        name="Manchester United",
        topics=["Manchester United"],
        reader=WikipediaReader(),
    )
    await knowledge.ainsert(
        name="CV 2",
        path="data/cv_2.pdf",
    )

    # Give the server time to index the uploaded documents
    await asyncio.sleep(60)

    await agent.aprint_response("What skills does Jordan Mitchell have?", markdown=True)
    await agent.aprint_response(
        "In what year did Manchester United change their name?",
        markdown=True,
    )

    results = await vector_db.async_search("What skills does Jordan Mitchell have?")
    if results:
        doc = results[0]
        print(f"References: {doc.meta_data.get('references', [])}")


if __name__ == "__main__":
    asyncio.run(main())
```

## Usage

<Note>
  This example requires a running LightRAG server. It connects to `http://localhost:9621` unless `LIGHTRAG_SERVER_URL` is set.
</Note>

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno pypdf wikipedia openai
    ```
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export LIGHTRAG_API_KEY="your-lightrag-api-key"
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="Run Agent">
    ```bash theme={null}
    python async_lightrag_db.py
    ```
  </Step>
</Steps>
