run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.71k stars 5.26k forks source link

[Question]: AzureChatStore: Ensuring Asynchronous Requests and Understanding _atable_service_client Usage #15231

Open gazambuja opened 3 months ago

gazambuja commented 3 months ago

Question Validation

Question

I'm working on integrating AzureChatStore into my project and want to ensure that all requests to the store are made asynchronously to optimize performance. I've been reviewing the source code, but I'm having trouble understanding the following:

Any insights or guidance on these questions would be greatly appreciated. Thanks in advance for your help!

chat_store = AzureChatStore.from_connection_string(
    connection_string=self.azure_connstr,
    chat_table_name="memory",
)

memory = ChatMemoryBuffer.from_defaults(
    token_limit=3900,
    chat_store=chat_store,
    chat_store_key=user_key
)
dosubot[bot] commented 3 months ago

Hey @gazambuja! I'm here to help you with any questions or issues you have regarding the AzureChatStore. Feel free to ask me anything!

AzureChatStore explicitly makes asynchronous requests using the _atable_service_client, which is an instance of AsyncTableServiceClient from the azure.data.tables.aio module. This client is designed to handle asynchronous operations.

The difference between _atable_service_client and _table_service_client is as follows:

This distinction allows AzureChatStore to support both synchronous and asynchronous interactions with Azure Table Storage or Cosmos DB. The AzureKVStore class, for example, initializes these clients and provides methods like put and aput for synchronous and asynchronous operations, respectively [1][2].

For ensuring asynchronous operations, you should use methods provided by AsyncTableServiceClient, such as create_table_if_not_exists, upsert_entity, submit_transaction, get_entity, list_entities, delete_entity, and query_entities [1][2].

To continue talking to Dosu, mention @dosu.

git-hamza commented 2 months ago

Commenting here to follow this, Since I am also working on something similar.

Meanwhile If somebody can answer this or point me to the direction since I am unable to find anything in the documentation page.

I want to keep each user's chat history. For now I am been using SimpleChatStore but now I want to replace it with AzureChatStore.

Right now my functionality looks something like this; I load the chatstore from the disk with. chat_store = SimpleChatStore.from_persist_path(persist_path="chat_store.json")

It has all of the user's chat history and I can retrieve from it and displays it for the specific user when they log in to their session.

After they are done with their query, I run chat_store.persist(persist_path="chat_store.json") This stores the updated chat in the memory.

With AzureChatStore, LlamaIndex Demo: Azure Table Storage as a ChatStore shows loading of chat_store from AzureChatStore. My question is how to persist the chat history on the Azure after each query, Do we explicitly call add_message after processing of each query?