Natural language interface to regular search/query?

Posting here because it is related to AI

We are looking to build a simple application that uses natural language queries, like in Compass (e.g. “find me a home in San Jose with at least 3 bedrooms on a quiet street”)

We think Vector Search might be an overkill for this, so we’d like to simply translate the natural language query into a MongoDB query (or perhaps our pre-defined API wrapper on top of it)

The question is could you share any pointers/code examples on how to do this, perhaps how MongoDB Compass does this…

Hi @Dmitriy_Kruglyak , Thank you for your question. I can provide general guidance on how to go about doing this - You will want to use an LLM like OpenAI GPT-4 or Anthropic Claude and perform Prompt engineering where you will provide sample schema of your db and instruct the model to convert your natural language query to MQL. This will work reasonably well for basic queries and schemas.

To further improve the performance you can leverage RAG using Vector Search could be leverage to provide a few specific examples to the LLM on how to perform the task, but will require you to have a dataset of sample natural language prompts to MQL. (Same requirement of a labeled dataset for fine-tuning one of these models). You can progressively improve the accuracy but this will increase the effort required as well

Thanks, I understand these basics and really looking for any prompt/ code examples