Find answers from the community

Updated 3 months ago

How to use "ChatMemoryBuffer" with SQLTableRetrieverQueryEngine

How to use "ChatMemoryBuffer" with SQLTableRetrieverQueryEngine
k
v
L
9 comments
Please stand by @vinodvarma24 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
Based on the provided extracts, there is no direct interaction mentioned between ChatMemoryBuffer and SQLTableRetrieverQueryEngine. However, I can provide information on how to use each of them separately.

ChatMemoryBuffer is a simple buffer for storing chat history. It has several methods such as from_dict, from_orm, from_string, get, get_all, and json for various operations like creating a chat memory buffer from a dictionary or a string, getting the chat history, and generating a JSON representation of the model. Here is an example of how to use from_string method:

Plain Text
ChatMemoryBuffer.from_string(json_str)


On the other hand, SQLTableRetrieverQueryEngine is used to construct a query engine that can retrieve relevant table schema and synthesize a SQL query and a response from the results of that query. Here is an example of how to use it:

Plain Text
query_engine = SQLTableRetrieverQueryEngine(
    sql_database, obj_index.as_retriever(similarity_top_k=1)
)
response = query_engine.query("Which city has the highest population?")
print(response)


In this example, sql_database is your SQLDatabase and obj_index is your table schema index.

For more detailed information, you can refer to the LlamaIndex documentation ().

Please note that the interaction between ChatMemoryBuffer and SQLTableRetrieverQueryEngine might require additional steps or methods that are not mentioned in the provided extracts.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai give me any notebooks for implementing ChatMemoryBuffer
@kapa.ai give me any notebooks for implementing ChatMemoryBuffer
@Logan M Any insight here would be of a great help?
Chat memory buffer only works with agents/chat engines. So you'll have to setup one of those with your sql query engine as a part of it
@Logan M Hey Logan, Now I' trying to use CondenseQuestionChatEngine on top of my SQL query engine, and i'm following this notebook. But not sure where to import the CondenseQuestionChatEngine from. Can you please help me? Here is the error im facing: NameError Traceback (most recent call last) Cell In[14], line 85 66 custom_chat_history = [ 67 ChatMessage( 68 role=MessageRole.USER, (...) 74 ) 75 ] 77 query_engine = SQLTableRetrieverQueryEngine( 78 sql_database, 79 object_index.as_retriever(similarity_top_k=3), (...) 82 service_context=service_context 83 ) ---> 85 chat_engine = CondenseQuestionChatEngine.from_defaults( 86 query_engine=query_engine, 87 condense_question_prompt=custom_prompt, 88 chat_history=custom_chat_history, 89 verbose=True 90 ) 91 end = time.time() 92 print(f"Time taken by SQLTableRetrieverQueryEngine: {end - start} seconds") NameError: name 'CondenseQuestionChatEngine' is not defined https://gpt-index.readthedocs.io/en/latest/core_modules/query_modules/chat_engines/usage_pattern.html
from llama_index.chat_engine import CondenseQuestionChatEngine
Figured it out meanwhile, Thanks @Logan M
Add a reply
Sign up and join the conversation on Discord