Find answers from the community

Updated 3 months ago

Sql langchain

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