----------------------
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
:
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:
----------------------