Hello everyone,
I’m building a RAG system where a user asks a question, and I need to determine whether they’re asking for a single, specific file or a list of related files from a database. I’m exploring two main architectural approaches and would appreciate some guidance on which is considered better industry practice.
The Situation: A user inputs a query, for example:
-
“Show me the details for the
2024_Q3_Report.pdffile.” (This requires a specific file lookup). -
“List all the reports for Q3.” (This requires a list of files).
My Two Proposed Approaches:
-
LLM as a Simple Classifier:
-
I would create a prompt that asks the LLM to classify the user’s intent into a specific category.
-
Example Prompt: “Categorize the following query. Output ‘1’ for a specific file request or ‘2’ for a list request. User query: [user_query]”
-
Based on the number returned by the LLM, my application code would then execute the appropriate database query (either
SELECT * FROM files WHERE filename = '...'orSELECT filename FROM files WHERE name LIKE '%...').
-
-
LLM with Function Calling:
-
I would define two functions in my application:
get_file_details(file_name)andlist_similar_files(query). -
I would then use the OpenAI API’s function-calling capability, providing it with the definitions of these two functions.
-
The LLM would analyze the user’s query and decide which function to call and with what arguments. My application would then intercept this function call and execute the corresponding database query.
-
My Questions for the Community:
-
Which of these two approaches is more efficient and reliable for a production environment?
-
Which is considered standard industry practice?
-
Are there any significant downsides to the simple classification approach that I might not be considering? (For example, is it brittle?)
I appreciate any insights you can provide. Thanks!