Mongodb Natural language Conversation

Hi All

I am working on Natural language generation for Mongodb query using OpenAI, Python Langchain.

I am able to generate the query accurately using OpenAI gpt4 model and I have passed this to Mongodb Aggregate pipeline.

I am getting the results accurately in Mongodb Json format. I am passing this to LLM again to convert this json to Natural Language text to the user.

This call is taking time to convert json to Natural Language though it’s accurate. It’s response time is around 8-10 seconds and overall process is around 12 seconds.

How can I bring down this 2-3 seconds?

I have tried semantic caching too but it’s only helpful if the user asked the similar question before but I want fast response for all the questions.

Please suggest if we can use any other technique like Function Calling agents etc.

Thanks in Advance

You might try something like pyjq to convert the json to plain text before sending to the API

1 Like

Thanks…I will try this approach.

Hi Saikrishna, I am also trying to do the same but I am stuck with queries involving datetime. I am using python (pymongo) to run queries. Everytime ChatGPT 4o gives datetime format which is not working. How did you solve that issue, can you share your sample prompt how you solved it?

Hi Vishnu,

I have also faced the same issue.

I have implemented following steps to fix this issue.

  1. Make sure the date is stored in appropriate date format in Mongodb
  2. Give one or two sample examples atleast in prompt/context related to date time queries with your expected query.
  3. Once the aggregate pipeline query is generated from the LLM, modify the pipeline by parsing the date times using python date functions.

Hope it helps.