# Semantic Search

Semantic textual similarity datasets allow you to go beyond traditional keyword and exact-match search. AnnDB uses state-of-the-art machine learning models to provide accurate and semantically relevant results. Using the API, you can build a dataset of sentences which you can then query using natural language queries to find semantically similar information.

### Create a Dataset

Create a dataset with `Semantic Similarity` type which tells AnnDB to encode your sentences to vectors.

![](https://1514770980-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MBjJDID-9E2lsbXx9on%2F-MYkDSbL82qX_ZankqcO%2F-MYkDYR7niLJMu3Vjchb%2Fimage.png?alt=media\&token=4b85967a-2c14-4703-9370-6d9b5e14d07c)

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('my sentence', metadata={'key': 'value'})
```

```python
# Batch
result = dataset.insert_batch([
    anndb_api.TextItem(None, 'my sentence', {'key': 'value'}),
    ...
])

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

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.insert("my sentence", metadata={ "key": "value" })
```

```ruby
result = dataset.insert_batch([
    {
        text: "my sentence",
        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, 'my updated sentence', metadata={'key': 'value'})
```

```python
# Batch
result = dataset.update_batch([
    anndb_api.TextItem(id, 'my updated sentence', {'key': 'value'}),
    ...
])

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

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.update(id, "my updated sentence", metadata={ "key": "value" })
```

```ruby
result = dataset.update_batch([
    {
        id: id,
        text: "my updated sentence",
        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 %}
