AnnDB
Search…
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.
In order to manage data in your dataset, create a corresponding dataset instance using the client.
Python
Ruby
1
dataset = client.text('<DATASET_NAME>')
Copied!
1
dataset = client.text("<DATASET_NAME>")
Copied!
Python
Ruby
1
result = dataset.search('query', 10)
2
3
for item in result:
4
print(item.id, item.metadata)
Copied!
1
result = dataset.search("query", 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('my sentence', metadata={'key': 'value'})
Copied!
1
# Batch
2
result = dataset.insert_batch([
3
anndb_api.TextItem(None, 'my sentence', {'key': 'value'}),
4
...
5
])
6
7
for r in result:
8
print(r.id, r.error)
Copied!
1
id = dataset.insert("my sentence", metadata={ "key": "value" })
Copied!
1
result = dataset.insert_batch([
2
{
3
text: "my sentence",
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(id, 'my updated sentence', metadata={'key': 'value'})
Copied!
1
# Batch
2
result = dataset.update_batch([
3
anndb_api.TextItem(id, 'my updated sentence', {'key': 'value'}),
4
...
5
])
6
7
for r in result:
8
print(r.id, r.error)
Copied!
1
id = dataset.update(id, "my updated sentence", metadata={ "key": "value" })
Copied!
1
result = dataset.update_batch([
2
{
3
id: id,
4
text: "my updated sentence",
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