AnnDB
Search…
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.
In order to manage data in your dataset, create a corresponding dataset instance using the client.
Python
Ruby
1
dataset = client.vector('<DATASET_NAME>')
Copied!
Python client accepts either a list of floats or a NumPy array as vectors.
1
dataset = client.vector("<DATASET_NAME>")
Copied!
Ruby client accepts a list of floats as vectors.
Python
Ruby
1
result = dataset.search([0.4506, -0.6739, -0.2360, -1.3630, ...], 10)
2
3
for item in result:
4
print(item.id, item.metadata)
Copied!
1
result = dataset.search([0.4506, -0.6739, -0.2360, -1.3630, ...], 10)
2
3
result.each do |item|
4
puts item.id, item.metadata
5
end
Copied!

Insert

Python
Ruby
1
# Single item
2
id = dataset.insert(
3
[0.4506, -0.6739, -0.2360, -1.3630, ...],
4
metadata={'key': 'value'}
5
)
Copied!
1
# Batch
2
result = dataset.insert_batch([
3
anndb_api.VectorItem(
4
None,
5
[0.4506, -0.6739, -0.2360, -1.3630, ...],
6
{'key': 'value'}
7
),
8
...
9
])
10
11
for r in result:
12
print(r.id, r.error)
Copied!
1
id = dataset.insert(
2
[0.4506, -0.6739, -0.2360, -1.3630, ...],
3
metadata={ "key": "value" }
4
)
Copied!
1
result = dataset.insert_batch([
2
{
3
vector: [0.4506, -0.6739, -0.2360, -1.3630, ...],
4
metadata: { "key": "value" }
5
},
6
...
7
])
8
9
result.each { |r|
10
puts r[:id], r[:error]
11
}
Copied!

Update

Python
Ruby
1
# Single item
2
id = dataset.update(
3
id,
4
[0.4506, -0.6739, -0.2360, -1.3630, ...],
5
metadata={'key': 'value'}
6
)
Copied!
1
# Batch
2
result = dataset.update_batch([
3
anndb_api.VectorItem(
4
id,
5
[0.4506, -0.6739, -0.2360, -1.3630, ...],
6
{'key': 'value'}
7
),
8
...
9
])
10
11
for r in result:
12
print(r.id, r.error)
Copied!
1
id = dataset.update(
2
id,
3
[0.4506, -0.6739, -0.2360, -1.3630, ...],
4
metadata={ "key": "value" }
5
)
Copied!
1
result = dataset.update_batch([
2
{
3
id: id,
4
vector: [0.4506, -0.6739, -0.2360, -1.3630, ...],
5
metadata: { "key": "value" }
6
},
7
...
8
])
9
10
result.each { |r|
11
puts r[:id], r[:error]
12
}
Copied!

Delete

Python
Ruby
1
# Single item
2
dataset.delete(id)
Copied!
1
# Batch
2
result = dataset.delete_batch([id, ...])
3
4
for r in result:
5
print(r.id, r.error)
Copied!
1
dataset.delete(id)
Copied!
1
result = dataset.delete_batch([id, ...])
2
3
result.each { |r|
4
puts r[:id], r[:error]
5
}
Copied!
Last modified 7mo ago