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

# Milvus Vector Database

> Use Milvus as a vector database for your Knowledge Base.

## Setup

```shell theme={null}
uv pip install pymilvus
```

## Initialize Milvus

Set the uri and token for your Milvus server.

* If you only need a local vector database for small scale data or prototyping, setting the uri as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.
* If you have large scale data, say more than a million vectors, you can set up a more performant Milvus server on [Docker or Kubernetes](https://milvus.io/docs/quickstart.md).
  In this setup, please use the server address and port as your uri, e.g.`http://localhost:19530`. If you enable the authentication feature on Milvus, use `your_username:your_password` as the token, otherwise don't set the token.
* If you use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and API key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#cluster-details) in Zilliz Cloud.

## Example

```python agent_with_knowledge.py theme={null}
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.milvus import Milvus

vector_db = Milvus(
    collection="recipes",
    uri="./milvus.db",
)
# Create knowledge base
knowledge_base = Knowledge(
    vector_db=vector_db,
)

# Create and use the agent
agent = Agent(knowledge=knowledge_base)

if __name__ == "__main__":
    knowledge_base.insert(
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
    )

    agent.print_response("How to make Tom Kha Gai", markdown=True)
    agent.print_response("What was my last question?", stream=True)
```

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

    ```python async_milvus_db.py theme={null}
    # install pymilvus - `pip install pymilvus`
    import asyncio

    from agno.agent import Agent
    from agno.knowledge.knowledge import Knowledge
    from agno.vectordb.milvus import Milvus

    # Initialize Milvus with local file
    vector_db = Milvus(
        collection="recipes",
        uri="tmp/milvus.db",  # For local file-based storage
    )

    # Create knowledge base
    knowledge_base = Knowledge(
        vector_db=vector_db,
    )

    # Create agent with knowledge base
    agent = Agent(knowledge=knowledge_base)

    if __name__ == "__main__":
        # Load knowledge base asynchronously
        asyncio.run(knowledge_base.ainsert(
                url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
            )
        )

        # Query the agent asynchronously
        asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
    ```

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

## Milvus Params

<Snippet file="vectordb_milvus_params.mdx" />

Advanced options can be passed as additional keyword arguments to the `MilvusClient` constructor.
