AnnDB
Search…
⌃K

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
dataset = client.vector('<DATASET_NAME>')
Python client accepts either a list of floats or a NumPy array as vectors.
dataset = client.vector("<DATASET_NAME>")
Ruby client accepts a list of floats as vectors.
Python
Ruby
result = dataset.search([0.4506, -0.6739, -0.2360, -1.3630, ...], 10)
for item in result:
print(item.id, item.metadata)
result = dataset.search([0.4506, -0.6739, -0.2360, -1.3630, ...], 10)
result.each do |item|
puts item.id, item.metadata
end

Insert

Python
Ruby
# Single item
id = dataset.insert(
[0.4506, -0.6739, -0.2360, -1.3630, ...],
metadata={'key': 'value'}
)
# 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)
id = dataset.insert(
[0.4506, -0.6739, -0.2360, -1.3630, ...],
metadata={ "key": "value" }
)
result = dataset.insert_batch([
{
vector: [0.4506, -0.6739, -0.2360, -1.3630, ...],
metadata: { "key": "value" }
},
...
])
result.each { |r|
puts r[:id], r[:error]
}

Update

Python
Ruby
# Single item
id = dataset.update(
id,
[0.4506, -0.6739, -0.2360, -1.3630, ...],
metadata={'key': 'value'}
)
# 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)
id = dataset.update(
id,
[0.4506, -0.6739, -0.2360, -1.3630, ...],
metadata={ "key": "value" }
)
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]
}

Delete

Python
Ruby
# Single item
dataset.delete(id)
# Batch
result = dataset.delete_batch([id, ...])
for r in result:
print(r.id, r.error)
dataset.delete(id)
result = dataset.delete_batch([id, ...])
result.each { |r|
puts r[:id], r[:error]
}