> This page is for version v1.3 (default).
> For other versions, use one of these documentation indexes:
> - v1.3 (default): https://docs.twelvelabs.io/v1.3/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.twelvelabs.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.twelvelabs.io/_mcp/server.

# Milvus - Advanced video search

> Build semantic video search with the TwelveLabs Embed API and Milvus vector DB.

![](/_fern-img/690b13096d6e6410223567943c6f4677e1122fed83e8aec13ab0a710064baf9b.webp)

**Summary**:  This integration creates an efficient semantic video search solution by combining TwelveLabs' [Embed API](/docs/guides/create-embeddings), which generates multimodal embeddings from video content, with Milvus,  an open-source vector database that provides efficient storage and retrieval for your embeddings. This integration enables you to incorporate video content analysis capabilities into your applications.

Key use cases include:

* Content-based video retrieval
* Recommendation systems
* Search engines that understand the nuances of video data.

**Description**: The process of performing a semantic video search using the Embed API and Milvus involves two main steps:

1. Create multimodal embeddings for your video content using the Embed API.
2. Use the embeddings created in the previous step to perform similarity searches in Milvus.

**Code explanation**: Our blog post, [Advanced Video Search: Leveraging TwelveLabs and Milvus for Semantic Search](https://www.twelvelabs.io/blog/twelve-labs-and-milvus), guides you through the process of creating a video search application, from setup to performing searches.

**Colab Notebook**: [TwelveLabs-EmbedAPI-Milvus](https://colab.research.google.com/drive/1nTOAxo82E71_d9XhSfFuVmkMPv1Fj4u9?usp=sharing)

# Integration with TwelveLabs

This section describes how you can use the [TwelveLabs Python SDK](https://github.com/twelvelabs-io/twelvelabs-python) to create video embeddings for semantic video search. The `generate_embedding` function returns a list of dictionaries, each containing an embedding vector and the associated metadata:

**`Python`**

```python Python
def generate_embedding(video_url):
		"""
    Generate embeddings for a given video URL using the TwelveLabs API.

    This function creates an embedding task for the specified video URL using
    the Marengo-retrieval-2.7 engine. It monitors the task progress and waits
    for completion. Once done, it retrieves the task result and extracts the
    embeddings along with their associated metadata.

    Args:
        video_url (str): The URL of the video to generate embeddings for.

    Returns:
        tuple: A tuple containing two elements:
            1. list: A list of dictionaries, where each dictionary contains:
                - 'embedding': The embedding vector as a list of floats.
                - 'start_offset_sec': The start time of the segment in seconds.
                - 'end_offset_sec': The end time of the segment in seconds.
                - 'embedding_scope': The scope of the embedding (e.g., 'shot', 'scene').
            2. EmbeddingsTaskResult: The complete task result object from TwelveLabs API.

    Raises:
        Any exceptions raised by the TwelveLabs API during task creation,
        execution, or retrieval.
    """

    # Create an embedding task
    task = twelvelabs_client.embed.task.create(
        engine_name="Marengo-retrieval-2.7",
        video_url=video_url
    )
    print(f"Created task: id={task.id} engine_name={task.engine_name} status={task.status}")

    # Define a callback function to monitor task progress
    def on_task_update(task: EmbeddingsTask):
        print(f"  Status={task.status}")

    # Wait for the task to complete
    status = task.wait_for_done(
        sleep_interval=2,
        callback=on_task_update
    )
    print(f"Embedding done: {status}")

    # Retrieve the task result
    task_result = twelvelabs_client.embed.task.retrieve(task.id)

    # Extract and return the embeddings
    embeddings = []
    for v in task_result.video_embeddings:
        embeddings.append({
            'embedding': v.embedding.float,
            'start_offset_sec': v.start_offset_sec,
            'end_offset_sec': v.end_offset_sec,
            'embedding_scope': v.embedding_scope
        })
    
    return embeddings, task_result
```

For more details on how to create and customize video embeddings, see the [Create video embeddings](https://docs.twelvelabs.io/docs/create-video-embeddings) page.

# Next steps

After reading this page, you have the following options:

* **Customize and use the example**: Use the [TwelveLabs-EmbedAPI-Milvus](https://colab.research.google.com/drive/1nTOAxo82E71_d9XhSfFuVmkMPv1Fj4u9?usp=sharing) notebook to understand how the integration works. You can make changes and add more functionalities to suit your specific use case. Some notable examples include:
  * **Combine text and video queries for hybrid search**: Use the Embed API to [create text embeddings](/docs/guides/create-embeddings/query) for your queries. Then, you can perform weighted searches in Milvus using both text and video embeddings.
  * **Search within specific parts of videos**: Break long videos into smaller segments. Create an embedding for each segment to find specific moments in videos. To adjust the timing and length of your embeddings, see [Customize your embeddings](/docs/guides/create-embeddings/at-scale/video#customize-your-embeddings).
  * **Analyze video content**: Use embeddings to group similar video segments. This helps you detect trends or find unusual content in large video collections.
* **Explore further**: Try the [applications built by the community](https://docs.twelvelabs.io/docs/from-the-community) or our [sample applications](https://docs.twelvelabs.io/docs/sample-applications) to get more insights into the TwelveLabs Video Understanding Platform's diverse capabilities and learn more about integrating the platform into your applications.