This December, I'm showing how naive chatbots fail and how AI agents make shopping easier.
We've seen naive chatbots fail at clarifying questions, context shifts, numerical requirements, multiple requests in one query, price filters, style suggestions, unavailable colors, negations and new color requirements.
Today, we focus on multi-color requirements.
When a customer wants "women's black shoes with blue details" a naive chatbot can't handle the combined color request. It either returns no results or random items. An AI agent, on the other hand, understands the request fully and finds the exact product that matches both colors.
Source Code
For a deeper dive into this example, check out my GitHub repository for a detailed, step-by-step implementation in Jupyter Notebooks, breaking down the code and methodology used by the AI agent in today's scenario.
Introducing SoleMates
SoleMates is our fictional online shoe store we'll use to illustrate these concepts:
SoleMates is our fictional online shoe store
Today's Challenge: Handling Multi-Color Queries
Scenario
A customer asks:
Customer: "I'm looking for women's black shoes with blue details":
A customer initiates a chat with SoleMates and asks about men's casual shoes, but not in black
Naive Chatbot Response
The naive chatbot tries to vectorize the entire request but has no logic to combine color the two color attributes:
The naive chatbot pulls items from the database that mention women's black shoe with blue details
It returns heels from various black shoes but none with blue details:
The naive chatbot ends up failing to find black women's shoes with blue details
Because it can't filter by color details, it either returns:
- No items at all
- Random women's black or blue shoes, but not the correct combination
The simple chatbot ends up saying that there are no black women's shoes with blue details:
The naive chatbot ends replying: "there are no women's black shoes with blue details available"
This is incorrect, as we do have a pair that meets the criteria.
Why Did the Naive Chatbot Fail?
- It can't handle multiple attributes like "black" + "blue details"
- No metadata-based filtering to combine color requirements
- Treats the entire query as plain text without structured reasoning
Limitations Highlighted
- No multi-attribute filtering
- Limited understanding of color details
- Inaccurate results for complex requests
AI Agent Solution
The AI agent uses metadata filters. When the request is "women's black shoes with blue details", it:
- Identifies gender: women
- Identifies primary color: black
- Identifies secondary color detail: blue
- It creates a filter:
- gender=women
- color=black
- color_details=[blue] and searches the database
- The agent finds the exact product:
The AI agent sees the request and decides to apply a color filter
How Did the AI Agent Succeed?
- It breaks down the request into structured metadata
- Uses multiple filters to ensure both black and blue details are matched
- Delivers one perfect match instead of random or no results
Key Takeaways
Naive Chatbot Limitation
- Can't handle complex color requests and returns irrelevant or no results
AI Agent Advantages
- Understands multiple attributes within one request
- Applies metadata filters for precise product matching
- Gives customers the exact product they want
Conclusion
Multi-color queries are common when shoppers look for that perfect item.
Naive chatbots fail at combining attributes, resulting in poor recommendations.
AI agents leverage metadata to handle multiple colors, ensuring customers find what they are looking for.
About This Series
In this series, we highlight the shortcomings of naive chatbots and show how AI agents provide better results by using metadata and advanced reasoning.
Follow along to see how AI agents tackle more complex challenges every day this December.
Coming Up: Handling Special Occasions
In tomorrow's issue, we'll explore how AI Agents Handle Handle Special Occasions
Sign up here for my upcoming course to learn how to build your own AI agent chatbot
Behind the Scenes: Code Snippets
Here's a simplified illustration of how the AI agent processes the query.
We're giving the agent access to two tools it can use freely:
- Vector database metadata filtering
- Vector database query
1. Vector database metadata filtering tool
def create_metadata_filter(filter_string):
# For "women's black shoes with blue details"
# Extract gender=women, color=black, color_details=[blue]
filters = parse_filters(filter_string)
return filters
2. Vector database query
def search_footwear_database(query_str, filters_json):
embedded_query = embed_query_aws_titan(query_str)
results = vector_db.search(embedded_query, filters=filters_json)
return results
I use AWS Titan, a multimodal embedding model that converts both product texts and images into vectors, integrated as the function embed_query_aws_titan
into the AI agent tool search_footwear_database
.
This means the AI agent can process a query like "red heels" and match it to not only product descriptions but also actual images of red heels in the database.
By combining text and image data, the model helps the AI agent provide more relevant and visually aligned recommendations based on the customer's input.
Agent workflow
Construct agent worker with access to the two tools and initiate the agent:
from llama_index.core.agent import AgentRunner, FunctionCallingAgentWorker
agent_worker = FunctionCallingAgentWorker.from_tools(
[
create_metadata_filters_tool,
query_vector_database_tool,
])
agent = AgentRunner(
agent_worker,
)
Initiate conversation with agent:
agent.chat("I'm looking for women's black shoes with blue details")
Agent workflow:
- Customer: "I'm looking for women's black shoes with blue details"
- Agent calls
create_metadata_filter("women's black shoes with blue details")
- Gets filter:
[
{"key": "gender", "value": "women", "operator": "=="},
{"key": "color", "value": "black", "operator": "=="},
{"key": "color_details", "value": ["blue"], "operator": "in"}
]
- Returns a black shoes with blue details:
The AI agent applies filters and finds the exact product
Here's the full agent output:
Added user message to memory: I'm looking for women's black shoes with blue details
=== Calling Function ===
Calling function: create_metadata_filter with args: {"filter_string": "women's black shoes with blue details"}
=== Function Output ===
[{"key": "gender", "value": "women", "operator": "=="}, {"key": "color", "value": "black", "operator": "=="}, {"key": "color_details", "value": ["blue"], "operator": "in"}]
=== Calling Function ===
Calling function: search_footwear_database with args: {"query_str": "shoes", "filters_json": [{"key": "gender", "value": "women", "operator": "=="}, {"key": "color", "value": "black", "operator": "=="}, {"key": "color_details", "value": ["blue"], "operator": "in"}]}
=== Function Output ===
[{'color': 'black', 'color_details': ['blue'], 'text': 'Nike women sweet ac black shoe', 'gender': 'women', 'product_type': 'sports shoes', 'product_id': 14, 'usage': 'sports', 'price': 135, 'similarity_score': 1.19315314}]
=== LLM Response ===
I found a pair of women's black shoes with blue details for you:
- **Product**: Nike Women Sweet AC Black Shoe
- **Type**: Sports Shoes
- **Price**: $135
If you're interested in this option or need more choices, feel free to let me know!
Additional Resources
Check out my GitHub repository for more code samples and instructions on building AI agents that handle multiple attributes.
Sign up here for my upcoming course to learn how to build your own AI agent chatbot
Why use AI agents instead of simple chatbots in e-commerce?
Online shoppers often search for products with multiple attributes, such as "women's black shoes with blue details." AI agents leverage advanced search techniques and metadata filtering to handle these complex requests. By understanding multiple product attributes, AI agents give users accurate recommendations, improving their shopping experience and boosting user satisfaction.