Quick Example
import videodb
conn = videodb.connect()
coll = conn.get_collection()
# Search entire collection
results = coll.search("product announcement")
for shot in results.get_shots():
print(f"Video: {shot.video_id}")
print(f"Time: {shot.start}s - {shot.end}s")
print(f"Content: {shot.text}")
import { connect } from 'videodb';
const conn = connect();
const coll = await conn.getCollection();
// Search entire collection
const results = await coll.search("product announcement");
for (const shot of results.shots) {
console.log(`Video: ${shot.videoId}`);
console.log(`Time: ${shot.start}s - ${shot.end}s`);
console.log(`Content: ${shot.text}`);
}
Collection vs Video Search
| Scope | Method | Use Case |
|---|---|---|
| Single video | video.search() | Find moments in a specific video |
| Entire library | coll.search() | Find content across all videos |
Search All Videos
Spoken Content
# Search spoken content across all videos
results = coll.search("discusses artificial intelligence")
# Results include video IDs
for shot in results.get_shots():
print(f"Found in video {shot.video_id} at {shot.start}s")
// Search spoken content across all videos
const results = await coll.search("discusses artificial intelligence");
// Results include video IDs
for (const shot of results.shots) {
console.log(`Found in video ${shot.videoId} at ${shot.start}s`);
}
Visual Content
from videodb import IndexType
# Search scene indexes across collection
results = coll.search(
query="person speaking at podium",
index_type=IndexType.scene
)
import { IndexTypeValues, SearchTypeValues } from 'videodb';
// Search scene indexes across collection
const results = await coll.search(
"person speaking at podium",
SearchTypeValues.semantic,
IndexTypeValues.scene
);
Metadata Filtering
Narrow search to specific categories using metadata filters.Index with Metadata
from videodb import SceneExtractionType
# Add metadata during indexing
video.index_scenes(
extraction_type=SceneExtractionType.time_based,
extraction_config={"time": 30},
prompt="Describe the scene",
metadata={"category": "news", "topic": "technology"}
)
// Add metadata during indexing
await video.indexScenes({
extractionType: 'time',
extractionConfig: { time: 30 },
prompt: "Describe the scene",
metadata: { category: "news", topic: "technology" }
});
Search with Filters
from videodb import IndexType
# Filter by metadata
results = coll.search(
query="product launch",
filter=[{"category": "news"}],
index_type=IndexType.scene
)
# Multiple filters (AND logic)
results = coll.search(
query="keynote speech",
filter=[
{"category": "conference"},
{"year": "2024"}
],
index_type=IndexType.scene
)
import { IndexTypeValues, SearchTypeValues } from 'videodb';
// Filter by metadata
const results = await coll.search(
"product launch",
SearchTypeValues.semantic,
IndexTypeValues.scene,
[{ category: "news" }]
);
// Multiple filters (AND logic)
const results = await coll.search(
"keynote speech",
SearchTypeValues.semantic,
IndexTypeValues.scene,
[
{ category: "conference" },
{ year: "2024" }
]
);
Metadata Guidelines
| Rule | Limit |
|---|---|
| Max key-value pairs | 5 |
| Max key length | 20 characters |
| Max value length | 20 characters |
| Value types | string or int |
Scene-Level Metadata
Tag individual scenes for fine-grained filtering.from videodb.scene import Scene
# Create scenes with metadata
scenes = [
Scene(
video_id=video.id,
start=0,
end=60,
description="Opening segment with logo",
metadata={"segment_type": "intro"}
),
Scene(
video_id=video.id,
start=60,
end=300,
description="Main presentation content",
metadata={"segment_type": "content"}
),
Scene(
video_id=video.id,
start=300,
end=360,
description="Q&A session",
metadata={"segment_type": "qa"}
)
]
# Index with scene-level metadata
video.index_scenes(scenes=scenes, name="segmented_index")
# Search only Q&A segments
results = video.search(
query="questions about pricing",
filter=[{"segment_type": "qa"}],
index_type=IndexType.scene
)
import { Scene } from 'videodb';
// Create scenes with metadata
const scenes = [
new Scene({
videoId: video.id,
start: 0,
end: 60,
description: "Opening segment with logo",
metadata: { segment_type: "intro" }
}),
new Scene({
videoId: video.id,
start: 60,
end: 300,
description: "Main presentation content",
metadata: { segment_type: "content" }
}),
new Scene({
videoId: video.id,
start: 300,
end: 360,
description: "Q&A session",
metadata: { segment_type: "qa" }
})
];
// Index with scene-level metadata
await video.indexScenes({ scenes, name: "segmented_index" });
// Search only Q&A segments
const results = await video.search(
"questions about pricing",
SearchTypeValues.semantic,
IndexTypeValues.scene,
[{ segment_type: "qa" }]
);
Use Cases
Media Archive
# Tag videos by topic
for video in news_videos:
video.index_scenes(
prompt="Describe the news segment",
metadata={"channel": "CNN", "category": "politics"}
)
# Search political news only
results = coll.search(
query="election coverage",
filter=[{"category": "politics"}],
index_type=IndexType.scene
)
Training Library
# Tag by skill level
beginner_videos.index_scenes(
prompt="Describe the tutorial content",
metadata={"level": "beginner", "topic": "python"}
)
# Find beginner Python content
results = coll.search(
query="how to define a function",
filter=[{"level": "beginner"}, {"topic": "python"}],
index_type=IndexType.scene
)
Surveillance
# Tag by camera location
camera_footage.index_scenes(
prompt="Identify people and vehicles",
metadata={"location": "entrance", "camera_id": "cam_01"}
)
# Search specific camera
results = coll.search(
query="person in red jacket",
filter=[{"location": "entrance"}],
index_type=IndexType.scene
)
Performance Considerations
Index Before Searching
Collection search only finds content that has been indexed:# Index all videos first
for video in coll.get_videos():
video.index_spoken_words()
video.index_scenes(prompt="Describe the scene")
# Now search across all
results = coll.search("quarterly results")
// Index all videos first
const videos = await coll.getVideos();
for (const video of videos) {
await video.indexSpokenWords();
await video.indexScenes({ prompt: "Describe the scene" });
}
// Now search across all
const results = await coll.search("quarterly results");
Use Metadata Filters
Filters reduce the search space and improve speed:# Fast: filtered search
results = coll.search(
query="product demo",
filter=[{"category": "marketing"}]
)
# Slower: unfiltered search across everything
results = coll.search("product demo")
Search Examples
Explore practical search implementations:Character Clips
Extract specific characters or people from video collections
Multimodal Search
Combine text, visual, and audio search for powerful results
Next Steps
Accuracy Tips
Improve search precision and recall
Latency and Cost
Optimize for speed and efficiency