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

# Qdrant Handshake

> Export Chonkie's Chunks into a Qdrant collection.

The `QdrantHandshake` class provides seamless integration between Chonkie's chunking system and Qdrant, a high-performance vector database.

Embed and store your Chonkie chunks in Qdrant without ever leaving the Chonkie SDK.

## Installation

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

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

## Basic Usage

### Initialization

<CodeGroup>
  ```python Initialize using chonkie theme={"system"}
  from chonkie import QdrantHandshake
  handshake = QdrantHandshake(url="http://localhost:6333")
  ```

  ```python initialize using the client theme={"system"}
  from qdrant_client import QdrantClient
  client = QdrantClient(":memory:")
  handshake = QdrantHandshake(client=client, collection_name="my_collection")
  ```

  ```python qdrant cloud Initialization theme={"system"}
  from qdrant_client import QdrantClient
  handshake = QdrantHandshake(
      url="YOUR_CLOUD_URL",
      api_key="YOUR_API_KEY",
  )
  ```
</CodeGroup>

# Parameters

<ParamField path="client" type="Optional[qdrant_client.QdrantClient]" default="None">
  Qdrant client instance. If not provided, a new client will be created based on other parameters.
</ParamField>

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

<ParamField path="embedding_model" type="Union[str, BaseEmbeddings]" default="minishlab/potion-retrieval-32M">
  Embedding model to use. Can be a model name or a BaseEmbeddings instance.
</ParamField>

<ParamField path="url" type="Optional[str]" default="None">
  URL of the Qdrant server. If provided, will connect to this server.
</ParamField>

<ParamField path="path" type="Optional[str]" default="None">
  If provided, creates a persistent Qdrant client at the specified path.
</ParamField>

<ParamField path="api_key" type="Optional[str]" default="None">
  API key for Qdrant Cloud authentication.
</ParamField>

### Writing Chunks to Qdrant

```python theme={"system"}
from chonkie import QdrantHandshake, SemanticChunker    

# Initialize the handshake
handshake = QdrantHandshake(
    url="YOUR_CLOUD_URL",
    api_key="YOUR_API_KEY",
    collection_name="my_documents",
)

# Create some chunks
chunker = SemanticChunker()
chunks = chunker.chunk("Chonkie loves to chonk your texts!")

# Write chunks to Qdrant
handshake.write(chunks)
```

### Searching Chunks in Qdrant

You can retrieve the most similar chunks from your Qdrant collection using the `search` method:

<CodeGroup>
  ```python search using a query theme={"system"}
  from chonkie import QdrantHandshake

  # Initialize the handshake
  handshake = QdrantHandshake(
      url="YOUR_CLOUD_URL",
      api_key="YOUR_API_KEY",
      collection_name="my_documents",
  )
  results = handshake.search(query="chonk your texts", limit=2)
  for result in results:
      print(result["score"], result["text"])
  ```

  ```python search using embedding theme={"system"}
  from chonkie import QdrantHandshake

  # Initialize the handshake
  handshake = QdrantHandshake(
      url="YOUR_CLOUD_URL",
      api_key="YOUR_API_KEY",
      collection_name="my_documents",
  )
  embedding = handshake.embedding_model.embed("chonk your texts").tolist()
  results = handshake.search(embedding=embedding, limit=2)
  for result in results:
      print(result["score"], result["text"])
  ```

  ```python search using chonkie chunks theme={"system"}
  from chonkie import QdrantHandshake, SemanticChunker

  # Initialize the handshake
  handshake = QdrantHandshake(
      url="YOUR_CLOUD_URL",
      api_key="YOUR_API_KEY",
      collection_name="my_documents",
  )

  # Create some chunks
  chunker = SemanticChunker(embedding_model=handshake.embedding_model)
  chunks = chunker.chunk("Chonkie loves to chonk your texts!")

  # Search the handshake
  results = handshake.search(
      embedding=chunks[0].sentences[0].embedding, 
      limit=2,
  )
  for result in results:
      print(result["score"], result["text"])
  ```
</CodeGroup>
