LanceDB - Building advanced video understanding applications

Summary: This integration allows you to create advanced video understanding and retrieval applications. It combines two key components:

  • TwelveLabs’ Embed API: Generates multimodal embeddings for video content and text.
  • LanceDB: A serverless vector database that stores, indexes, and queries high-dimensional vectors at scale.

Key use cases include:

  • Semantic video search engines
  • Content-based recommendation systems
  • Anomaly detection in video streams.

Description: The process of performing a semantic video search using Twleve Labs and LanceDB involves two main steps:

  1. Use the Embed API to create multimodal embeddings for video content and text queries.
  2. Use the embeddings to perform similarity searches in LanceDB.

Step-by-step guide: Our blog post, Building Advanced Video Understanding ApplicationsL Integrating TwelveLabs Embed API with LanceDB for Multimodal AI, guides you through the process of creating a video search application, from setup to generating video embeddings and querying them efficiently.
Colab Notebook: TwelveLabs-EmbedAPI-LanceDB

Integration with TwelveLabs

This section describes how you can use the TwelveLabs Python SDK to create embeddings for videos and text queries.

Video embeddings

The generate_embedding function takes the URL of a video as a parameter and returns a list of dictionaries, each containing an embedding vector and the associated metadata:

Node.js
1from twelvelabs.models.embed import EmbeddingsTask
2
3def generate_embedding(video_url: str) -> tuple[List[Dict[str, Any]], Any]:
4 """Generate embeddings for a given video URL."""
5 task = twelvelabs_client.embed.task.create(
6 engine_name="Marengo-retrieval-2.6",
7 video_url=video_url
8 )
9
10 def on_task_update(task: EmbeddingsTask):
11 print(f" Status={task.status}")
12
13 task.wait_for_done(sleep_interval=2, callback=on_task_update)
14 task_result = twelvelabs_client.embed.task.retrieve(task.id)
15
16 embeddings = [{
17 'embedding': v.embedding.float,
18 'start_offset_sec': v.start_offset_sec,
19 'end_offset_sec': v.end_offset_sec,
20 'embedding_scope': v.embedding_scope
21 } for v in task_result.video_embeddings]
22
23 return embeddings, task_result

For more details, see the Create video embeddings page.

Text embeddings

The get_text_embedding function generates embeddings for text queries:

Node.js
1def get_text_embedding(text_query: str) -> List[float]:
2 """Generate a text embedding for a given text query."""
3 return twelvelabs_client.embed.text(text_query).embedding.float

For more details, see the Create text embeddings page.

Next steps

After reading this page, you have the following options:

  • Customize and use the example: Use the TwelveLabs-EmbedAPI-LanceDB 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:
  • Explore further: Try the applications built by the community or our 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.
Built with