Find answers from the community

Updated 4 months ago

Sql langchain

At a glance

The community members are discussing how to use the LangChain SQLDatabase Chain with an embedded table schema index, similar to the feature provided by Llamaindex. The main challenges they face are:

1. The SQL index query can only return the SQL result, which needs to be converted into a customized summary. However, when the SQL result is large, directly using the QuestionAnswer prompt to convert it to natural language hits the token limit.

2. Passing the entire SQL result as one document throws format errors, while splitting each row as a separate document results in the prompt only returning one row record.

The community members suggest creating a list index on the fly and querying to summarize it, as Llamaindex can handle the token limits. However, they are unsure how well it will perform with raw SQL results and may need to customize the prompt template.

Additionally, the community members discuss whether the SQLIndex query can generate a natural language result directly, instead of just presenting the SQL dataset. The response indicates that this feature is not currently available, but the Llamaindex team would like to add it in the future.

Finally, the community members inquire about Llamaindex's support for GPT-4, and receive guidance on how to set the model name and ensure access to

Useful resources
Hi, how to use langchain SQLDatabase Chain with embedded table schema index? Llamaindex provide option to store embedded table schema index from service context. Then how to use similar one from Langchain?
L
c
9 comments
I ended up not using the sql database chain and used my own custom chain

Check out this example using the sql index + langchain

https://huggingface.co/spaces/llamaindex/llama_index_sql_sandbox/tree/main
@Logan M Thanks Logan. This is similar to what I'm trying now. However, currently I face challenge is that for sql index query, it could only return sql result. However, we need to convert sql result back into a customized summary way. So what I'm facing is that sometimes is sql result is large, directly using QuestionAnswer prompt to convert sql result back to natural langauge hit token limit. Then I tried using index, but passing all sql result as one document still will throw some format error. However, if I split each row as one document, prompt result always return only 1 row record. Do you have any better suggestion for this?
Hmm, maybe you can create a list index on the fly and query to summarize it?

Then llama index will handle all the token limits for you

Not sure how good it will be at reading a raw sql result though. Might need to customize the prompt template?
@Logan M can sqlindex query generate natural language result directly? instead of just presenting sql dataset?
Currently no. Would love to add that feature someday though πŸ˜…
That's why I used a langcahin agent in my demo. But you are right, if the sql result is too big it'll cause token problems with the agent
@Logan M Thanks though.
@Logan M and one more question. Currently does llamaindex support gpt4? I try to convert to gpt4. But when use verctor index.query, it shows error of needs engine or deployment id, which I've already passed api key.
It should support gpt 4, just need to make sure you set the model name (and also make sure you have access)

For example, this notebook uses gpt4 https://github.com/jerryjliu/llama_index/blob/main/examples/test_wiki/TestNYC-Tree-GPT4.ipynb
Add a reply
Sign up and join the conversation on Discord