#Multiple results db query. How to manage?

1 messages · Page 1 of 1 (latest)

frank flare
#

I'm building a API GPT bot that performs queries on a database. One of the tables is the clients table, which has "name" and "business_name" columns. The issue I'm facing is that names can partially overlap. For example, I could have "Martin Smith," "Martin Doe," and even "Martina White." If I ask for the budgets of client Martin, I shouldn't search with an "equals," but rather with a "LIKE," which could return all three.

My question is: What is the best way to handle these situations? Is there a standard approach for disambiguating such results, or should I simply handle it by checking when multiple results are returned? Additionally, should the bot ask for clarification before executing the query (doing a kind of pre-query) instead of running the query directly?

unborn lavaBOT
#

Hi @frank flare. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, there are a few strategies you can consider when handling multiple results from a database query in your GPT bot:

  1. Return the First Matching Result: If multiple questions or keywords are identified as relevant, you can return the first matching result that appears in the database. This approach is mentioned in the OpenAI forum post (https://community.openai.com/t/938053) about consistent responses from custom GPT. However, this might not be the best approach if there are multiple valid matches, as it could lead to inaccurate results.

  2. Ask for Clarification: If the user’s query contains ambiguous words, you can prompt them for clarification before proceeding to answer. This is also suggested in the same OpenAI forum post (https://community.openai.com/t/938053). In your case, if a query for "Martin" returns multiple results, you could ask the user to provide more information to narrow down the search.

  3. Handle Complex Queries: For complex user queries that could be broken into multiple components, focus on the core question and provide the closest matching answer based on either the question or the associated tags. This approach is also mentioned in the OpenAI forum post (https://community.openai.com/t/938053).

  4. Use a More Advanced Query Method: If the standard "LIKE" query is returning too many results, you might consider using a more advanced method. For example, you could use vector embeddings to understand the complexity behind a question, as suggested in another OpenAI forum post (https://community.openai.com/t/785868).

Remember to always follow the order of priority: Exact match > Tag/Keyword match > Synonym match > No match. This will help ensure that the most relevant results are returned first.

#

In terms of whether to ask for clarification before executing the query or after, it would likely depend on the specific use case and the user experience you want to provide. Asking for clarification before could potentially save resources by avoiding unnecessary queries, but it might also slow down the response time for the user.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: