Find answers from the community

Updated last year

How to enable the llms to perform sql joins if the use query requires a join to get the ou

At a glance
The community member asked how to enable LLMs (Large Language Models) to perform SQL joins when the query requires a join to get the output. Another community member responded that the SQLJoinQueryEngine provided by LlamaIndex can be used for this purpose. This query engine allows combining insights from structured tables with unstructured data. However, the provided extracts did not include a specific example of using SQLJoinQueryEngine. Instead, they provided an example of using NLSQLTableQueryEngine to perform a natural language query that translates to a SQL query. The community member suggested checking the official LlamaIndex documentation or the source code on GitHub for more details on using SQLJoinQueryEngine.
@kapa.ai How to enable the llms to perform sql joins if the use query requires a join to get the output
k
2 comments
Please stand by @Karthik as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To enable LLMs to perform SQL joins, you can use the SQLJoinQueryEngine provided by LlamaIndex. This query engine allows you to combine insights from your structured tables with your unstructured data. It first decides whether to query your structured tables for insights. Once it does, it can then infer a corresponding query to the vector store in order to fetch corresponding documents.

Unfortunately, the provided extracts do not include a specific example of using SQLJoinQueryEngine. However, they do provide an example of using NLSQLTableQueryEngine to perform a natural language query that translates to a SQL query under the hood. This might give you an idea of how to use SQLJoinQueryEngine.

Here is the example code for NLSQLTableQueryEngine:

Plain Text
from llama_index.indices.struct_store.sql_query import NLSQLTableQueryEngine
from IPython.display import Markdown, display

query_engine = NLSQLTableQueryEngine(
    sql_database=sql_database,
    tables=["github_issues", "github_comments", "github_users"],
)
query_str = "Which issues have the most comments? Give the top 10 and use a join on url."
response = query_engine.query(query_str)
display(Markdown(f"<b>{response}</b>"))


You can find more details about this in the source ().

For more specific usage of SQLJoinQueryEngine, I recommend checking the official LlamaIndex documentation or the source code on GitHub.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord