This repository provides a full pipeline for building a retrieval-augmented system using a two-tower (dual-encoder) neural network architecture, trained and evaluated on the MS MARCO dataset. The system leverages ChromaDB for efficient vector storage and retrieval, and supports both classic and modern (LangChain-based) RAG pipelines.
- Train a two-tower BERT-based neural network with LoRA on MS MARCO.
- Encode and store passage embeddings in a persistent ChromaDB vector database.
- Query the database for relevant passages using a trained query encoder.
- RAG (Retrieval-Augmented Generation) pipelines for question answering, including a LangChain-based implementation.
- Train the Dual-Encoder Model
- Run
s1_train_tnn_bert.pyto train the two-tower BERT model with LoRA on MS MARCO.
- Run
- Build the Passage Database
- Run
s2_store_passages_in_database_bert.pyto encode MS MARCO passages and store them in a ChromaDB vector database.
- Run
- Query the Database
- Use
s3_query_database_bert.pyto interactively query the ChromaDB database for relevant passages.
- Use
- RAG Pipelines
s4_rag.py: A RAG pipeline using the ChromaDB database and a transformer.s4_rag2.py: A RAG pipeline using LangChain, ChromaDB database, and a transformer.
- Install dependencies
pip install -r requirements.txt # For LangChain RAG (s4_rag2.py): pip install langchain langchain-community chromadb transformers sentence-transformers - (Optional) Set up Weights & Biases
- For experiment tracking, set your
WANDB_API_KEYas an environment variable.
- For experiment tracking, set your
- Train the model:
python s1_train_tnn_bert.py
- Build the passage database:
python s2_store_passages_in_database_bert.py
- Query the database:
python s3_query_database_bert.py
- Run a RAG pipeline:
python s4_rag.py # or python s4_rag2.py
- The default models and paths can be changed in the scripts as needed.
- Ensure you have enough disk space for ChromaDB and MS MARCO data.