Python Forum

Full Version: Chatbot database RAG
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am currently developing a chatbot to interact with an already existing database that is coded in MySql. As for the framework, I am using django and trying to implement async functionalities. I am stuck in a part of the code that handles the RAG request. The specific part is down below: Reference code.

Open the image in a new tab, in order to be able to zoom. The code is pretty extensive.

The problem is that when finishing the sql_database function and returning it to the load_process_database function, I get the error of:
Error:
Unexpected error during vectorstore initialization: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 23796 and this is thread id 28192. Error type: <class 'django.db.utils.DatabaseError'> Error args: ("DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 23796 and this is thread id 28192.",)


Just so you know, this error was customised by me. That is why is says that the is an error during the vectorstore initialization.

The full file code is attached. [attachment=2965]

Thank you in advance
Not sure if mysql supports vectors. Can you try with Postgre sql. It has vector support
Ensure database access stays in the same thread.
Use django.db.connection.ensure_connection() to check if the connection is valid.
Consider using connection pooling (e.g., django-db-connection-pool).
Use sync_to_async for running database queries in async functions.
In the context of building chatbots with Retrieval-Augmented Generation (RAG), "Thread Modes" likely refers to different approaches or configurations for managing conversation history and context within a RAG chatbot, while "database RAG" indicates using a database to store and retrieve relevant information for the chatbot's responses. RAG stands for retrieval augmented generation. In simple terms, RAG is the process of providing a Large Language Model (LLM) with specific information relevant ...The article provides a guide on how to build a personal RAG Chatbot using LlamaIndex and Open LLMs. This tool can revolutionize your data interactions.