How do I use an LLM to find the top k records that best match a question?

Ask the LLM to score each record on its own and sort by the score, instead of comparing records in pairs. In our semantic top-k post, Quail's AI.SCORE turns the TRUE and FALSE logits of Qwen3-4B into a score from 0 to 1 for each record. On three tasks, this matched or beat pairwise comparison with Quickselect on Precision@25 (for example, 96% vs. 80% on contracts) and ran 8.2x faster per task (geometric mean).

Sources: Supporting LLM-Powered Top-k Queries in Quail

Guide: What Is AI-SQL?

More questions on this topic

All questions about using AI for data and knowledge work