Menu

Similarity Is Not Truth: Comparing vector distance, is_true(), and extract() in Azure AI for PostgreSQL
📰

Similarity Is Not Truth: Comparing vector distance, is_true(), and extract() in Azure AI for PostgreSQL

DEV Community: postgres·Franck Pachot·about 14 hours ago
#23nxNvPG
#devtopostgresql#devto#dev#false#true
Reading 0:00
15s threshold

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 .

DROP TABLE IF EXISTS countries ; CREATE TABLE countries ( country text primary key , region text ) ;

\ copy countries ( country , region ) FROM PROGRAM 'curl -L "https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv"' WITH ( FORMAT csv , HEADER true ) ;

SELECT * FROM countries WHERE region = 'OCEANIA' LIMIT 10 ;

Enter fullscreen mode

Exit…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.