> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chonkie.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Milvus Handshake

> Export Chonkie's Chunks into a Milvus collection.

The `MilvusHandshake` class provides seamless integration between Chonkie's chunking system and Milvus, a powerful, open-source vector database.

Embed and store your Chonkie chunks in a Milvus collection, with automatic schema and index creation, without ever leaving the Chonkie SDK.

## Installation

Before using the Milvus handshake, make sure to install the required dependencies:

```bash theme={"system"}
pip install chonkie[milvus]
```

## Basic Usage

### Initialization

<CodeGroup>
  ```python Initialize for a Local Instance theme={"system"}
  from chonkie import MilvusHandshake

  # Connects to Milvus at http://localhost:19530 by default
  handshake = MilvusHandshake()
  ```

  ```python Initialize using a URI theme={"system"}
  from chonkie import MilvusHandshake

  # Recommended for connecting to remote or secured instances
  handshake = MilvusHandshake(
      uri=os.getenv("MILVUS_URI"),
      user=os.getenv("MILVUS_USER"),
      api_key=os.getenv("MILVUS_API_KEY"),
      collection_name="test_collection",
  )
  ```
</CodeGroup>

### Parameters

<ParamField path="collection_name" type="Union[str, Literal['random']]" default="random">
  The name of the Milvus collection to use. If "random", a unique name is generated.
</ParamField>

<ParamField path="embedding_model" type="Union[str, BaseEmbeddings]" default="minishlab/potion-retrieval-32M">
  The embedding model to use for creating vectors.
</ParamField>

<ParamField path="uri" type="Optional[str]" default="None">
  The full URI to connect to Milvus. This is the preferred method for specifying connection details.
</ParamField>

<ParamField path="host" type="str" default="localhost">
  The host of the Milvus instance. Used if `uri` is not provided.
</ParamField>

<ParamField path="port" type="str" default="19530">
  The port of the Milvus instance. Used if `uri` is not provided.
</ParamField>

<ParamField path="alias" type="str" default="default">
  The connection alias to use for this Milvus connection.
</ParamField>

### Writing Chunks to Milvus

```python theme={"system"}
from chonkie import MilvusHandshake, SentenceChunker

# Initialize the handshake for your deployment
handshake = MilvusHandshake(
    uri="http://localhost:19530",
    collection_name="my_documents",
)

# Create some chunks
chunker = SentenceChunker()
chunks = chunker.chunk("Milvus stores data in collections. Chonkie makes ingestion easy!")

# Write chunks to the Milvus collection
handshake.write(chunks)
```

### Searching Chunks in Milvus

You can retrieve the most similar chunks from your Milvus collection using the `search` method.

<CodeGroup>
  ```python Search using a Text Query theme={"system"}
  from chonkie import MilvusHandshake

  # Initialize the handshake to connect to your collection
  handshake = MilvusHandshake(
      uri="http://localhost:19530",
      collection_name="my_documents",
  )

  results = handshake.search(query="easy data ingestion", limit=2)
  ```

  ```python Search using an Embedding Vector theme={"system"}
  from chonkie import MilvusHandshake

  # Initialize the handshake
  handshake = MilvusHandshake(
      uri="http://localhost:19530",
      collection_name="my_documents",
  )

  # Generate an embedding vector for your query
  embedding = handshake.embedding_model.embed("easy data ingestion")

  results = handshake.search(embedding=embedding, limit=2)
  ```
</CodeGroup>
