From the course: Vector Databases in Practice: Deep Dive
Solution: Vector database queries
(upbeat music) - [Instructor] Okay, let's now take a look at how I implemented those tasks for the challenge. The first task was to perform a hybrid search on the review collection. So first of all, I got the review collection like so, so that we can interact with it. Now I know that I need to run two queries, so let's set up a for loop here with two alpha values. And then of course, I'm running a search. So I'll look in the query submodule for the hybrid method, where my query here is "fun for the whole family". We'll provide the alpha value from our loop, and then limit the number of results to three. I would also like to get the score metadata, so I'll specify the return metadata parameter and use the metadata query class. And then with the response, I've written a note here to display what the alpha value used was, so I can see it in the results before iterating through the objects and displaying the review body, as well as the metadata score. And when we run this code, I get these results for each alpha value. And what did you think of these results? For me, the second set of results with the alpha of 0.9 matches the intent of my search better, which was looking for movies that talked about enjoyment for the family, as in family friendly movies. Now the alpha value of 0.9 very much lends the result towards vector search. So it makes sense that these results align with my general meaning of the phrase of the query, but of course, your mileage may vary depending on your search string, intent, and the data set itself. Now let's have a look at the second task, which was to construct a RAG query. We were instructed to use the movies collection. So we'll use the movies object, and it's a RAG query, so we'll use the generate submodule. And it's a vector search, which means we need to use the near text method with action adventure as our query string. Now our task was to generate a tagline for each movie. As a result, the RAG task to use here is single prompt, that will act on each individual object and send the object to the language model with the query. So here's the prompt that I came up with. Here, I ask the language model to suggest a tagline for this film based on the title and the description. And I break down what the title is, as well as what the description is. Just a reminder, again, this is a template for Weaviate to replace these variables within the braces, within the collection property. This is not a Python F-String. The results can then be printed out with something like this. We'll have a heading for generated results. And for each object, we'll print out the movie information, including the title and the description that the language model would've based its answer on before showing the generated tagline. And of course, we should remember to close our client connection as well. And now if we run this code, we're seeing the results for the earlier query as well. And then we get our generated taglines. So for the movie The Enchanted, we get a tagline like "Embark on enchanting journey" . And for Galactic Odyssey, we get the tagline, "Embark on an ultimate space adventure to save Earth". How does yours go? New results will probably differ from mine for a couple of reasons. One is that large language models are not deterministic. And of course, your prompt probably differed from mine in some way or another, but hopefully you arrived at a similar query syntax as they did, and your language model was to generate a tagline that made sense in the context of the given information. So that's your first challenge down. If you can write queries like these, you are well in your way to making great use of vector databases. But you might also be wondering, "Hey, how did the data get there in the first place?" Well, that's exactly what we're going to explore and work on in the next chapter.
Contents
-
-
-
A high-level view of vector databases3m 15s
-
What you can do with vector databases3m 3s
-
Get set up for the course3m 42s
-
Keyword filtering and keyword searches4m 25s
-
Vector searches3m 7s
-
Searching with filters3m 37s
-
Hybrid searches3m 33s
-
Retrieval augmented generation3m 30s
-
Challenge: Vector database queries1m 33s
-
Solution: Vector database queries4m 28s
-
-
-
-
-