Try out the answer function on a sample index in the Answer playground

Setup

1

Create an API key

First create an API key using the instructions in API keys

2

Install the client

Next install the AskVideos client if using Python. Or consult the REST API reference for other frameworks.

3

Create an index

Next, create an index. For this tutorial, we will use an index with the name ‘test_index’

4

Add some videos

Next, add some videos to the index. Now we are ready to get started with getting answers!

Answer a question

index_name = 'test_index'
query = 'What dog breeds are mentioned?'

results = client.answer(
            index_name,
            query)

Answer modes

Specific videos

Instead of using all the videos in the index, you can also specify the video_ids variable to limit the videos used in synthesizing the answer.

video_ids = ['video_id1', 'video_id2', 'video_id3']

results = client.answer(
            index_name,
            query,
            video_ids=video_ids)

Retrieval Augmented Generation (RAG)

AskVideos also supports RAG to synthesize answers from the video.

Using embeddings to find the relevant parts of the video before generating tokens helps to reduce cost and provide more accurate answers. In addition, if the text in the index exceeds the input token limit, RAG can help overcome this limitation by selecting only the most relevant parts for the context.

In order to specify RAG mode, simply update the mode variable as follows.

results = client.answer(
            index_name,
            query,
            mode='rag')

If you need to limit the videos to perform RAG over, you can also specify the video_ids variable as follows.

video_ids = ['video_id1', 'video_id2', 'video_id3']

results = client.answer(
            index_name,
            query,
            mode='rag',
            video_ids=video_ids)

System prompt

The system prompt is customizable and can unlock powerful capabilities in the answer engine. Here are some examples of useful system prompts.

In order to utilize a custom system prompt with the query, do the following:

system_prompt = '''
Your custom system prompt
'''

results = client.answer(
            index_name,
            query,
            system_prompt=system_prompt)

Next steps

In addition to answering questions, the AskVideos API can also find specific moments in the videos.