UChat Official

Introduction

In today's training session, we explore a powerful technique to leverage OpenAI embeddings for dynamic user routing within chatbots.

This method allows you to send buttons or question blocks to specific users based on their input, enabling a more personalized and efficient conversational experience.

The process, while seemingly complex at first, becomes straightforward with a clear step-by-step approach. By the end of this guide, you'll understand how to set up embedding-based intent recognition, map responses to dedicated flows, and use buttons and question blocks to enhance user engagement.

Step-by-Step Breakdown of the Embedding-Based Routing

1. Setting Up the Initial Question Block

  • Purpose: Capture user input and map responses to custom fields.

  • Implementation:

    • Create a question block (optional if default reply suffices).

    • Inside, ask a simple question (e.g., "How can I contact you?").

    • Map the response to a custom field (e.g., user_response).

Note: The question block is essential if you want to simulate specific conversation flows or gather user input explicitly.

2. Integrating OpenAI Embedding Action

  • Navigate to: Action block → OpenAI embedding match.

  • Select: Integration → OpenAI → Embedding match.

  • Input: Use Last Text Input (or the custom field) to ensure the embedding reflects the user's latest message.

  • Configure:

    • Set a minimum score threshold (e.g., 0.8) to ensure high-confidence matches.

    • Provide a test value (e.g., "How to contact you?") to verify embedding accuracy.

Parameter

Description

Example

Search Field

Text to embed and match

last_text_input or custom field

Score Threshold

Confidence level for match

0.8

Test Value

Sample input for testing

"How to contact you?"

  • Outcome: The system returns an embedding with a score and matched text (e.g., "Contact details").

3. Mapping Embedding Results to Custom Fields

  • Map:

    • Matched TextResponse Text.

    • ScoreConfidence Score.

    • Heading (if used) → Intent or Category (e.g., Reservations, Contact).

Tip: Use custom fields like openai_score, embed_heading, and embed_text for clarity.

4. Conditional Logic Based on Embedding Confidence

  • Check the score:

    • Use an OR condition block.

    • Set condition: Score ≥ 0.8.

  • Verify the intent:

    • Use a Condition block.

    • Example: If embed_heading equals "Reservations".

Condition

Description

Example

Score ≥ 0.8

High-confidence match

openai_score >= 0.8

Heading equals "Reservations"

Specific intent

embed_heading == "Reservations"

  • Routing:

    • If conditions are met, send user to dedicated flow (e.g., reservation flow).

    • Else, fallback to default reply or generic message.

5. Creating Dedicated Flows for Specific Intents

  • Example: Reservation flow.

  • Setup:

    • Create a subflow (e.g., reservations_subflow).

    • Use embed text to prompt for details (date, time, guests).

    • Add buttons for quick responses or options.

Tip: Use embed text with buttons to streamline user input and guide them through the process.

6. Using Buttons and Question Blocks for User Engagement

  • Buttons: Offer predefined options (e.g., "Create Reservation", "Contact Support").

  • Question Blocks: Capture specific details (e.g., number of guests, date).

  • Flow Integration:

    • When a user clicks a button, route to the relevant subflow.

    • Inside subflows, use embed text and buttons to facilitate data collection.

Example Buttons

Purpose

Result

"Make a Reservation"

Trigger reservation flow

User directed to reservation subflow

"Contact Support"

Provide contact info

User receives contact details

7. Dynamic Response Mapping and Multi-Intent Handling

  • Multiple headings: Map each to its own conditional branch.

  • Example:

    • Heading: "Contact", route to contact info.

    • Heading: "Workshops", route to workshop info.

    • Heading: "Reservations", route to reservation flow.

  • Implementation:

    • Use condition groups to check multiple headings.

    • Map each heading to a specific flow or response.

Heading

Action

Example Response

Contact

Send contact details

"You can reach us at..."

Workshops

Provide workshop info

"Upcoming workshops are..."

Reservations

Initiate reservation flow

"Let's make a reservation..."

  • Default fallback: If no match is found, send a generic reply or use GPT-generated response.

8. Generating and Updating Embeddings

  • Create embeddings for each intent or category.

  • Upload or regenerate embeddings as your content updates.

  • Ensure case sensitivity is consistent to improve matching accuracy.

Tip: Regularly update embeddings to reflect new content or intents.

9. Benefits of Embedding-Based Routing

  • High accuracy in intent recognition, even with free text.

  • Flexible routing to dedicated flows based on user input.

  • Enhanced user experience with buttons and quick replies.

  • Reduced manual intent tagging—embeddings handle the heavy lifting.

  • Scalable for complex chatbot architectures.

Summary

In summary, OpenAI embeddings provide a robust mechanism to detect user intent and route conversations dynamically within your chatbot. By mapping embedding results to custom fields, setting confidence thresholds, and using conditional logic, you can create dedicated flows for different user needs—be it reservations, contact inquiries, or workshop information. Incorporating buttons and question blocks further enhances engagement, making interactions more natural and efficient.

This approach streamlines your chatbot's ability to understand free-text inputs and respond appropriately, all while maintaining a seamless user experience. As you implement this setup, remember to regularly update your embeddings and fine-tune thresholds for optimal performance.