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

# Searching Through Videos

> Learn how to use natural language to search for specific moments within a single video or across a library of videos.

## Overview

VidNavigator's semantic search allows you to find relevant information within your video content without having to manually sift through hours of footage. You can search across a library of online videos (like YouTube) or your own uploaded files.

## Prerequisites

* A valid VidNavigator API key.
* The Python or JavaScript SDK installed in your project.

## Billing

Semantic search consumes `search_request` usage. 1 credit covers 10 searches across YouTube or your own uploaded files.

## Searching Videos

### Searching Across Online Videos

This example demonstrates how to search for videos on YouTube that match a specific query.

#### Using the Python SDK

```python theme={null}
from vidnavigator import VidNavigatorClient, VidNavigatorError

client = VidNavigatorClient()

try:
    results = client.search_videos(
        query="What are the best practices for React development?",
        focus="relevance",
        start_year=2022
    )
    print(f"Found {len(results.data['results'])} relevant videos:")
    for video in results.data['results']:
        print(f"- {video['title']} ({video['url']})")
except VidNavigatorError as e:
    print(f"An error occurred: {e.message}")

```

#### Using the JavaScript SDK

```javascript theme={null}
const { VidNavigatorClient, VidNavigatorError } = require('vidnavigator');

const client = new VidNavigatorClient({
  apiKey: process.env.VIDNAVIGATOR_API_KEY,
});

async function searchOnlineVideos() {
  try {
    const results = await client.searchVideos({
      query: "What are the best practices for React development?",
      focus: "relevance",
      start_year: 2022
    });
    console.log(`Found ${results.data.results.length} relevant videos:`);
    results.data.results.forEach(video => {
      console.log(`- ${video.title} (${video.url})`);
    });
  } catch (error) {
    if (error instanceof VidNavigatorError) {
      console.error(`An error occurred: ${error.message}`);
    } else {
      console.error("An unexpected error occurred:", error);
    }
  }
}

searchOnlineVideos();
```

### Searching Your Uploaded Files

This example demonstrates how to search across the files you have uploaded to VidNavigator. Each result includes `namespace_ids` and `namespaces` showing which namespaces the file belongs to.

#### Using the Python SDK

```python theme={null}
from vidnavigator import VidNavigatorClient, VidNavigatorError

client = VidNavigatorClient()

try:
    results = client.search_files(query="Customer feedback on pricing")
    print(f"Found {len(results.data['results'])} relevant files:")
    for file_result in results.data['results']:
        ns_names = [ns['name'] for ns in file_result.get('namespaces', [])]
        print(f"- {file_result['name']} (File ID: {file_result['id']}, Namespaces: {ns_names})")
except VidNavigatorError as e:
    print(f"An error occurred: {e.message}")
```

#### Using the JavaScript SDK

```javascript theme={null}
const { VidNavigatorClient, VidNavigatorError } = require('vidnavigator');

const client = new VidNavigatorClient({
  apiKey: process.env.VIDNAVIGATOR_API_KEY,
});

async function searchUploadedFiles() {
  try {
    const results = await client.searchFiles({ query: "Customer feedback on pricing" });
    console.log(`Found ${results.results.length} relevant files:`);
    results.results.forEach(fileResult => {
      const nsNames = (fileResult.namespaces || []).map(ns => ns.name);
      console.log(`- ${fileResult.name} (File ID: ${fileResult.id}, Namespaces: ${nsNames})`);
    });
  } catch (error) {
    if (error instanceof VidNavigatorError) {
      console.error(`An error occurred: ${error.message}`);
    } else {
      console.error("An unexpected error occurred:", error);
    }
  }
}

searchUploadedFiles();
```

### Filtering File Search by Namespace

You can restrict search to specific namespaces by passing `namespace_ids`. If omitted, all namespaces are searched.

```python theme={null}
results = client.search_files(
    query="Customer feedback on pricing",
    namespace_ids=["64a1b2c3d4e5f6789abc0002"]
)
```

```javascript theme={null}
const results = await client.searchFiles({
  query: "Customer feedback on pricing",
  namespace_ids: ["64a1b2c3d4e5f6789abc0002"]
});
```
