Simon Willison’s Weblog: llm-sort

Source URL: https://simonwillison.net/2025/Feb/11/llm-sort/
Source: Simon Willison’s Weblog
Title: llm-sort

Feedly Summary: llm-sort
Delightful LLM plugin by Evangelos Lamprou which adds the ability to perform “semantic search" – allowing you to sort the contents of a file based on using a prompt against an LLM to determine sort order.
Best illustrated by these examples from the README:
llm sort –query "Which names is more suitable for a pet monkey?" names.txt

cat titles.txt | llm sort –query "Which book should I read to cook better?"

It works using this pairwise prompt, which is executed multiple times using Python’s sorted(documents, key=functools.cmp_to_key(compare_callback)) mechanism:
Given the query:
{query}

Compare the following two lines:

Line A:
{docA}

Line B:
{docB}

Which line is more relevant to the query? Please answer with "Line A" or "Line B".

Via lobste.rs
Tags: llm, plugins, generative-ai, ai, llms, python

AI Summary and Description: Yes

Summary: The text describes a plugin named “llm-sort,” which enables semantic search capabilities using LLMs (large language models) to sort file contents based on user-defined prompts. This advancement has implications for AI and LLM security, especially as semantic search becomes integral to data processing in various applications.

Detailed Description:
The “llm-sort” plugin by Evangelos Lamprou introduces an innovative method to enhance data handling by utilizing semantic search through LLMs. This tool allows users to query and sort file contents dynamically based on relevance to specified prompts, which can be particularly useful in various AI and data analysis applications.

Key Features and Insights:
– **Semantic Search**: The plugin leverages LLM capabilities to enable a deeper understanding of content relevance, moving beyond traditional keyword matching.
– **Sorting Mechanism**: It employs Python’s sorting functionality in conjunction with a custom compare function that assesses two lines of text based on a user-defined query.
– **Practical Examples**:
– A user can determine appropriate names for a pet monkey by querying a names file.
– Users can decide which book to read from a list based on cooking improvement queries.

– **Execution Method**: The plugin operates by comparing pairs of lines through multiple iterations, enhancing the sorting process’s accuracy based on semantic context, which is pivotal for practical AI and LLM applications.

– **Tags and Application**: The mention of tags like LLM, generative AI, and Python indicates broad usability for developers and data scientists interested in incorporating advanced sorting mechanisms in AI-powered applications.

This development reflects the growing importance of contextual understanding in artificial intelligence and emergent data processing landscapes, urging professionals in security and compliance to consider the implications of such technologies concerning data privacy and automated processing capabilities.