Find answers from the community

Home
Members
Byamasu Patrick
B
Byamasu Patrick
Offline, last seen 3 months ago
Joined September 25, 2024
Hello, is it possible to defined a query indexes for multiple tables instead of just using one table. I tried one which uses SQLDatabaseChain on one table it seems to work perfectly fine. But the one that talks about Indexing (Many Tables) many tables wit SQLTableRetrieverQueryEngine is giving very worse results. Is there a way I can improve on this ?
1 comment
L
I have expanded my integration using this guide
https://gpt-index.readthedocs.io/en/latest/examples/index_structs/struct_indices/SQLIndexDemo-ManyTables.html
However, I am not getting the good results. My goal is to add an agent that will be able to analyze the request and perform the analysis before running the SQL query. Is there an interface which provide that feature?
5 comments
L
B
I have the following code which works perfectly fine, and I can then use the SQLTableRetrieverQueryEngine to query the database and get answers. But I want to be able to create the index once so I can reuse it without recreating it every time. Is it possibile to achieve that @Logan M ?

Here is my code:

def table_index_builder(sql_database, table_context_dict: dict[str, Literal]) -> ObjectIndex: table_node_mapping = SQLTableNodeMapping(sql_database) table_schema_objs: list[SQLTableSchema] = [] # Build our table schema for table_name in table_context_dict: # one SQLTableSchema for each table table_schema = (SQLTableSchema( table_name=table_name, context_str=table_context_dict[table_name])) table_schema_objs.append(table_schema) obj_index = ObjectIndex.from_objects( table_schema_objs, table_node_mapping, VectorStoreIndex, ) return obj_index def build_query_engine(sql_database: SQLDatabase, service_context: ServiceContext, table_context_dict: dict[str, Literal]) -> SQLTableRetrieverQueryEngine: # build object index obj_index = table_index_builder( sql_database, table_context_dict=table_context_dict) query_engine = SQLTableRetrieverQueryEngine( sql_database=sql_database, table_retriever=obj_index.as_retriever(similarity_top_k=2), service_context=service_context ) return query_engine
2 comments
B
L
Here is my code and the error I am getting

sql_database = SQLDatabase.from_uri(db_uri) table_node_mapping = SQLTableNodeMapping(sql_database) all_table_names = [ "responses", "demographic", "respondents"] table_schema_objs = [] for table_name in all_table_names: table_schema_objs.append(SQLTableSchema(table_name=table_name)) obj_index = ObjectIndex.from_objects( table_schema_objs, table_node_mapping, VectorStoreIndex, )

python main.py Traceback (most recent call last): File "C:\Users\hp\Desktop\openai\main.py", line 64, in <module> obj_index = ObjectIndex.from_objects( File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\base.py", line 50, in from_objects nodes = object_mapping.to_nodes(objects) File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\base_node_mapping.py", line 55, in to_nodes return [self.to_node(obj) for obj in objs] File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\base_node_mapping.py", line 55, in <listcomp> return [self.to_node(obj) for obj in objs] File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\table_node_mapping.py", line 46, in to_node f"{self._sql_database.get_single_table_info(obj.table_name)}\n" AttributeError: 'SQLDatabase' object has no attribute 'get_single_table_info'

Can someone help me how to resolve this error? I have tried to check my code everything seems to work perfectly fine
7 comments
B
L