Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions videodb/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def search(self, query: str, *args, **kwargs) -> Union[SearchResponse, SearchRes
"mode",
"return_fields",
"include_clip",
"session_id",
}
unsupported_params = {"index_name", "index_names", "index_id", "index_ids"}

Expand All @@ -506,6 +507,8 @@ def search(self, query: str, *args, **kwargs) -> Union[SearchResponse, SearchRes
has_new = any(k in kwargs and kwargs[k] is not None for k in new_params)
has_unsupported = any(k in kwargs and kwargs[k] is not None for k in unsupported_params)

if kwargs.get("deepsearch_config") is not None:
raise ValueError("deepsearch_config is internal and cannot be passed to search().")
if has_old and (has_new or has_unsupported):
raise ValueError(
"Cannot mix legacy search params with new search params. "
Expand Down
13 changes: 8 additions & 5 deletions videodb/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,18 @@ def __repr__(self) -> str:
class SearchResponse:
"""Envelope returned by high-level Search v2.

For ``response_type='shots'``, ``results`` is a :class:`SearchResult`.
For ``response_type='shots'`` or ``response_type='deepsearch'``, ``results`` is a :class:`SearchResult`.
For ``response_type='aggregate'``, ``results`` is the aggregate dict/list returned by the server.
"""

def __init__(self, _connection, **kwargs):
self._connection = _connection
self.response_type = kwargs.get("response_type")
self.session_id = kwargs.get("session_id")
self.waiting_for = kwargs.get("waiting_for") or "none"
self.clarification = kwargs.get("clarification")
raw_results = kwargs.get("results", [])
if self.response_type == "shots":
if self.response_type in {"shots", "deepsearch"}:
self.results = SearchResult(_connection, results=raw_results)
self.shots = self.results.shots
else:
Expand All @@ -203,21 +206,21 @@ def __repr__(self) -> str:
return f"SearchResponse(response_type={self.response_type}, results={self.results})"

def __iter__(self):
if self.response_type == "shots":
if self.response_type in {"shots", "deepsearch"}:
return iter(self.results)
if isinstance(self.results, list):
return iter(self.results)
return iter([self.results])

def __len__(self):
if self.response_type == "shots":
if self.response_type in {"shots", "deepsearch"}:
return len(self.results)
if isinstance(self.results, list):
return len(self.results)
return 1 if self.results is not None else 0

def __getitem__(self, index):
if self.response_type == "shots":
if self.response_type in {"shots", "deepsearch"}:
return self.results[index]
return self.results[index]

Expand Down
3 changes: 3 additions & 0 deletions videodb/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def search(self, query: str, *args, **kwargs) -> Union[SearchResponse, SearchRes
"mode",
"return_fields",
"include_clip",
"session_id",
}
unsupported_params = {"index_name", "index_names", "index_id", "index_ids"}

Expand All @@ -125,6 +126,8 @@ def search(self, query: str, *args, **kwargs) -> Union[SearchResponse, SearchRes
has_new = any(k in kwargs and kwargs[k] is not None for k in new_params)
has_unsupported = any(k in kwargs and kwargs[k] is not None for k in unsupported_params)

if kwargs.get("deepsearch_config") is not None:
raise ValueError("deepsearch_config is internal and cannot be passed to search().")
if has_old and (has_new or has_unsupported):
raise ValueError(
"Cannot mix legacy search params with new search params. "
Expand Down
Loading