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

# Search for moments

> Find exact moments across videos in the index

> [!NOTE]
>
> Try out the search function on a sample index in the [Search playground](https://app.askvideos.com/playground)

## Setup

**1. Create an API key**

First create an API key using the instructions in [API keys](https://docs.askvideos.com/installation/api-key)

**2. Install the client**

Next install the AskVideos client if using [Python](https://docs.askvideos.com/installation/python). Or consult the [REST API](https://docs.askvideos.com/api-reference/introduction.md) reference for other frameworks.

**3. Create an index**

Next, [create an index](https://docs.askvideos.com/quickstart/add-videos.md#creating-an-index). For this tutorial, we will use an index with the name 'test\_index'

**4. Add some videos**

Next, [add some videos](https://docs.askvideos.com/quickstart/add-videos.md) to the index. Now we are ready to get started with searching!

## Search using text

```python theme={null}
index_name = 'test_index'
query = 'dogs running around'
top_k = 30 # Number of results to return.

results = client.search_videos(
            index_name,
            query,
            top_k=top_k)
```

The returned results look like this:

```json theme={null}
{
    "6689571-hd_1280_720_25fps": [
        {
            "score": 0.09953739908006456,
            "start_seconds": 0,
            "end_seconds": 18
        }
    ],
    "855386-hd_1280_720_25fps": [
        {
            "score": 0.10187351703643799,
            "start_seconds": 0,
            "end_seconds": 2
        },
        {
            "score": 0.08336693048477173,
            "start_seconds": 2,
            "end_seconds": 6
        },
        {
            "score": 0.10038037598133087,
            "start_seconds": 6,
            "end_seconds": 10
        }
    ]
    ...
}
```

Where the results are a dictionary of lists where the key of the dictionary is the `video_id` and the list items are segments of the video that are in the `top_k` results.

Each segment contains a score representing how close of a match the segment is to the query and the start and end timestamps within the video.

## Search using an image

```python theme={null}
index_name = 'test_index'
image_path = '/path/to/image.jpg'
top_k = 30 # Number of results to return.

results = client.search_by_image(
            image_path,
            query,
            top_k=top_k)
```

## Search using a video

```python theme={null}
index_name = 'test_index'
video_path = '/path/to/video.mp4'
top_k = 30 # Number of results to return.

results = client.search_by_video(
            index_name,
            video_path,
            top_k=top_k)
```

## Next steps

In addition to finding moments, AskVideos can also answer questions based on the videos in the index.

> [card] [Generate answers](https://docs.askvideos.com/quickstart/answer.md)
>
> Ask questions and generate answers from video content.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.