Find answers from the community

Updated 2 years ago

hi i tried the example shown here

At a glance
hi. i tried the example shown here: https://gpt-index.readthedocs.io/en/latest/how_to/composability.html#defining-summary-text

im getting the error shown in the image. any idea what im doing wrong? "summarize" does seem to be a valid query mode @jerryjliu0
Attachments
Screenshot_2023-02-28_at_12.02.34_AM.png
Screenshot_2023-02-27_at_11.59.00_PM.png
1
2
a
j
28 comments
also related question, why is "Summary" needed for structured data like a SQL index? makes sense why it is needed for chunkifying unstructured data like a notion doc
to be clear, i'm just trying to use llama-index for natural language to SQL. i started trying the GPTTreeIndex and the GPTListIndex to run join queries across base indices. should i be taking a different approach? @jerryjliu0
hi, @alex you want to use the SQL index right? for the SQL index you shouldn't be customizing the mode, just leave it as "default" - that's our default text-to-SQL interface
thanks for the quick reply! is there a way to increase the completion token limit? SQL generated from the summary prompt is being cut off in the middle because my table has too many columns
thanks!

also, what are the summaries from these GPTSQLStructStoreIndex objects used for? i see that its generating a bunch of stuff like sums and averages. doesnt it make more sense to just get a description for each table, and feed that to a top level node or something so it has context to perform join queries?
@alex to clarify, what do you mean by summaries? (also i might head off to bed soon but will respond tmrw)
the input for BaseGPTIndex.set_text() , which needs to be set when creating combined indices
Ah I see. You can set the summaries to whatever you want!

We need summaries primarily for composability - since that allows you to define indices on top of other indices, each subindex needs to correspond to some "text" so that the top-level index can index over that
@jerryjliu0 ooh i think i know how to use the SQL Index now...i tried following along with this screenshot in your docs/twitter thread but was really confused about how the GPTStructStoreIndex only accepts a single table_name value, even if the index is being used for JOIN queries

i just picked an arbitrary table in my db, built the context and saved it on the index with store_context_str=True, and queried that 1 SQL Index obj and it seems to be doing pretty well so far
Attachment
FpvipPDagAUZqyf.png
any tips on how to deal with hallucinations? i notice it'll sometimes make up a column or table that doesnt exist
Hi @alex yeah sorry it's really confusing, I'll look into cleaning this up. The table_name field on the index constructor is only needed if you're looking to infer structured datapoints from unstructured data. For text-to-SQL every table included in the SQLDatabase will be used in the prompt.
@jerryjliu0 is there a way to customize the prompt template for PTStructStoreIndex? im currently hacking around it by hardcoded extra context into my query string itself
im using BaseGPTIndex.query (using a GPTSQLStructStoreIndex, not GPTNLStructStoreIndexQuery ). looks like its only for the latter @jerryjliu0
Attachment
Screenshot_2023-03-01_at_8.27.20_AM.png
yeah. the former is literally just a raw SQL query (it's actually not that useful since you can also just query the SQL engine directly)
sorry if this is stupid question, i am completely new to python, but these AI stuff are mindblowing, so i just cant resist to try something.
so, my question is: how should I pass that text_to_sql_prompt to index.query call?

index.query("bla-bla-bla", text_to_sql_prompt=PROMPT) - this leads to error that text_to_sql is not allowed in query call 😦
hi @TopClans (Азат) , 1) are you using the sql index, and 2) what prompt are you using? let me know if you have a code snippet
1) im using GPTNLStructStoreIndexQuery (hope i answered right)
2) PROMPT_TMPL = ( "This is mysql database schema. \n" "---------------------\n" "{schema}" "\n---------------------\n" "Given this information, please return SQL query, and nothing else: {query_str}\n" ) PROMPT = TextToSQLPrompt(PROMPT_TMPL)
btw, there is an example: https://gpt-index.readthedocs.io/en/stable/reference/indices/struct_store_query.html#gpt_index.indices.query.struct_store.GPTNLStructStoreIndexQuery

response = index.query("<query_str>", mode="sql")

when i add mode="sql", it says:
TypeError: query() got an unexpected keyword argument 'mode'
hi @TopClans (Азат) , what is your index variable? So, GPTNLStructStoreIndexQuery is not public facing, you would instead do something like this:
Plain Text
index = GPTSQLStructStoreIndex(
    documents=documents,
    sql_database=sql_database, 
    table_name="city_stats",
)

index.query("text to sql", mode="default", prompt=prompt)

Setting mode="default" will use the GPTNLStructStoreIndexQuery class under the hood
this is my code:
PROMPT = TextToSQLPrompt(PROMPT_TMPL) prompt_helper = PromptHelper(4096, 4096, 10) index = GPTNLStructStoreIndexQuery( [], sql_database=sql_database, sql_context_container=context_container, prompt_helper=prompt_helper ) response = index.query(query_str, mode="default", prompt=PROMPT)
using index via GPTSQLStructStoreIndex with param prompt:
index = GPTSQLStructStoreIndex( [], sql_database=sql_database, table_name="1c_sales_items", )
response = index.query("blablabla?", mode="default", prompt=PROMPT)

and getting error:
TypeError: __init__() got an unexpected keyword argument 'prompt'
and if dont use that prompt, generated SQL query consist ambiguous field
btw I watched your podcast with Weaviate yesterday and you described some mind-blowing opportunities for devs, thats very impressive technology
sorry i named the prompt field wrong
try index.query(..., text_to_sql_prompt=...)
Add a reply
Sign up and join the conversation on Discord