Closed danielstankw closed 5 months ago
π€
Hello @danielstankw! I'm Dosu, an automated assistant here to lend a hand while we wait for a human maintainer. I'm equipped to help you troubleshoot bugs, answer any questions you might have, and guide you on becoming a contributor. Let's figure this out together!
Based on the information you've provided, it seems like the query_engine.query()
method is generating the correct SQL query, but the response it returns is incorrect. This could be due to how the method processes the response from the SQL query.
The query_engine.query()
method in the LlamaIndex codebase is part of the RouterQueryEngine
class. It selects one out of several candidate query engines to execute a query, executes the query, and returns a response. If multiple query engines are selected, it executes the query on each of them and collects the responses. If more than one response is received, it combines them using a summarizer. If only one response is received, it is used as the final response.
Here is the relevant code:
def _query(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:
with self.callback_manager.event(
CBEventType.QUERY, payload={EventPayload.QUERY_STR: query_bundle.query_str}
) as query_event:
result = self._selector.select(self._metadatas, query_bundle)
if len(result.inds) > 1:
responses = []
for i, engine_ind in enumerate(result.inds):
logger.info(
f"Selecting query engine {engine_ind}: " f"{result.reasons[i]}."
)
selected_query_engine = self._query_engines[engine_ind]
responses.append(selected_query_engine.query(query_bundle))
if len(responses) > 1:
final_response = combine_responses(
self._summarizer, responses, query_bundle
)
else:
final_response = responses[0]
else:
try:
selected_query_engine = self._query_engines[result.ind]
logger.info(
f"Selecting query engine {result.ind}: {result.reason}."
)
except ValueError as e:
raise ValueError("Failed to select query engine") from e
final_response = selected_query_engine.query(query_bundle)
# add selected result
final_response.metadata = final_response.metadata or {}
final_response.metadata["selector_result"] = result
query_event.on_end(payload={EventPayload.RESPONSE: final_response})
return final_response
Source: llama_index/query_engine/router_query_engine.py
It's possible that the issue lies in how the query_engine.query()
method processes the SQL query response, or in how it combines multiple responses if more than one query engine is selected.
To further investigate this issue, could you please provide more information about the query_engine.query()
method and the RouterQueryEngine
class? Specifically, it would be helpful to know how the method processes the SQL query response, and how it combines multiple responses if more than one query engine is selected. Additionally, could you please provide the code for the combine_responses()
function and the summarizer
object? This information will help us understand why the query_engine.query()
method is returning an incorrect response despite generating the correct SQL query.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a π if this is helpful and π if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Bug Description
When using an LLM I obtain correct SQL query for my question.
The response I get is:
If I take this query and run it using
sql_database.run_sql(sql_query)
I do obtained a correct answer.Version
0.9.13
Steps to Reproduce
None
Relevant Logs/Tracbacks
No response