This project is a modular, scalable solution for Legal Question Answering (RAG). It processes legal documents, and answers user queries in natural language. The services are designed to be run on AWS infrastructure
Python
3
94 commits
updated Sep 5, 2025
LexQuery is an end-to-end solution designed to handle the entire lifecycle of legal question answering, from processing complex legal documents to deploying an API-ready chatbot interface. Built with scalability and modularity in mind, LexQuery streamlines the journey from raw legal text to actionable insights, leveraging a robust architecture tailored for production.
Whether you’re dealing with thousands of legal documents or delivering answers to users in real time, LexQuery ensures precision, performance, and scalability—all in a single, easy-to-deploy package.
This project addresses one of the most overlooked but critical challenges in the world of Retrieval-Augmented Generation (RAG): implementing a robust RAG pipeline for non-English languages, specifically tailored to the complexities of Vietnamese legal texts, in a production environment. Here's why this project deserves your attention out of the thousands of prebuilt RAG solutions available:
Custom Preprocessing for Vietnamese Texts:
Advanced Retrieval Mechanisms:
Seamless Integration of LLMs:
Unlike generic RAG solutions, LexQuery is built from the ground up to address:
LexQuery isn’t about reinventing RAG technology—it’s about adapting proven designs, like those found in frameworks such as LangChain, to meet the specific, underserved needs of startups working with Vietnamese legal content. By focusing on the niche challenges of linguistic complexity, document scalability, and cost-effective deployment, LexQuery bridges the gap between general-purpose RAG systems and the practical requirements of SMEs.
This project is built for those who need a robust, scalable pipeline to handle localized legal documents with minimal overhead. LexQuery’s approach provides a tailored solution for businesses navigating the complexities of integrating modern AI into their workflows—without the need for extensive customization or massive budgets.
legal_qa_rag/
|- format_service/ # Handles formatting raw text into structured Record objects
|- rag_service/ # Processes user queries using Retrieval-Augmented Generation
|- shared_libs/ # Contains shared utilities, models, prompts, and configurations
|- rag-cdk/ # AWS infrastructure definitions for deployment using AWS CDK
|- Dockerfile # Base Docker setup for the services
|- docker-compose.yml # Config to run multiple services during development
|- README.md # Project overview and instructions
Format Service:
Embedding Service:
RAG Service:
Shared Libraries:
Flexible LLM Providers:
Microservice Architecture:
Embedding and Search:
AWS Integration:
Cost-Efficient Operations:
API Compatibility:
Optimized Data Formatting:
Clone the Repository:
git clone https://github.com/phuocnguyen90/LexQuery.git
cd legal_qa_rag
Set Up Environment Variables:
Create a .env file or set environment variables directly. Essential variables include:
AWS_REGION: AWS region (e.g., us-east-1)CACHE_TABLE_NAME: DynamoDB table name for cachingSQS_QUEUE_URL: URL of the SQS queue for processing queriesWORKER_LAMBDA_NAME: Name of the worker Lambda functionInstall Dependencies:
pip install -r requirements.txt
Build and Run Services Locally (Development Mode):
Use Docker Compose to run multiple services during development.
docker-compose up --build
Deploy AWS Infrastructure Using CDK:
Navigate to the rag-cdk-infra/ directory and deploy the infrastructure.
cd rag-cdk-infra
cdk deploy
Deploy Services:
Services are containerized using Docker and can be deployed to AWS Lambda or ECS as per your requirements.
Submit a Query:
Send a POST request to /submit_query with query_text in the request body.
{
"query_text": "What is the process for registering a business in Vietnam?"
}
Fetch Query Result:
Send a GET request to /get_query with query_id as a query parameter.
GET /get_query?query_id=<your-query-id>
Local Testing:
Use the /local_test_submit_query endpoint to test the RAG functionality locally without relying on worker Lambdas.
{
"query_text": "What are the legal requirements for starting a business?"
}
Configure AWS CLI:
Ensure that the AWS CLI is installed and configured with your AWS credentials.
aws configure
Navigate to Infrastructure Directory:
cd rag-cdk-infra
Bootstrap AWS CDK (If Not Already Bootstrapped):
cdk bootstrap
Deploy Infrastructure:
cdk deploy
Ensure that the DynamoDB table (CACHE_TABLE_NAME) is set up with the following schema:
query_id (String)cache_key-index on cache_key (String)Ensure that the SQS queue (SQS_QUEUE_URL) is created and properly configured to receive messages for query processing.
Deploy the worker Lambda function (WORKER_LAMBDA_NAME) which will process the queries from the SQS queue.
Contributions are welcome! Please follow these steps to contribute:
Fork the Repository:
Click the "Fork" button at the top right of the repository page.
Create a New Branch:
git checkout -b feature/YourFeatureName
Make Your Changes:
Implement your feature or bug fix.
Commit Your Changes:
git commit -m "Add your descriptive commit message"
Push to Your Fork:
git push origin feature/YourFeatureName
Create a Pull Request:
Navigate to the original repository and create a pull request from your fork.
This project is licensed under the MIT License.
This project is a modular, scalable solution for Legal Question Answering (RAG). It processes legal documents, and answers user queries in natural language. The services are designed to be run on AWS infrastructure
Python
3
94 commits
updated Sep 5, 2025
LexQuery is an end-to-end solution designed to handle the entire lifecycle of legal question answering, from processing complex legal documents to deploying an API-ready chatbot interface. Built with scalability and modularity in mind, LexQuery streamlines the journey from raw legal text to actionable insights, leveraging a robust architecture tailored for production.
Whether you’re dealing with thousands of legal documents or delivering answers to users in real time, LexQuery ensures precision, performance, and scalability—all in a single, easy-to-deploy package.
This project addresses one of the most overlooked but critical challenges in the world of Retrieval-Augmented Generation (RAG): implementing a robust RAG pipeline for non-English languages, specifically tailored to the complexities of Vietnamese legal texts, in a production environment. Here's why this project deserves your attention out of the thousands of prebuilt RAG solutions available:
Custom Preprocessing for Vietnamese Texts:
Advanced Retrieval Mechanisms:
Seamless Integration of LLMs:
Unlike generic RAG solutions, LexQuery is built from the ground up to address:
LexQuery isn’t about reinventing RAG technology—it’s about adapting proven designs, like those found in frameworks such as LangChain, to meet the specific, underserved needs of startups working with Vietnamese legal content. By focusing on the niche challenges of linguistic complexity, document scalability, and cost-effective deployment, LexQuery bridges the gap between general-purpose RAG systems and the practical requirements of SMEs.
This project is built for those who need a robust, scalable pipeline to handle localized legal documents with minimal overhead. LexQuery’s approach provides a tailored solution for businesses navigating the complexities of integrating modern AI into their workflows—without the need for extensive customization or massive budgets.
legal_qa_rag/
|- format_service/ # Handles formatting raw text into structured Record objects
|- rag_service/ # Processes user queries using Retrieval-Augmented Generation
|- shared_libs/ # Contains shared utilities, models, prompts, and configurations
|- rag-cdk/ # AWS infrastructure definitions for deployment using AWS CDK
|- Dockerfile # Base Docker setup for the services
|- docker-compose.yml # Config to run multiple services during development
|- README.md # Project overview and instructions
Format Service:
Embedding Service:
RAG Service:
Shared Libraries:
Flexible LLM Providers:
Microservice Architecture:
Embedding and Search:
AWS Integration:
Cost-Efficient Operations:
API Compatibility:
Optimized Data Formatting:
Clone the Repository:
git clone https://github.com/phuocnguyen90/LexQuery.git
cd legal_qa_rag
Set Up Environment Variables:
Create a .env file or set environment variables directly. Essential variables include:
AWS_REGION: AWS region (e.g., us-east-1)CACHE_TABLE_NAME: DynamoDB table name for cachingSQS_QUEUE_URL: URL of the SQS queue for processing queriesWORKER_LAMBDA_NAME: Name of the worker Lambda functionInstall Dependencies:
pip install -r requirements.txt
Build and Run Services Locally (Development Mode):
Use Docker Compose to run multiple services during development.
docker-compose up --build
Deploy AWS Infrastructure Using CDK:
Navigate to the rag-cdk-infra/ directory and deploy the infrastructure.
cd rag-cdk-infra
cdk deploy
Deploy Services:
Services are containerized using Docker and can be deployed to AWS Lambda or ECS as per your requirements.
Submit a Query:
Send a POST request to /submit_query with query_text in the request body.
{
"query_text": "What is the process for registering a business in Vietnam?"
}
Fetch Query Result:
Send a GET request to /get_query with query_id as a query parameter.
GET /get_query?query_id=<your-query-id>
Local Testing:
Use the /local_test_submit_query endpoint to test the RAG functionality locally without relying on worker Lambdas.
{
"query_text": "What are the legal requirements for starting a business?"
}
Configure AWS CLI:
Ensure that the AWS CLI is installed and configured with your AWS credentials.
aws configure
Navigate to Infrastructure Directory:
cd rag-cdk-infra
Bootstrap AWS CDK (If Not Already Bootstrapped):
cdk bootstrap
Deploy Infrastructure:
cdk deploy
Ensure that the DynamoDB table (CACHE_TABLE_NAME) is set up with the following schema:
query_id (String)cache_key-index on cache_key (String)Ensure that the SQS queue (SQS_QUEUE_URL) is created and properly configured to receive messages for query processing.
Deploy the worker Lambda function (WORKER_LAMBDA_NAME) which will process the queries from the SQS queue.
Contributions are welcome! Please follow these steps to contribute:
Fork the Repository:
Click the "Fork" button at the top right of the repository page.
Create a New Branch:
git checkout -b feature/YourFeatureName
Make Your Changes:
Implement your feature or bug fix.
Commit Your Changes:
git commit -m "Add your descriptive commit message"
Push to Your Fork:
git push origin feature/YourFeatureName
Create a Pull Request:
Navigate to the original repository and create a pull request from your fork.
This project is licensed under the MIT License.