# Question Answering

Question answering datasets provide an out-of-the-box solution for a machine learning powered search engine. AnnDB uses state-of-the-art machine learning models to provide highly relevant search results. Using the API, you can build a dataset of facts that you can later query using natural language queries.

### Create a Dataset

Create a dataset with `Question Answering` type which tells AnnDB to encode your facts and queries to vectors.

![](/files/-MYkDtqLyiHJZ4buhnc5)

In order to manage data in your dataset, create a corresponding dataset instance using the client.

{% tabs %}
{% tab title="Python" %}

```python
dataset = client.text('<DATASET_NAME>')
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
dataset = client.text("<DATASET_NAME>")
```

{% endtab %}
{% endtabs %}

### Search

{% tabs %}
{% tab title="Python" %}

```python
result = dataset.search('query', 10)

for item in result:
    print(item.id, item.metadata)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
result = dataset.search("query", 10)

result.each do |item|
    puts item.id, item.metadata
end
```

{% endtab %}
{% endtabs %}

### Insert

{% tabs %}
{% tab title="Python" %}

```python
# Single item
id = dataset.insert(
    'London has 8.9 million inhabitants.',
    metadata={'key': 'value'}
)
```

```python
# Batch
result = dataset.insert_batch([
    anndb_api.TextItem(
        None,
        'London has 8.9 million inhabitants.',
        {'key': 'value'}
    ),
    ...
])

for r in result:
    print(r.id, r.error)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.insert(
    "London has 8.9 million inhabitants.",
    metadata={ "key": "value" }
)
```

```ruby
result = dataset.insert_batch([
    {
        text: "London has 8.9 million inhabitants.",
        metadata: { "key": "value" }
    },
    ...
])

result.each { |r|
    puts r[:id], r[:error]
}
```

{% endtab %}
{% endtabs %}

### Update

{% tabs %}
{% tab title="Python" %}

```python
# Single item
id = dataset.update(
    id,
    'London has 9 million inhabitants.',
    metadata={'key': 'value'}
)
```

```python
# Batch
result = dataset.update_batch([
    anndb_api.TextItem(
        id,
        'London has 9 million inhabitants.',
        {'key': 'value'}
    ),
    ...
])

for r in result:
    print(r.id, r.error)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.update(
    id,
    "London has 9 million inhabitants.",
    metadata={ "key": "value" }
)
```

```ruby
result = dataset.update_batch([
    {
        id: id,
        text: "London has 9 million inhabitants.",
        metadata: { "key": "value" }
    },
    ...
])

result.each { |r|
    puts r[:id], r[:error]
}
```

{% endtab %}
{% endtabs %}

### Delete

{% tabs %}
{% tab title="Python" %}

```python
# Single item
dataset.delete(id)
```

```python
# Batch
result = dataset.delete_batch([id, ...])

for r in result:
    print(r.id, r.error)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
dataset.delete(id)
```

```ruby
result = dataset.delete_batch([id, ...])

result.each { |r|
    puts r[:id], r[:error]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anndb.com/datasets/question-answering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
