From d2d57491af67eed882918ddbf39dca311f1268ad Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Thu, 29 May 2025 17:57:44 +0530 Subject: [PATCH 01/15] Add clip support --- videodb/video.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/videodb/video.py b/videodb/video.py index eb4da7b..ab8ae1a 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -562,6 +562,31 @@ def add_subtitle(self, style: SubtitleStyle = SubtitleStyle()) -> str: ) return subtitle_data.get("stream_url", None) + def clip( + self, + query: str, + content_type: str, + model_name: str, + ) -> str: + """Generate a clip from the video using a prompt. + + :param str query: Prompt to generate the clip + :param str content_type: Content type for the clip + :param str model_name: Model name for generation + :return: The stream url of the generated clip + :rtype: str + """ + + clip_data = self._connection.post( + path=f"{ApiPath.video}/{self.id}/{ApiPath.clip}", + data={ + "prompt": query, + "content_type": content_type, + "model_name": model_name, + }, + ) + return clip_data.get("stream_url") + def insert_video(self, video, timestamp: float) -> str: """Insert a video into another video From 39fadd0c841add83c220cfc2b945fd9d24593172 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Thu, 29 May 2025 18:03:25 +0530 Subject: [PATCH 02/15] Fix param of video clip to prompt from query --- videodb/video.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/videodb/video.py b/videodb/video.py index ab8ae1a..0a19d82 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -564,13 +564,13 @@ def add_subtitle(self, style: SubtitleStyle = SubtitleStyle()) -> str: def clip( self, - query: str, + prompt: str, content_type: str, model_name: str, ) -> str: """Generate a clip from the video using a prompt. - :param str query: Prompt to generate the clip + :param str prompt: Prompt to generate the clip :param str content_type: Content type for the clip :param str model_name: Model name for generation :return: The stream url of the generated clip @@ -580,7 +580,7 @@ def clip( clip_data = self._connection.post( path=f"{ApiPath.video}/{self.id}/{ApiPath.clip}", data={ - "prompt": query, + "prompt": prompt, "content_type": content_type, "model_name": model_name, }, From c787a0127b191ed49f36a5ea98ba7d51252e30e5 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Thu, 29 May 2025 18:06:23 +0530 Subject: [PATCH 03/15] Add api path for clip --- videodb/_constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/videodb/_constants.py b/videodb/_constants.py index 0e80158..7d0904a 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -58,6 +58,7 @@ class ApiPath: index = "index" search = "search" compile = "compile" + clip = "clip" workflow = "workflow" timeline = "timeline" delete = "delete" From 60d7019848d5d2b70ae4814abddb7e32d645793a Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Fri, 30 May 2025 11:29:10 +0530 Subject: [PATCH 04/15] Add rerank support in semantic search for collections and videos --- videodb/_constants.py | 1 + videodb/collection.py | 4 ++++ videodb/search.py | 4 ++++ videodb/video.py | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/videodb/_constants.py b/videodb/_constants.py index 7d0904a..97d0260 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -36,6 +36,7 @@ class Workflows: class SemanticSearchDefaultValues: result_threshold = 5 score_threshold = 0.2 + rerank = False class Segmenter: diff --git a/videodb/collection.py b/videodb/collection.py index e941cf4..a46888e 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -8,6 +8,7 @@ ApiPath, IndexType, SearchType, + SemanticSearchDefaultValues, ) from videodb.video import Video from videodb.audio import Audio @@ -387,6 +388,7 @@ def search( result_threshold: Optional[int] = None, score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, + rerank: bool = SemanticSearchDefaultValues.rerank, filter: List[Dict[str, Any]] = [], ) -> SearchResult: """Search for a query in the collection. @@ -397,6 +399,7 @@ def search( :param int result_threshold: Number of results to return (optional) :param float score_threshold: Threshold score for the search (optional) :param float dynamic_score_percentage: Percentage of dynamic score to consider (optional) + :param bool rerank: Rerank search results (optional) :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -410,6 +413,7 @@ def search( result_threshold=result_threshold, score_threshold=score_threshold, dynamic_score_percentage=dynamic_score_percentage, + rerank=rerank, filter=filter, ) diff --git a/videodb/search.py b/videodb/search.py index ba557be..ac46442 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -123,6 +123,7 @@ def search_inside_video( result_threshold: Optional[int] = None, score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, + rerank: bool = SemanticSearchDefaultValues.rerank, **kwargs, ): search_data = self._connection.post( @@ -136,6 +137,7 @@ def search_inside_video( "result_threshold": result_threshold or SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, + "rerank": rerank, **kwargs, }, ) @@ -150,6 +152,7 @@ def search_inside_collection( result_threshold: Optional[int] = None, score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, + rerank: bool = SemanticSearchDefaultValues.rerank, **kwargs, ): search_data = self._connection.post( @@ -163,6 +166,7 @@ def search_inside_collection( "result_threshold": result_threshold or SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, + "rerank": rerank, **kwargs, }, ) diff --git a/videodb/video.py b/videodb/video.py index 0a19d82..7ed9a2e 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -5,6 +5,7 @@ IndexType, SceneExtractionType, SearchType, + SemanticSearchDefaultValues, Segmenter, SubtitleStyle, Workflows, @@ -69,6 +70,7 @@ def search( result_threshold: Optional[int] = None, score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, + rerank: bool = SemanticSearchDefaultValues.rerank, filter: List[Dict[str, Any]] = [], **kwargs, ) -> SearchResult: @@ -80,6 +82,7 @@ def search( :param int result_threshold: (optional) Number of results to return :param float score_threshold: (optional) Threshold score for the search :param float dynamic_score_percentage: (optional) Percentage of dynamic score to consider + :param bool rerank: (optional) Rerank search results :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -93,6 +96,7 @@ def search( result_threshold=result_threshold, score_threshold=score_threshold, dynamic_score_percentage=dynamic_score_percentage, + rerank=rerank, filter=filter, **kwargs, ) From 710ec9acfcb11c54267a478a648cf5696c131003 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Fri, 30 May 2025 12:58:39 +0530 Subject: [PATCH 05/15] Add rerank_params in semantic search --- videodb/_constants.py | 1 + videodb/collection.py | 3 +++ videodb/search.py | 4 ++++ videodb/video.py | 3 +++ 4 files changed, 11 insertions(+) diff --git a/videodb/_constants.py b/videodb/_constants.py index 97d0260..1c0c63f 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -37,6 +37,7 @@ class SemanticSearchDefaultValues: result_threshold = 5 score_threshold = 0.2 rerank = False + rerank_param = {} class Segmenter: diff --git a/videodb/collection.py b/videodb/collection.py index a46888e..d49e9cf 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -389,6 +389,7 @@ def search( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, + rerank_param: dict = SemanticSearchDefaultValues.rerank_param, filter: List[Dict[str, Any]] = [], ) -> SearchResult: """Search for a query in the collection. @@ -400,6 +401,7 @@ def search( :param float score_threshold: Threshold score for the search (optional) :param float dynamic_score_percentage: Percentage of dynamic score to consider (optional) :param bool rerank: Rerank search results (optional) + :param dict rerank_param: Parameters for reranking (optional) :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -414,6 +416,7 @@ def search( score_threshold=score_threshold, dynamic_score_percentage=dynamic_score_percentage, rerank=rerank, + rerank_param=rerank_param, filter=filter, ) diff --git a/videodb/search.py b/videodb/search.py index ac46442..9528aec 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -124,6 +124,7 @@ def search_inside_video( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, + rerank_param: dict = SemanticSearchDefaultValues.rerank_param, **kwargs, ): search_data = self._connection.post( @@ -138,6 +139,7 @@ def search_inside_video( or SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, + "rerank_param": rerank_param, **kwargs, }, ) @@ -153,6 +155,7 @@ def search_inside_collection( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, + rerank_param: dict = SemanticSearchDefaultValues.rerank_param, **kwargs, ): search_data = self._connection.post( @@ -167,6 +170,7 @@ def search_inside_collection( or SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, + "rerank_param": rerank_param, **kwargs, }, ) diff --git a/videodb/video.py b/videodb/video.py index 7ed9a2e..08ca277 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -71,6 +71,7 @@ def search( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, + rerank_param: dict = SemanticSearchDefaultValues.rerank_param, filter: List[Dict[str, Any]] = [], **kwargs, ) -> SearchResult: @@ -83,6 +84,7 @@ def search( :param float score_threshold: (optional) Threshold score for the search :param float dynamic_score_percentage: (optional) Percentage of dynamic score to consider :param bool rerank: (optional) Rerank search results + :param dict rerank_param: (optional) Parameters for reranking :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -97,6 +99,7 @@ def search( score_threshold=score_threshold, dynamic_score_percentage=dynamic_score_percentage, rerank=rerank, + rerank_param=rerank_param, filter=filter, **kwargs, ) From 52c6c5e5249bb81dc885f614b84ca92cccf20c54 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Fri, 30 May 2025 13:02:52 +0530 Subject: [PATCH 06/15] Fix rrank param name to rerank_params --- videodb/_constants.py | 2 +- videodb/collection.py | 6 +++--- videodb/search.py | 8 ++++---- videodb/video.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/videodb/_constants.py b/videodb/_constants.py index 1c0c63f..0bb1036 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -37,7 +37,7 @@ class SemanticSearchDefaultValues: result_threshold = 5 score_threshold = 0.2 rerank = False - rerank_param = {} + rerank_params = {} class Segmenter: diff --git a/videodb/collection.py b/videodb/collection.py index d49e9cf..e857ece 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -389,7 +389,7 @@ def search( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, - rerank_param: dict = SemanticSearchDefaultValues.rerank_param, + rerank_params: dict = SemanticSearchDefaultValues.rerank_params, filter: List[Dict[str, Any]] = [], ) -> SearchResult: """Search for a query in the collection. @@ -401,7 +401,7 @@ def search( :param float score_threshold: Threshold score for the search (optional) :param float dynamic_score_percentage: Percentage of dynamic score to consider (optional) :param bool rerank: Rerank search results (optional) - :param dict rerank_param: Parameters for reranking (optional) + :param dict rerank_params: Parameters for reranking (optional) :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -416,7 +416,7 @@ def search( score_threshold=score_threshold, dynamic_score_percentage=dynamic_score_percentage, rerank=rerank, - rerank_param=rerank_param, + rerank_params=rerank_params, filter=filter, ) diff --git a/videodb/search.py b/videodb/search.py index 9528aec..b27f469 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -124,7 +124,7 @@ def search_inside_video( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, - rerank_param: dict = SemanticSearchDefaultValues.rerank_param, + rerank_params: dict = SemanticSearchDefaultValues.rerank_params, **kwargs, ): search_data = self._connection.post( @@ -139,7 +139,7 @@ def search_inside_video( or SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, - "rerank_param": rerank_param, + "rerank_params": rerank_params, **kwargs, }, ) @@ -155,7 +155,7 @@ def search_inside_collection( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, - rerank_param: dict = SemanticSearchDefaultValues.rerank_param, + rerank_params: dict = SemanticSearchDefaultValues.rerank_params, **kwargs, ): search_data = self._connection.post( @@ -170,7 +170,7 @@ def search_inside_collection( or SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, - "rerank_param": rerank_param, + "rerank_params": rerank_params, **kwargs, }, ) diff --git a/videodb/video.py b/videodb/video.py index 08ca277..3a2c26a 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -71,7 +71,7 @@ def search( score_threshold: Optional[float] = None, dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, - rerank_param: dict = SemanticSearchDefaultValues.rerank_param, + rerank_params: dict = SemanticSearchDefaultValues.rerank_params, filter: List[Dict[str, Any]] = [], **kwargs, ) -> SearchResult: @@ -84,7 +84,7 @@ def search( :param float score_threshold: (optional) Threshold score for the search :param float dynamic_score_percentage: (optional) Percentage of dynamic score to consider :param bool rerank: (optional) Rerank search results - :param dict rerank_param: (optional) Parameters for reranking + :param dict rerank_params: (optional) Parameters for reranking :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -99,7 +99,7 @@ def search( score_threshold=score_threshold, dynamic_score_percentage=dynamic_score_percentage, rerank=rerank, - rerank_param=rerank_param, + rerank_params=rerank_params, filter=filter, **kwargs, ) From 6378ca61fa5cdc465b8e2db5e5e6b8c6dea5131e Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Fri, 30 May 2025 16:10:05 +0530 Subject: [PATCH 07/15] Add segmenation type in spoken index --- videodb/video.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/videodb/video.py b/videodb/video.py index 3a2c26a..0ec11ac 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -284,12 +284,14 @@ def translate_transcript( def index_spoken_words( self, language_code: Optional[str] = None, + segmentation_type: Optional[str] = None, force: bool = False, callback_url: str = None, ) -> None: """Semantic indexing of spoken words in the video. :param str language_code: (optional) Language code of the video + :param str segmentation_type: (optional) Segmentation type used for indexing :param bool force: (optional) Force to index the video :param str callback_url: (optional) URL to receive the callback :raises InvalidRequestError: If the video is already indexed @@ -301,6 +303,7 @@ def index_spoken_words( data={ "index_type": IndexType.spoken_word, "language_code": language_code, + "segmentation_type": segmentation_type, "force": force, "callback_url": callback_url, }, From 60fdc5e984509bf38ef60fd0e3f121ba7f452292 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Mon, 2 Jun 2025 15:10:19 +0530 Subject: [PATCH 08/15] Allow 0 as score threshold and result threshold --- videodb/search.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/videodb/search.py b/videodb/search.py index b27f469..94efcd1 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -134,9 +134,11 @@ def search_inside_video( "index_type": index_type, "query": query, "score_threshold": score_threshold - or SemanticSearchDefaultValues.score_threshold, + if score_threshold is not None + else SemanticSearchDefaultValues.score_threshold, "result_threshold": result_threshold - or SemanticSearchDefaultValues.result_threshold, + if result_threshold is not None + else SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, "rerank_params": rerank_params, @@ -165,9 +167,11 @@ def search_inside_collection( "index_type": index_type, "query": query, "score_threshold": score_threshold - or SemanticSearchDefaultValues.score_threshold, + if score_threshold is not None + else SemanticSearchDefaultValues.score_threshold, "result_threshold": result_threshold - or SemanticSearchDefaultValues.result_threshold, + if result_threshold is not None + else SemanticSearchDefaultValues.result_threshold, "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, "rerank_params": rerank_params, From 723fa12e419b3405fa7f8eea0649d1d43397ce24 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Tue, 10 Jun 2025 16:42:51 +0530 Subject: [PATCH 09/15] Add hybrid search option --- videodb/_constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/videodb/_constants.py b/videodb/_constants.py index 0bb1036..43e9fde 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -22,6 +22,7 @@ class SearchType: class IndexType: spoken_word = "spoken_word" scene = "scene" + hybrid = "hybrid" class SceneExtractionType: From 163921e02b59342996c2b797c1619f8219ce2440 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Wed, 11 Jun 2025 16:20:36 +0530 Subject: [PATCH 10/15] Add scene index id and name in the shot of search response --- videodb/search.py | 4 ++++ videodb/shot.py | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/videodb/search.py b/videodb/search.py index 94efcd1..a536d65 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -34,6 +34,8 @@ def __init__(self, _connection, **kwargs): def _format_results(self): for result in self._results: self.collection_id = result.get("collection_id") + scene_index_id = result.get("scene_index_id") + scene_index_name = result.get("scene_index_name") for doc in result.get("docs"): self.shots.append( Shot( @@ -45,6 +47,8 @@ def _format_results(self): doc.get("end"), doc.get("text"), doc.get("score"), + scene_index_id=scene_index_id, + scene_index_name=scene_index_name, ) ) diff --git a/videodb/shot.py b/videodb/shot.py index c2fadcb..484ff6b 100644 --- a/videodb/shot.py +++ b/videodb/shot.py @@ -19,6 +19,8 @@ class Shot: :ivar int search_score: Search relevance score :ivar str stream_url: URL to stream the shot :ivar str player_url: URL to play the shot in a player + :ivar Optional[str] scene_index_id: ID of the scene index for scene search results + :ivar Optional[str] scene_index_name: Name of the scene index for scene search results """ def __init__( @@ -31,6 +33,8 @@ def __init__( end: float, text: Optional[str] = None, search_score: Optional[int] = None, + scene_index_id: Optional[str] = None, + scene_index_name: Optional[str] = None, ) -> None: self._connection = _connection self.video_id = video_id @@ -40,21 +44,33 @@ def __init__( self.end = end self.text = text self.search_score = search_score + self.scene_index_id = scene_index_id + self.scene_index_name = scene_index_name self.stream_url = None self.player_url = None def __repr__(self) -> str: - return ( + repr_str = ( f"Shot(" f"video_id={self.video_id}, " f"video_title={self.video_title}, " f"start={self.start}, " f"end={self.end}, " f"text={self.text}, " - f"search_score={self.search_score}, " - f"stream_url={self.stream_url}, " + f"search_score={self.search_score}" + ) + if self.scene_index_id: + repr_str += f", scene_index_id={self.scene_index_id}" + + if self.scene_index_name: + repr_str += f", scene_index_name={self.scene_index_name}" + + repr_str += ( + f", stream_url={self.stream_url}, " f"player_url={self.player_url})" ) + return repr_str + def __getitem__(self, key): """Get an item from the shot object""" From bf02b6a65a953ea17c3176b9e80f9445e7da68d7 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Wed, 11 Jun 2025 18:10:18 +0530 Subject: [PATCH 11/15] Put scene index id and name of shots in search result at doc level and introduce metadata --- videodb/search.py | 7 +++---- videodb/shot.py | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/videodb/search.py b/videodb/search.py index a536d65..a5e53ff 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -34,8 +34,6 @@ def __init__(self, _connection, **kwargs): def _format_results(self): for result in self._results: self.collection_id = result.get("collection_id") - scene_index_id = result.get("scene_index_id") - scene_index_name = result.get("scene_index_name") for doc in result.get("docs"): self.shots.append( Shot( @@ -47,8 +45,9 @@ def _format_results(self): doc.get("end"), doc.get("text"), doc.get("score"), - scene_index_id=scene_index_id, - scene_index_name=scene_index_name, + scene_index_id=doc.get("scene_index_id"), + scene_index_name=doc.get("scene_index_name"), + metadata=doc.get("metadata"), ) ) diff --git a/videodb/shot.py b/videodb/shot.py index 484ff6b..2fee6d4 100644 --- a/videodb/shot.py +++ b/videodb/shot.py @@ -21,6 +21,7 @@ class Shot: :ivar str player_url: URL to play the shot in a player :ivar Optional[str] scene_index_id: ID of the scene index for scene search results :ivar Optional[str] scene_index_name: Name of the scene index for scene search results + :ivar Optional[dict] metadata: Additional metadata for the shot """ def __init__( @@ -35,6 +36,8 @@ def __init__( search_score: Optional[int] = None, scene_index_id: Optional[str] = None, scene_index_name: Optional[str] = None, + metadata: Optional[dict] = None, + ) -> None: self._connection = _connection self.video_id = video_id @@ -46,6 +49,7 @@ def __init__( self.search_score = search_score self.scene_index_id = scene_index_id self.scene_index_name = scene_index_name + self.metadata = metadata self.stream_url = None self.player_url = None @@ -65,6 +69,9 @@ def __repr__(self) -> str: if self.scene_index_name: repr_str += f", scene_index_name={self.scene_index_name}" + if self.metadata: + repr_str += f", metadata={self.metadata}" + repr_str += ( f", stream_url={self.stream_url}, " f"player_url={self.player_url})" From c431d8034455240d22b08ace9ccc74c7eb366f30 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Wed, 11 Jun 2025 18:19:00 +0530 Subject: [PATCH 12/15] Give support for sort_docs_on param in collection search --- videodb/_constants.py | 1 + videodb/collection.py | 3 +++ videodb/search.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/videodb/_constants.py b/videodb/_constants.py index 43e9fde..2479ba9 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -39,6 +39,7 @@ class SemanticSearchDefaultValues: score_threshold = 0.2 rerank = False rerank_params = {} + sort_docs_on = None class Segmenter: diff --git a/videodb/collection.py b/videodb/collection.py index e857ece..4e2dcdb 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -390,6 +390,7 @@ def search( dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, rerank_params: dict = SemanticSearchDefaultValues.rerank_params, + sort_docs_on: str = SemanticSearchDefaultValues.sort_docs_on, filter: List[Dict[str, Any]] = [], ) -> SearchResult: """Search for a query in the collection. @@ -402,6 +403,7 @@ def search( :param float dynamic_score_percentage: Percentage of dynamic score to consider (optional) :param bool rerank: Rerank search results (optional) :param dict rerank_params: Parameters for reranking (optional) + :param str sort_docs_on: Parameter to specify what metric to sort the docs of video on :raise SearchError: If the search fails :return: :class:`SearchResult ` object :rtype: :class:`videodb.search.SearchResult` @@ -418,6 +420,7 @@ def search( rerank=rerank, rerank_params=rerank_params, filter=filter, + sort_docs_on=sort_docs_on ) def search_title(self, query) -> List[Video]: diff --git a/videodb/search.py b/videodb/search.py index a5e53ff..7a6eea2 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -161,6 +161,7 @@ def search_inside_collection( dynamic_score_percentage: Optional[float] = None, rerank: bool = SemanticSearchDefaultValues.rerank, rerank_params: dict = SemanticSearchDefaultValues.rerank_params, + sort_docs_on: str = SemanticSearchDefaultValues.sort_docs_on, **kwargs, ): search_data = self._connection.post( @@ -178,6 +179,7 @@ def search_inside_collection( "dynamic_score_percentage": dynamic_score_percentage, "rerank": rerank, "rerank_params": rerank_params, + "sort_docs_on": sort_docs_on, **kwargs, }, ) From 72c07ae9fd609f161e10d715089e7d35ea553f89 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Wed, 11 Jun 2025 19:19:30 +0530 Subject: [PATCH 13/15] Add param to access result search metadata --- videodb/search.py | 1 + 1 file changed, 1 insertion(+) diff --git a/videodb/search.py b/videodb/search.py index 7a6eea2..407e1f4 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -29,6 +29,7 @@ def __init__(self, _connection, **kwargs): self.player_url = None self.collection_id = "default" self._results = kwargs.get("results", []) + self.metadata = kwargs.get("meta", None) self._format_results() def _format_results(self): From 6e65feb472e73eaf511ac0473b09786b37e7f4f6 Mon Sep 17 00:00:00 2001 From: ashish-spext Date: Wed, 11 Jun 2025 19:33:20 +0530 Subject: [PATCH 14/15] Give custom search type support --- videodb/_constants.py | 1 + videodb/search.py | 1 + 2 files changed, 2 insertions(+) diff --git a/videodb/_constants.py b/videodb/_constants.py index 2479ba9..c8d920d 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -17,6 +17,7 @@ class SearchType: keyword = "keyword" scene = "scene" llm = "llm" + custom = "custom" class IndexType: diff --git a/videodb/search.py b/videodb/search.py index 407e1f4..7750a57 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -256,6 +256,7 @@ def search_inside_collection(self, **kwargs): SearchType.semantic: SemanticSearch, SearchType.keyword: KeywordSearch, SearchType.scene: SceneSearch, + SearchType.custom: SemanticSearch, } From e22fe8a5c65819e1d73d78db250f6daad560e294 Mon Sep 17 00:00:00 2001 From: Rohit Garg Date: Mon, 16 Jun 2025 19:39:57 +0530 Subject: [PATCH 15/15] SearchResult res in video.clip method --- videodb/video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/videodb/video.py b/videodb/video.py index 0ec11ac..edb7a1e 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -595,7 +595,7 @@ def clip( "model_name": model_name, }, ) - return clip_data.get("stream_url") + return SearchResult(self._connection, **clip_data) def insert_video(self, video, timestamp: float) -> str: """Insert a video into another video