Back to the video

Wagtail AI and Wagtail Vector Index

Transcript

By Dan BraghiÈ™. From Wagtail Space NL 2024. Published June 27, 2024.

Watch the video Markdown version 1,502 words · auto-generated · en

Summary

Dan Braghiș introduces two optional packages: Wagtail AI, which adds configurable LLM-powered tools to the Wagtail admin, and Wagtail Vector Index, which helps developers implement semantic search, recommendations, and natural-language interfaces. Wagtail AI supports multiple LLM providers through Simon Willison’s LLM package, configurable prompts, translation and correction workflows, and image alt-text generation, while Vector Index turns content into embeddings and supports pluggable backends such as NumPy, pgvector, Qdrant, and Weaviate. He explains the APIs for querying, searching, and finding similar objects, then highlights practical concerns including API costs, prompt injection, streaming requirements, asynchronous servers, and database connection pooling. The packages are being developed around real-world use cases, with Wagtail AI planned to gain broader editorial workflows and Vector Index moving toward a stable API and more providers.

Transcript

Automatically transcribed, so expect mistakes in names and technical terms. Filler words are removed.

0:00 Wagtail AI and Vector Index

There we go. All right. Hi everyone. Welcome. I'm here today to spread the world, the word about our new AI overlords. But on a serious note, I'm Dan, also known as Zero Lab. I work for Torchbox and you may have seen me in Slack or in GitHub issues. So what do I actually want to talk about? When we talk Blocktail AI, it's two packages, the Bogtail AI and Wogtail Vector Index. They were started by my cold colleague Tom Usher, who you know wanted to play and had a side project and we've since adapted that

adopted that and brought in a number of enhancements and iterations and we kind of looked at how might we use them in real world scenarios and yeah what would the be a sensible way to use them. So rather than jump in the LLM, you know, an AI craze, we wanted to just look at practical solutions. Also I want to note that these are all optional so they're they're not bundled into Wagtail, don't don't worry about that. So Wagtail AI, it's a package aimed at editors or anyone that has access to the Wagtail admin and it's intended to kind of enhance the

1:45 Wagtail AI

the experience and the wagtail interface. It uses the LLM package, so that's Simon Willison's Sim Simon Willison known in the Django world and it allows us to support multiple LLMs so OpenAI or Claude or even OLAMA It provides configurable prompts from the Wagtel admin and more recently it supports alt text generation. And that last bit is not new, so Martin put I think it's somewhere here, had a package that did this for some time using

Azure cognition and AWS and Google Vision but we wanted to bring that into a unified experience So quick demo. I'm I didn't want to risk it so I recorded a screencast. So this is me adding a new prompt saying well translate to Dutch There you also see two others that come with it. Here I have a page with some errors, so I I'm asking it to correct those and then translating that to Dutch. And it didn't stop. So it kind of does that. That uses OpenAI, but you can because

because of the LLM package you can also use a local LLM so you don't send your data anywhere. This other demo is just generating an alt text from an image. Currently it's supporting just the open I open AI vision API. But you can You can build your own prov provider so you can integrate with other services. The next one is Rocktail Vector Index And that is aimed more at developers to help them build

4:03 Wagtail Vector Index

richer sites or richer interactions. So What are some of the use cases for that? So one of them is natural language search, similarity search, or content recommendations. So first off, a note on vector indexes. So for those of you who don't know This whole thing is really so vector in the you may have heard embeddings, basically they're numerical representations of the of the of the content. Or well or of the input. So that might be text, images.

4:48 Vector Embeddings

So it tries to capture the semantics or the characteristics of the input in a numerical form. And then there are specialized databases that store these kind of these clusters of numbers and they use different algorithms to basically group similar things together so that the you do you can you can retrieve them more efficiently and then you know the further the away they are the less common they though those things are. So the way we went with it, and it's still kind of we're coming to

5:34 Index Architecture and Providers

to an API that would make sense for most people is that we went we sort of copied the Wagtail Search Index design where you have a mix in and then you define some field fields. It supports asynchronous operations, so we it started with the LLM package, but we've integrated the light LLM package to support that and that's useful if you want to do streaming responses and kind of chat like interfaces. And it comes with pluggable providers. So NumPy, PG vector, quadrant, and weve8. And these are basically either services or sort of specialized databases that

6:19 Query, Search, and Similarity

that know what to do with those numbers. And This is a kind of a quick example how you might implement it. So you have a mix-in, you add it to your page model And then you define which fields to be considered for that for the embedding, so transformed into these numerical representations. And then the vector index itself has these three public interfaces or things that it can do and that's query, search or similarity. So query will take the string,

convert that into an embedding, find similar content from your from your database or your vector index, then pass that to a an l LLM as context and then we'll it will give you a response. Search uses natural language processing to purely look what you have look up what you have in your index and then the similarity one you give it an object and it will try to find you know the closest I think five, but that's configurable. So the closest objects based on magic.

7:50 Practical Applications and LLM Considerations

And so like this is a like a practical application. So we built a sort of chat with the internet. So that's our Internet torch box. So you just ask questions, it will find the relevant documents and then it uses an LLM to just compile the data. So a few considerations when using well any LLM really. So cost if you're using some service like OpenAI or Cloud, or you know, Google's G Gemini and so on. There's some cost associated with using the API and you know it might be small, but if you

especially if you open that to the public, it will it will ramp up. And if you do, so then you probably want to consider some kind of proxying service so it doesn't cost you an arm and a leg. Prompt injection, it's it's always, you know, that's the big thing, especially with the LLMs and people trying to find creative ways to you know for the to let the lm kind of hallucinate or kind of spew or reveal information it's not supposed to do so you kind of want to be careful And then if you want to do streaming interfaces, you definitely need on a synchronous server. You want connection pooling and that's coming to Django 5.

1. So basically you don't want to be making lots of requests and kind of saturating your database. Of course you could use other you know if you're not using it in a Django and Wagtail context that may not be such a problem So quickly about the roadmap. So our plan is to further enhance Wagtail AI, so the user-facing or editorial-facing experience, maybe look at multiple responses. A more seamless editorial process where perhaps it looks at the whole page as at the whole page rather than you know one single field And I put there insert your use case here

10:08 Roadmap

because we'd like to hear you know real user needs and try to see how we can do that holistically And for Wactal vector index, it's it's usable right now, so we have we we're we're we're we're using it in well you'd say production, but it's internal. So we're moving towards a stable release, so a stable API. We want to add more out-of-the-box providers so you can use it with you name it, and then kind of look at the j generally like the performance and maybe considerations for things like Pg vector. Yeah, and those are the

The URLs have a play, let us know what you think.