An AI application stores document embeddings in Azure Database for PostgreSQL Flexible Server. Which SQL query finds the 5 most similar documents to a given embedding using cosine distance?
- A SELECT * FROM docs ORDER BY embedding <-> $1 LIMIT 5
- B SELECT * FROM docs ORDER BY embedding <=> $1 LIMIT 5 (correct answer)
- C SELECT * FROM docs ORDER BY embedding <#> $1 LIMIT 5
- D SELECT TOP 5 * FROM docs WHERE cosine(embedding, $1) > 0.8
Shortcut: The <=> operator in pgvector computes cosine distance. <-> is Euclidean (L2), <#> is inner product (negative dot product). ORDER BY ASC finds nearest neighbours.