Vector search queries often use top-k similarity, assuming the highest-scoring results are true and can serve as factual validation. These scores represent distances between vectors (e.g., <=> for cosine distance in PostgreSQL with pgvector), so they should be used to retrieve relevant results—not as a final ranking of truth. Azure AI on HorizonDB can call an AI model to generate embeddings for comparison and provides more specific functions, such as is_true() or extract(), for structured responses.
In this blog post, I'll use the three of them on a small dataset, a table of countries, with the same goal: tell me if the country is an island or not.
I generate embeddings from the country name, assuming that the model has enough knowledge about countries:
For a real application, you may provide more information, such as a geographical description of the country, rather than using the AI model as a source of knowledge, but I keep this simple for the demo.
country | distance | is_true_result | extracted
----------------------------------+--------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Iceland | 0.5288325821583937 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Dominica | 0.583984959074203 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Marshall Islands | 0.5923968276529713 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Seychelles | 0.5933297352264011 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Solomon Islands | 0.5992036897764201 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Barbados | 0.6026798894629409 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Bahamas | 0.6037901963467236 | f | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Mauritius | 0.6124306023780004 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Jamaica | 0.6180866747206792 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Ireland | 0.6208333769699201 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": "United Kingdom (Northern Ireland)"}
Grenada | 0.6314871259473416 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Palau | 0.6331963890581136 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Kiribati | 0.6340927146328686 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Cyprus | 0.6354914993816243 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Maldives | 0.6368475975326672 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Malta | 0.6370369487669678 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
New Zealand | 0.6520422783711599 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Antigua and Barbuda | 0.6560949198973425 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Fiji | 0.6563765953128096 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Saint Lucia | 0.6565374364556272 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Saint Kitts and Nevis | 0.6569025217334334 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Madagascar | 0.6579842393491677 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Nauru | 0.6588623575239401 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Belize | 0.6617206536439253 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Mexico, Guatemala"}
Cape Verde | 0.6656987305382893 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Guyana | 0.6690943980832992 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Brazil, Suriname, Venezuela"}
Micronesia | 0.6694775662174064 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Sri Lanka | 0.6755248175409809 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Andorra | 0.6756446018762446 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "France, Spain"}
Israel | 0.6763307658990072 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Lebanon, Syria, Jordan, Egypt, Palestine"}
Cuba | 0.6780035821480603 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Tonga | 0.6854439801282708 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Vanuatu | 0.6898198008050471 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Dominican Republic | 0.6930591990187845 | f | {"land": true, "water": true, "island": true, "continent": false, "neighbours": "Haiti"}
Saint Vincent and the Grenadines | 0.6936146574365081 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Singapore | 0.6939824470932374 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Samoa | 0.6942054226212125 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Haiti | 0.6970099016123408 | f | {"land": true, "water": false, "island": true, "continent": false, "neighbours": "Dominican Republic"}
Indonesia | 0.6982757826983539 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Malaysia, Papua New Guinea, Timor-Leste"}
Bahrain | 0.7010005561641666 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Comoros | 0.7067622419634335 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Estonia | 0.7085149756741925 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Latvia, Russia"}
Liechtenstein | 0.7098232671398083 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Austria, Switzerland"}
Tuvalu | 0.7100676352558253 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Brunei | 0.710790435672632 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Malaysia"}
San Marino | 0.7188084142495059 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Italy"}
Vatican City | 0.7195959897300721 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Italy"}
Suriname | 0.7227729682040444 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Brazil, Guyana, French Guiana"}
Sao Tome and Principe | 0.7228708359839435 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Guinea-Bissau | 0.7250435443354935 | f | {"land": true, "water": true, "island": false, "continent": false, "neighbours": "Senegal, Guinea"}
Trinidad and Tobago | 0.7255906511994212 | t | {"land": true, "water": true, "island": true, "continent": false, "neighbours": ""}
Greece | 0.7294355944328467 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Albania, North Macedonia, Bulgaria, Turkey"}
Qatar | 0.7311974837740045 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Saudi Arabia"}
Bhutan | 0.7334687504057431 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "India, China"}
Monaco | 0.7340602079110607 | f | {"land": true, "water": true, "island": false, "continent": false, "neighbours": "France"}
Iraq | 0.734913671407935 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Turkey, Iran, Kuwait, Saudi Arabia, Jordan, Syria"}
Kuwait | 0.7369097472864523 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Iraq, Saudi Arabia"}
Denmark | 0.7379886532695916 | f | {"land": true, "water": true, "island": false, "continent": false, "neighbours": "Germany"}
Slovenia | 0.7381978525807786 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Italy, Austria, Hungary, Croatia"}
Liberia | 0.7392671571539429 | f | {"land": true, "water": true, "island": false, "continent": false, "neighbours": "Sierra Leone, Guinea, Côte d'Ivoire"}
Djibouti | 0.740412556074715 | f | {"land": true, "water": true, "island": false, "continent": false, "neighbours": "Eritrea, Ethiopia, Somalia"}
Oman | 0.7413224461946565 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Saudi Arabia, United Arab Emirates, Yemen"}
Somalia | 0.7449227200702471 | f | {"land": true, "water": false, "island": false, "continent": false, "neighbours": "Djibouti, Ethiopia, Kenya"}
Gabon | 0.7456118851623608 | f | ... (truncated)
by Franck Pachot