The Legal AI Assistant project aims to create an AI-driven tool that streamlines legal research and document drafting. To accomplish this, we will utilize the Retrieval-Augmented Generation (RAG) framework, which merges a knowledge base with large language models (LLMs) to ensure accurate and current information. The RAG framework consists of three primary components: embedding, retrieval, and generation. Embedding: Transforming text into a format suitable for knowledge base storage. Retrieval: Extracting pertinent information from the knowledge base based on user queries.
Generation: Utilizing the retrieved information along with the user query to produce responses with an LLM.
- Data Collection and Preprocessing: Gather a dataset of legal documents, case laws, statutes, and legal opinions (all related to Hong Kong). These legal documents can include but are not limited to Hong Kong Basic Law, and various ordinances. Clean and preprocess the data to ensure it is suitable for the knowledge base.
- Knowledge Base Construction: Build a comprehensive and up-to-date knowledge base from the preprocessed legal data.
a. Create a vector database or knowledge graph to store information.
b. Implement a feature that allows users to add personal knowledge bases.
c. Utilize an embedding model, likely based on the BERT architecture, fine-tuned for the legal domain. - Model Integration: Integrate the knowledge base with a large language model (LLM) utilizing the RAG framework. This integration will empower the system to retrieve relevant documents from the knowledge base and produce accurate, context-aware responses. For the main LLM, there are various options to consider, including deploying an open-source model like LLaMa on a server or utilizing API calls to established LLMs such as GPT-4. We will explore these alternatives and select the most practical option.
In addition to the primary LLM, we can incorporate helper models during both the retrieval and generation phases. These models can assist in refining input queries by eliminating unnecessary words, thereby enhancing the relevance of the information retrieved. Furthermore, they can help rerank the results obtained from the retrieval phase before they are processed by the main LLM. Specifically, after the retrieval phase identifies the top K results for a given query, another LLM can evaluate and rank these results based on their relevance. - System Development: Design the user interface to facilitate smooth and intuitive interactions between users and the AI system. We are considering two main approaches for the application: a native app and a web app.
A native application offers enhanced data privacy, allowing users to store their personal knowledge bases locally without needing to upload documents to a remote server. Conversely, a web application provides greater convenience and accessibility, as users can engage with the system without having to install any software on their personal devices. Once the type of application is selected, we will determine the frameworks for both
the frontend and backend. - Testing and Validation: Conduct thorough testing of the system to guarantee accuracy, reliability, and adherence to legal standards. A crucial aspect of theapplication is ensuring that the LLM does not produce “hallucinations,” and this feature will be rigorously evaluated to confirm the software’s dependability. Additionally, after the initial prototype is completed, it will be made available to a select group of users for testing and feedback. This group will include both individuals with legal backgrounds, such as law students, and those from other fields. User feedback will be utilized to implement minor adjustments to enhance the application.
- Deployment and Maintenance: Deploy the system and provide continuous
maintenance. Find a way to continuously keep the knowledge base up to date.