video2agent 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ """Video2Agent: video search and understanding for AI agents."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
video2agent/bench.py ADDED
@@ -0,0 +1,53 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ import statistics
5
+ import time
6
+ from typing import Any
7
+
8
+ from .config import Config
9
+ from .pipeline import evidence, overview, search
10
+ from .util import json_dumps
11
+
12
+
13
+ def _tokens(value: Any) -> int:
14
+ return max(1, len(json_dumps(value, indent=None)) // 4)
15
+
16
+
17
+ def run_bench(cfg: Config, video_id: str, queries: list[str], *, image_budget: int = 2) -> dict[str, Any]:
18
+ t0 = time.perf_counter()
19
+ ov = overview(cfg, video_id)
20
+ overview_ms = round((time.perf_counter() - t0) * 1000, 1)
21
+ rows = []
22
+ latencies = []
23
+ total_tokens = _tokens(ov)
24
+ for q in queries:
25
+ t = time.perf_counter()
26
+ result = search(cfg, q, video_id=video_id, limit=5)
27
+ ms = round((time.perf_counter() - t) * 1000, 1)
28
+ latencies.append(ms)
29
+ total_tokens += _tokens(result)
30
+ first = (result.get("results") or [None])[0]
31
+ ev = None
32
+ if first:
33
+ t = time.perf_counter()
34
+ ev = evidence(cfg, video_id=video_id, at_ms=first["start_ms"], image_budget=image_budget)
35
+ ev_ms = round((time.perf_counter() - t) * 1000, 1)
36
+ total_tokens += _tokens(ev)
37
+ else:
38
+ ev_ms = None
39
+ rows.append({"query": q, "search_ms": ms, "results": len(result.get("results") or []),
40
+ "evidence_ms": ev_ms, "evidence_images": len((ev or {}).get("images") or [])})
41
+ ordered = sorted(latencies)
42
+ p50 = statistics.median(ordered) if ordered else 0.0
43
+ p95 = ordered[min(len(ordered) - 1, max(0, math.ceil(len(ordered) * 0.95) - 1))] if ordered else 0.0
44
+ return {
45
+ "ok": True,
46
+ "video_id": video_id,
47
+ "title": ov.get("title"),
48
+ "queries": rows,
49
+ "latency_ms": {"overview": overview_ms, "search_p50": p50, "search_p95": p95},
50
+ "estimated_tokens": total_tokens,
51
+ "counts": ov.get("counts"),
52
+ "metrics": ov.get("metrics"),
53
+ }