Home > Workload Solutions > Data Analytics > White Papers > Multimodal RAG Chatbot Powered by Dell Data Lakehouse > 7. Data Decomposition
The LLM decomposes the retrieved data into SQL and non-SQL components. This decomposition separates structured data that can be queried using SQL from other data types that may require different processing.
# Data Decomposition
import re
# Function to decompose LLM response into SQL and non-SQL components
def decompose_llm_response(response):
# Regular expressions to identify SQL queries
sql_pattern = re.compile(r'(SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)\s.*?;', re.IGNORECASE | re.DOTALL)
# Extract SQL queries
sql_queries = sql_pattern.findall(response)
# Extract non-SQL components (textual explanations, metadata, etc.)
non_sql_components = sql_pattern.sub('', response).strip()
return sql_queries, non_sql_components
# Decompose the LLM response
sql_queries, non_sql_components = decompose_llm_response(llm_response)
# Output the SQL queries and non-SQL components
print("SQL Queries:", sql_queries)
print("Non-SQL Components:", non_sql_components)