Using the Conversational Interface in inmydata

Modified on Tue, 24 Jun at 6:50 PM

Using the Conversational Interface in inmydata

The Conversational Interface allows agents to interpret and respond to natural language questions using data available in your inmydata environment. This is ideal when you want to give an agent freeform access to data, without having to build specific queries or filter logic manually.


What Makes the Conversational Interface Different?

Unlike structured queries, which are fast and deterministic, the conversational interface goes through several steps to understand, access, and interpret your question. These may include:

  • Interpreting the intent of the question

  • Determining which datasets are needed

  • Querying the appropriate data

  • Analysing the data

  • Formulating a natural language response

Because of this multi-step process, responses typically take up to a minute, depending on the complexity of the question and how busy the underlying AI services are.


Live Updates via ai_question_update Callback

To improve transparency and feedback during this process, the API emits an ai_question_update callback that provides live feedback on what the agent is doing. You might see messages such as:

  • "I'm thinking about what data I need to answer the question."

  • "I now have the data with 70 rows. I'll analyse the data to determine the top 10 stores based on sales in the last 6 weeks."

This makes the experience more interactive, especially when embedding in UIs or chat interfaces.


Example: Asking a Freeform Question

The following Python example shows how to use the ConversationalDataDriver to ask a question and receive updates as it is being processed.


import os

from dotenv import load_dotenv
from inmydata.ConversationalData import ConversationalDataDriver
import asyncio

load_dotenv()

# get_answer is an async function, so we need to run it in an event loop
async def main():
    driver = ConversationalDataDriver(os.environ['INMYDATA_TENANT'])

    # Register a callback to handle AI question updates
    def on_ai_question_update(caller, message):  
        print(message)

    # Register the callback handler for AI question updates
    driver.on("ai_question_update", on_ai_question_update) 

    question = "Give me the top 10 stores this year"
    answer = await driver.get_answer(question)
    
    print("=================================================================")
    print(f"The answer was: {answer.answer}")
    print(f"The subject used to generate the answer was: {answer.subject}")


asyncio.run(main())

Notes

  • The question can be phrased naturally (e.g. “What are our best performing stores this month?”).

  • The callback function (on_ai_question_update) is optional, but highly recommended for tracking progress.

  • Answer.answer contains the final human-readable response from the agent.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article