> For the complete documentation index, see [llms.txt](https://docs.anndb.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anndb.com/datasets/vector.md).

# Vector

Vector datasets allow you to store your own vectors so that they can be efficiently queried later. The dimension of vectors has to match the dimension specified when creating the dataset.

### Create a Dataset

Create a dataset with `Vector` type which tells AnnDB to skip any pre-processing and embedding, and store the vectors as is. The distance metric and dimension **cannot** be changed later.

![](/files/-MYkEDcEhKXJmcFLpo7u)

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

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

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

Python client accepts either a list of floats or a NumPy array as vectors.
{% endtab %}

{% tab title="Ruby" %}

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

Ruby client accepts a list of floats as vectors.
{% endtab %}
{% endtabs %}

### Search

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

```python
result = dataset.search([0.4506, -0.6739, -0.2360, -1.3630, ...], 10)

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

{% endtab %}

{% tab title="Ruby" %}

```ruby
result = dataset.search([0.4506, -0.6739, -0.2360, -1.3630, ...], 10)

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

{% endtab %}
{% endtabs %}

### Insert

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

```python
# Single item
id = dataset.insert(
    [0.4506, -0.6739, -0.2360, -1.3630, ...],
    metadata={'key': 'value'}
)
```

```python
# Batch
result = dataset.insert_batch([
    anndb_api.VectorItem(
        None,
        [0.4506, -0.6739, -0.2360, -1.3630, ...],
        {'key': 'value'}
    ),
    ...
])

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

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.insert(
    [0.4506, -0.6739, -0.2360, -1.3630, ...],
    metadata={ "key": "value" }
)
```

```ruby
result = dataset.insert_batch([
    {
        vector: [0.4506, -0.6739, -0.2360, -1.3630, ...],
        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,
    [0.4506, -0.6739, -0.2360, -1.3630, ...],
    metadata={'key': 'value'}
)
```

```python
# Batch
result = dataset.update_batch([
    anndb_api.VectorItem(
        id,
        [0.4506, -0.6739, -0.2360, -1.3630, ...],
        {'key': 'value'}
    ),
    ...
])

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

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.update(
    id,
    [0.4506, -0.6739, -0.2360, -1.3630, ...],
    metadata={ "key": "value" }
)
```

```ruby
result = dataset.update_batch([
    {
        id: id,
        vector: [0.4506, -0.6739, -0.2360, -1.3630, ...],
        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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.anndb.com/datasets/vector.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
