Query Agent Get Started
Build A Weaviate Query Agent - The E-Commerce Assistant
In this recipe, we will be building a simple e-commerce assistant agent with the Weaviate Query Agent. This agent will have access to a number of Weaviate collections, and will be capable of answering complex queries about brands and clothing items, accessing information from each collection.
๐ You can read and learn more about this service in our "Introducing the Weaviate Query Agent" blog.
To get started, we've prepared a few open datasets, available on Hugging Face. The first step will be walking through how to populate your Weaviate Cloud collections.
- E-commerce: A dataset that lists clothing items, prices, brands, reviews etc.
- Brands: A dataset that lists clothing brands and information about them such as their parent brand, child brands, average customer rating etc.
Additionally, we also have access to some other unrelated datasets which you can use to add more capabilities and variety to other agents later on in the recipe:
- Financial Contracts: A dataset of financial contracts between indivicuals and/or companies, as well as information on the type of contract and who has authored them.
- Weather: Daily weather information including temperature, wind speed, percipitation, pressure etc.
1. Setting Up Weaviate & Importing Data
To use the Weaviate Query Agent, first, create a Weaviate Cloud account๐
- Create Serverless Weaviate Cloud account and setup a free Sandbox
- Go to 'Embedding' and enable it, by default, this will make it so that we use
Snowflake/snowflake-arctic-embed-l-v2.0as the embedding model - Take note of the
WEAVIATE_URLandWEAVIATE_API_KEYto connect to your cluster below
Info: We recommend using Weaviate Embeddings so you do not have to provide any extra keys for external embedding providers.
Prepare the Collections
In the following code blocks, we are pulling our demo datasets from Hugging Face and writing them to new collections in our Weaviate Serverless cluster.
โ๏ธ The
QueryAgentuses the descriptions of collections and properties to decide which ones to use when solving queries, and to access more information about properties. You can experiment with changing these descriptions, providing more detail, and more. It's good practice to provide property descriptions too. For example, below we make sure that theQueryAgentknows that prices are all in USD, which is information that would otherwise be unavailable.
2. Set Up the Query Agent
When setting up the query agent, we have to provide it a few things:
- The
client - The
collectionwhich we want the agent to have access to. - (Optionally) A
system_promptthat describes how our agent should behave - (Optionally) Timeout - which for now defaults to 60s.
Let's start with a simple agent. Here, we're creating an agent that has access to our Brands & Ecommerce datasets.
3. Run the Query Agent
When we run the agent, it will first make a few decisions, depending on the query:
- The agent will decide which collection or collections to look up an answer in.
- The agent will also decide whether to perform a regular search query, what filters to use, whether to do an aggregation query, or all of them together!
- It will then provide a reponse within
QueryAgentResponse. We will use theprint_query_agent_responsefunction for a nice display of various information provided in the response object.
Ask a Question
Let's start with a simple question: "I like the vintage clothes, can you list me some options that are less than $200?"
We can then also inspect how the agent responded, what kind of searches it performed on which collections, whether it has identified if the final answer is missing information or not, as well as the final answer ๐
Ask a follow up question
The agent can also be provided with additional context. For example, we can provide the previous response as context and get a new_response
Now let's try a question that sholud require an aggregation. Let's see which brand lists the most shoes.
Search over multiple collections
In some cases, we need to combine the results of searches across multiple collections. From the result above, we can see that "Loom & Aura" lists the most shoes.
Let's imagine a scenario where the user would now want to find out more about this company, as well as the items that they sell.
Changing the System Prompt
In some cases, you may want to define a custom system_prompt for your agent. This can help you provide the agent with some default instructions as to how to behave. For example, let's create an agent that will always answer the query in the users language.
Let's also create a QueryAgent that has access to two more collections, Financial_contracts and Weather. Next, you can try out more queries yourself!
For example, this time lets ask something that is about weather!
Les vitesses de vent minimales, maximales et moyennes sont respectivement de 8,40 km/h, 94,88 km/h et 49,37 km/h. Ces donnรฉes offrent une vue d'ensemble des conditions de vent typiques mesurรฉes dans une pรฉriode ou un lieu donnรฉ.
Try More Questions
- For example Let's try to find out more about the brans "Eko & Stitch"
Yes, Eko & Stitch has a branch in the UK. The brand is part of the broader company Nova Nest, which serves as Eko & Stitch's parent brand. Eko & Stitch itself operates in the UK and has its child brands, Eko & Stitch Active and Eko & Stitch Kids, also within the UK.
- Our
multi_lingual_agentalso has access to a collection called "Financial_contracts". Let's try to find out some more information about this dataser.
The query seeks to identify the types of contracts listed and determine the most common type. Among the types of contracts provided in the results, the following were identified: employment contracts, sales agreements, invoice contracts, service agreements, and lease agreements. The most common type of contract found in the search results is the employment contract. However, when considering data from both search and aggregation results, the aggregation reveals that the invoice contract is the most common, followed by service agreements and lease agreements. While employment contracts appear frequently in the search results, they rank fourth in the aggregation data in terms of overall occurrences.