Skip to main content

Advent Calendar Day 12: How AI Agents Handle Numeric Height Queries

· 8 min read
Norah Sakal

Advent Calendar Day 12: How AI Agents Handle Numeric Height Queries

This December, I'm highlighting how naive chatbots fail at numeric filters and how AI agents get it right.

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, new color requirements and multi-color requests.

Yesterday, we saw how AI agents handle formal requirements. Today, we focus on a request for lower heel heights.

When a customer says, "I need women's heels with a heel height less than 2 inches", a naive chatbot might find only one option or ignore some products.

An AI agent, however, uses numeric filtering to find all matches.

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

SoleMates is our fictional online shoe store

Today's Challenge: Heels Under 2 Inches

Scenario

Customer: "I need women's heels with a heel height less than 2 inches":

A customer initiates a chat with SoleMates

A customer initiates a chat with SoleMates and asks about heels with a heel height less than 2 inches

Naive Chatbot Response

The naive chatbot just treats the query as text. It might find one heel that fits, but it doesn't systematically filter by heel height.

It misses other suitable options:

The naive chatbot tries to pull heels less than 2 inches high

The naive chatbot tries to pull heels less than 2 inches high and finds one

It finds one pair but fails to show other low-heel options.

Naive Chatbot: "Here is one option:"

The naive chatbot found only one heel less than 2 inches high

The naive chatbot found only one heel less than 2 inches high

Why Did the Naive Chatbot Fail?

  • No numeric filtering on heel height
  • Returns incomplete or limited results
  • Does not leverage metadata to find all matches

Limitations Highlighted

  • No proper numeric filters
  • Partial results instead of a full list
  • Lack of systematic approach to attribute-based queries

AI Agent Solution

The AI agent applies numeric filters.

It parses "less than 2 inches" and filters heels accordingly:

  • gender=women
  • heels_height<2

The AI agent finds all four matching options instead of just one.

AI Agent: "Here are some women's heels under 2 inches:

AI agent listing four matching options instead of just one

AI agent listing four matching options instead of just one

How Did the AI Agent Succeed?

  • Understands numeric constraints
  • Applies filters to return all matches, not just the first found
  • Leverages metadata (heel_height) to ensure accurate results

Key Takeaways

Naive Chatbot Limitation

  • Finds limited or no results due to lack of numeric filtering

AI Agent Advantages

  • Accurately applies numeric filters
  • Shows all products that fit the user's request
  • Enhances the shopping experience with full, accurate results

Conclusion

When users specify numeric requirements like heel height less than 2 inches, naive chatbots fail to apply proper filters and return only partial matches.

AI agents, on the other hand, use metadata and numeric reasoning to find all suitable options, improving both accuracy and user satisfaction.

About This Series

In this series, we show the shortcomings of naive chatbots and how AI agents excel by using metadata, numeric filters, and advanced reasoning.

Follow along as we continue to explore scenarios where AI agents outperform naive chatbots.

Learn to Build Your Own AI Agent Chatbot

I'm preparing a course to teach you how to build and deploy your own AI agent chatbot. Sign up here!


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:

  1. Vector database metadata filtering
  2. Vector database query

1. Vector database metadata filtering tool

def create_metadata_filter(filter_string):
# For "women's heels with a heel height less than 2 inches"
# Returns:
# [{"key": "gender", "value": "women", "operator": "=="},
# {"key": "heels_height", "value": 2, "operator": "<"}]
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
AWS Titan Multimodal Embeddings in Action

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 need women's heels with a heel height less than 2 inches")

Agent workflow:

Agent:

  1. Calls create_metadata_filter("women's heels heel height less than 2 inches")
  2. Gets filter:
[
{"key": "gender", "value": "women", "operator": "=="},
{"key": "heels_height", "value": 2, "operator": "<"}
]
  1. Applies the returned filters and calls the database query
  2. Lists women's heels under 2 inches:

AI agent listing women&#39;s heels under 2 inches

AI agent listing women's heels under 2 inches

Here's the full agent output:

Added user message to memory: I need women's heels with a heel height less than 2 inches
=== Calling Function ===
Calling function: create_metadata_filter with args: {"filter_string": "women's heels heel height less than 2 inches"}
=== Function Output ===
[{"key": "gender", "value": "women", "operator": "=="}, {"key": "heels_height", "value": 2, "operator": "<"}]
=== Calling Function ===
Calling function: search_footwear_database with args: {"query_str": "heels", "filters_json": [{"key": "gender", "value": "women", "operator": "=="}, {"key": "heels_height", "value": 2, "operator": "<"}]}
=== Function Output ===
[{'color': 'black', 'text': 'Catwalk women corporate leather black heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 88, 'usage': 'formal', 'price': 155, 'heels_height': 1, 'similarity_score': 1.71523559}, {'color': 'brown', 'text': 'Catwalk women brown heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 77, 'usage': 'casual', 'price': 75, 'heels_height': 1, 'similarity_score': 1.71276808}, {'color': 'brown', 'text': 'Catwalk women bronze brown heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 78, 'usage': 'casual', 'price': 70, 'heels_height': 1, 'similarity_score': 1.68853617}, {'color': 'black', 'text': 'Catwalk women black wedges', 'gender': 'women', 'product_type': 'heels', 'product_id': 15, 'usage': 'casual', 'price': 105, 'heels_height': 1, 'similarity_score': 1.19232333}]
=== LLM Response ===
Here are some women's heels with a heel height of less than 2 inches:

1. **Catwalk Women Corporate Leather Black Heels**
- Color: Black
- Usage: Formal
- Heel Height: 1 inch
- Price: $155

2. **Catwalk Women Brown Heels**
- Color: Brown
- Usage: Casual
- Heel Height: 1 inch
- Price: $75

3. **Catwalk Women Bronze Brown Heels**
- Color: Brown
- Usage: Casual
- Heel Height: 1 inch
- Price: $70

4. **Catwalk Women Black Wedges**
- Color: Black
- Usage: Casual
- Heel Height: 1 inch
- Price: $105

If you need more information or have any other preferences, feel free to let me know!

Additional Resources

For a deeper dive into this example, check out my GitHub repository where I break down the code and methodology used by the AI agent in today's scenario.

Upcoming AI agent course

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?

Many online shoppers look for products with specific numeric attributes, such as heels under a certain height.

AI agents understand numeric filters and use metadata to deliver accurate and comprehensive results.

By providing all low-heel options, AI agents improve the user experience, increase trust, and streamline online shopping journeys.