PyCon UK 2025

Type text, find pictures: an app using CLIP, PostgreSQL® and pgvector
2025-09-21 , Space 2

What would once have been magical is now becoming common place.

In this talk, I'll show how to write a Python app that takes a text snippet (like "cat" or "man jumping") and finds images that match.


The original LLMs (large language models) worked with text, making it possible to use a phrase to search for documents with a similar meaning. Later models addressed other media, for instance, allowing comparison of images. And now we have multi-modal models, like OpenAI's CLIP, which can work with images and text interchangably.

I'll give a quick introduction to vector search and CLIP, talk through setting up the necessary table in PostgreSQL®, walk through a script to calculate the embeddings of the chosen images, and store them in the database, and another script that takes a search text and uses pgvector to find matching images in the database.

I'll then show how you can use FastAPI and HTMX to quickly make a web app with a basic form. Merging the "find images" code into that then gives the final application.

All the code will also be available in a GitHub repository.


What level of experience do you expect from your audience for this session?:

Intermediate

After being a programmer for a good few years, I changed career in 2022 to become a Developer Educator at Aiven (https://aiven.io/tibs). My favourite programming language is Python, my favourite markup language is reStructuredText (although I'm fascinated by Typst), my favourite storage technologies are SQLite, PostgreSQL and Valkey, and I’m rather enthusiastic about Apache Kafka as a messaging system. Find out more about my past at https://www.tonyibbs.co.uk/