Introducing Intents

Zep's Intent Extractor identifies the intent of a message, persisting this to message metadata. πŸ’‘ With intent data, developers can build richer, more personalized agent interactions. πŸ”₯

Introducing Intents
Photo by Baehaki Hariri / Unsplash

In Natural Language Processing (NLP), extracting meaning from the chaos of human communication can seem daunting. Today, we are excited to introduce an important feature β€” "Intent extraction" that provides more profound value for real-time understanding.

Understanding the user's Intent is the cornerstone of designing meaningful and personalized interactions in any conversational AI system. Extracting Intent goes beyond merely recognizing words or phrases β€” it's about comprehending what users mean in a given context. Personalization of Large Language Model (LLM) applications requires understanding Intent across the conversational continuum.

Our newly minted feature: Intent Extraction, is a valuable tool for businesses leveraging AI-powered customer interactions.

What is Intent Extraction?

At its core, Intent Extraction is an NLP task that involves identifying the user's goal or purpose from their input β€” what they intend to do. For instance, a user might say, "Play some upbeat music." The intent here is not just about 'playing music' but specifying the type of music β€” 'upbeat'.

Using Intents

Zep automatically extracts Intents on every message by default, you can change that by toggling it on and off by editing config.yaml:

...
extractors:
  summarizer:
    enabled: true
  entities:
    enabled: true
  intent:
    enabled: true
  embeddings:
    enabled: true
    dimensions: 1536
    model: "AdaEmbeddingV2"
...

By default, all conversations will include a 'system' metadata with 'intent' set for each message that is stored in Zep.

Intent drives personalization

Here is an example of how 'intent' combined with customer preferences can help drive a personalized engagement with the user in an e-commerce setting:

Human: I'm looking for a new skincare product.

ZepMemory:
{
    "uuid": "6026b3b7-3755-4d00-89d8-243ecfc45931",
    "created_at": "2023-06-21T02:19:45.577522Z",
    "role": "human",
    "content": "I'm looking for a new skincare product.",
    "metadata": {
        "system": {
            "intent": "The subject is expressing a need or want for a new skincare product."
        }
        "customer_firstname": "Alice",
        "customer_id": "KDSJFJDSF",
        "member_since": "03-01-2009",
        "product_pref_tags": "eco-friendly, vegan"
    },
    "token_count": 11
}

AI: Of course, Alice. Based on your preference for eco-friendly and vegan products, I can recommend a few options. Are you looking for a specific type of skincare product like a cleanser, moisturizer, or serum?

ZepMemory:
{
    "uuid": "30eb918d-4b3a-42a9-a64b-c79e01f87ec4",
    "created_at": "2023-06-21T02:19:45.577522Z",
    "role": "ai",
    "content": "Of course, Alice. Based on your preference for eco-friendly and vegan products, I can recommend a few options. Are you looking for a specific type of skincare product like a cleanser, moisturizer, or serum?",
    "metadata": {
        "system": {
            "intent": "The subject is offering recommendations for eco-friendly and vegan skincare options and inquiring about the specific type of product the person is looking for."
        }
    },
    "token_count": 46
}

Human: I'm looking for a good face moisturizer.

ZepMemory:
{
    "uuid": "f8ec855b-fd59-4084-a3d1-2b81857d5dcd",
    "created_at": "2023-06-21T02:19:45.577522Z",
    "role": "human",
    "content": "I'm looking for a good face moisturizer.",
    "metadata": {
        "system": {
            "intent": "The subject is searching for a specific type of facial skincare product."
        }
    },
    "token_count": 12
}

AI: I recommend the 'Green Goddess' vegan moisturizer. It's a highly rated, eco-friendly product and is particularly effective for dry skin. Would you like to add this to your cart?

ZepMemory:
{
    "uuid": "4e3d0fe8-5242-4c9c-8891-34636af1e576",
    "created_at": "2023-06-21T02:19:45.577522Z",
    "role": "ai",
    "content": "I recommend the 'Green Goddess' vegan moisturizer. It's a highly rated, eco-friendly product and is particularly effective for dry skin. Would you like to add this to your cart?",
    "metadata": {
        "system": {
            "intent": "The subject is making a product recommendation and asking if the listener would like to add it to their cart."
        }
    },
    "token_count": 40
}

Human: Great, that should work!

ZepMemory:
{
            "uuid": "5ec6a546-eec9-4b9d-b03d-11b142600a0a",
            "created_at": "2023-06-21T02:19:45.577522Z",
            "role": "human",
            "content": "Great, that should work!",
            "metadata": {
                "system": {
                    "intent": "None."
                }
            },
            "token_count": 8
        }
    ]
}

Why is Intent Extraction Important?

As the usage of AI chatbots grows in various sectors, the necessity for these systems to understand and respond appropriately to user intentions has never been more crucial. Intent Extraction helps in:

  • Enhancing user experience: By understanding the user's Intent, AI systems can provide relevant and personalized responses, improving user satisfaction.
  • Streamlining interactions: It aids in simplifying conversations by identifying the user's goal early in the exchange.
  • Increasing efficiency: By recognizing the user's Intent accurately, AI systems can begin to fulfill actions on behalf of a user's request (like calling APIs, updating systems, etc.), boosting the overall efficiency of these systems.

Practical Application

Today's LLMs are extremely powerful regarding understanding, reasoning, and inference. So how do you leverage the power of Intents in your applications?

Let us take a look at how the example above may be really used in a real-life production setting:

Human intents that we captured in this conversation:
1: "The subject is expressing a need or want for a new skincare product."
2: "The subject is searching for a specific type of facial skincare product."

Now that we know the intent, we can analyze how customers have approached these conversations in the past and use that to model several possible ways of engaging with the customer in future engagements:

  1. Customers looking for skincare products in the past 7 days
  2. Customers searching for facial skincare in the past month
  3. Customers looking for specific types of products within the skincare category

So, if we wanted to cluster all customers looking for a skincare product in the last seven days, we can now create a customer segment that includes everyone whose Intent matches these criteria.

# Use Zep SDK
search_results = await client.asearch_memory(
    session_id=session_id,
    search_payload=MemorySearchPayload(
        metadata={
            "start_date": "2023-06-02",
        	"end_date": "2023-06-09",
            "where": {"jsonpath": "$[*]['metadata']['system']['intent'] == 'customers looking for skincare'"},
        },
    ),
)

# You can also use Langchain
search_results = retriever.get_relevant_documents(
      metadata={
          "start_date": "2023-06-02",
          "end_date": "2023-06-09",
          "where": {"jsonpath": "$[*]['metadata']['system']['intent'] == 'customers looking for skincare'"},
      },
  )

Further, you can continue this analysis to evaluate how many customers with an intent to buy a skincare moisturizer actually ended up buying it versus a different but related product (perhaps sunscreen). This could end up as refinement of the existing customer segment or perhaps additional customer segments.

Each of these customer segments can then be mapped into prompt journeys which can be then optimized for user personalization, brand loyalty, response consistency or other business outcomes.

from langchain.prompts import PromptTemplate, StringPromptTemplate
from langchain.chains import LLMChain
...
prompt = """you are a helpful shopping assistant. Use the User preferences and Recommendations to write back responses based on the following rules:
1. If the user has preference for {user_pref} then suggest {recommend_sku} products.
2. Make a helpful {prompt_journey_append} suggestion.

"""
prompt_journey.prompt = prompt
...

#
# an example of how a prompt_journey may be used
# prompt_journey may be implemented as a structure that 
# contains different prompts that can be used and chained together 
# for different customer segments
#
if customer_segment.tag == "ecofriendly":
  prompt_journey.type = customer_segment.type
  prompt_journey.append("eco-friendly face cream")
  prompt_journey.suggest_top(eco_sku)

elif customer_segment.tag == "newcustomer":
  prompt_journey.append("face cream with built in sun-protection?)
  prompt_journey.suggest_top(spf_facecream)

# Now you can use the chosen prompt
prompt = PromptTemplate.from_template(prompt_journey.prompt)
chain = LLMChain(llm=ChatOpenAI(), prompt=prompt)
chain.run(input=input)

A related and automated system might continually A-B test different prompt paths based on the learned intents and how you may want to position your products.

Now we can start to see the power of Intents in classifying how customers engage with products and build prompt journeys that provide deeper personalization in these engagements.

Agentic future

What makes Intent interesting is its potential in autonomous AI Agents. We are excited about combining deep personalization with workflows that may trigger APIs or call external systems based on actions identified in the conversation. Intent can also be used to debug steps, trim unnecessary Agent execution loops and optimize for rapid Agent execution.

Understanding Intent is core to human interpret-ability, accuracy, and repeatability in these systems. This is still an emerging space, and we see teams experimenting and innovating rapidly. We hope that this feature will help with a variety of use cases.

With the launch of Intent Extraction, we aim to make conversational AI more personal, meaningful, and efficient. Try it out today, and let us know what you think.

πŸ’‘

Zep Memory Store Quick Start Guide. Questions? Join our Discord πŸš€

Additional References

Visit Zep on GitHub!