> ## Documentation Index
> Fetch the complete documentation index at: https://docs.videodb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Collection Search

> Search across your entire video library with a single query

Search across all videos in a collection with a single query. Apply metadata filters to narrow results.

## Quick Example

<CodeGroup>
  ```python Python theme={null}
  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}")
  ```

  ```javascript Node.js theme={null}
  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}`);
  }
  ```
</CodeGroup>

***

## 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

<CodeGroup>
  ```python Python theme={null}
  # 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")
  ```

  ```javascript Node.js theme={null}
  // 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`);
  }
  ```
</CodeGroup>

### Visual Content

<CodeGroup>
  ```python Python theme={null}
  from videodb import IndexType

  # Search scene indexes across collection
  results = coll.search(
      query="person speaking at podium",
      index_type=IndexType.scene
  )
  ```

  ```javascript Node.js theme={null}
  import { IndexTypeValues, SearchTypeValues } from 'videodb';

  // Search scene indexes across collection
  const results = await coll.search(
      "person speaking at podium",
      SearchTypeValues.semantic,
      IndexTypeValues.scene
  );
  ```
</CodeGroup>

***

## Metadata Filtering

Narrow search to specific categories using metadata filters.

### Index with Metadata

<CodeGroup>
  ```python Python theme={null}
  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"}
  )
  ```

  ```javascript Node.js theme={null}
  // Add metadata during indexing
  await video.indexScenes({
      extractionType: 'time',
      extractionConfig: { time: 30 },
      prompt: "Describe the scene",
      metadata: { category: "news", topic: "technology" }
  });
  ```
</CodeGroup>

### Search with Filters

<CodeGroup>
  ```python Python theme={null}
  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
  )
  ```

  ```javascript Node.js theme={null}
  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" }
      ]
  );
  ```
</CodeGroup>

### 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.

<CodeGroup>
  ```python Python theme={null}
  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
  )
  ```

  ```javascript Node.js theme={null}
  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" }]
  );
  ```
</CodeGroup>

***

## Use Cases

### Media Archive

```python theme={null}
# 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

```python theme={null}
# 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

```python theme={null}
# 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:

<CodeGroup>
  ```python Python theme={null}
  # 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")
  ```

  ```javascript Node.js theme={null}
  // 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");
  ```
</CodeGroup>

### Use Metadata Filters

Filters reduce the search space and improve speed:

```python theme={null}
# 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:

<CardGroup cols={2}>
  <Card title="Character Clips" href="/examples-and-tutorials/video-rag/character-clips" icon="user">
    Extract specific characters or people from video collections
  </Card>

  <Card title="Multimodal Search" href="/examples-and-tutorials/video-rag/multimodal-search" icon="brain">
    Combine text, visual, and audio search for powerful results
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Accuracy Tips" href="/pages/understand/quality-and-evaluation/accuracy-tips" icon="target">
    Improve search precision and recall
  </Card>

  <Card title="Latency and Cost" href="/pages/understand/quality-and-evaluation/latency-and-cost" icon="gauge">
    Optimize for speed and efficiency
  </Card>
</CardGroup>
