Find answers from the community

Updated 3 months ago

Sql context

I'm trying to add context to a structured table using the same method as shown below, but it doesn't seem to work. Has anyone successfully injected context to a sql table?


Plain Text
# manually set context text
city_stats_text = (
    "This table gives information regarding the population and country of a given city.\n"
    "The user will query with codewords, where 'foo' corresponds to population and 'bar'"
    "corresponds to city."
)

from llama_index.objects import SQLTableNodeMapping, SQLTableSchema

table_node_mapping = SQLTableNodeMapping(sql_database)
table_schema_objs = [
    (SQLTableSchema(table_name="city_stats", context_str=city_stats_text))
]




Sources:
https://github.com/jerryjliu/llama_index/blob/main/docs/examples/index_structs/struct_indices/SQLIndexDemo.ipynb
https://gpt-index.readthedocs.io/en/latest/end_to_end_tutorials/structured_data/sql_guide.htm
L
P
14 comments
How do you know it doesn't work?
Is there an error?
I tried running a new query in the same ipynb, it was not providing any response as per the context.
So that text is only used for embeddings and retirveing the tables actually
Lol wait I'm wrong again, I have not touched any of this code before
But "the user will query with codeworss, where 'foo' corresponds to population" what is it for ?
Tbh I have no idea. Seems like a really strange example notebook
If you turn on debug logs, you can see the inputs the LLM inputs are

Plain Text
import openai
openai.log = "debug"
Thanks, I will check.
If we do not manually add context how does llm understand the table schema?
Is there anyway to check what type of data/information it stores about the table?
There is a step that pulls the sql schema for the table automtaically
@Logan M my usecase is to create a chatbot for large datasets, and i would like to add context for each table.

What approach should I take?
For example: I have an ecommerce dataset, and I would like to explain how to perform calculations such as gross margin, LTV, calculating new customers etcs, all based in the columns in the table
Add a reply
Sign up and join the conversation on Discord