This project implements a Retrieval-Augmented Generation (RAG) system designed to load and process two types of documents:
The system ingests these files, chunks their content, converts the chunks into vector embeddings using a multilingual transformer model, and stores them in a FAISS vector index. It supports searching for relevant chunks based on a user query, applies a re-ranking model to improve result relevance, and finally generates an answer using an OpenAI GPT-4o large language model (LLM).
The application is built with Python and FastAPI, exposing endpoints for file upload and search queries.
intfloat/multilingual-e5-large โ for multilingual text embeddings (supports English and Hebrew)HybridChunker from docling:
Alibaba-NLP/gte-multilingual-reranker-base โ cross-encoder model improves final relevance score and selects the best-matching chunkWhile not currently included, the system design allows optional hybrid search, combining:
rank_bm25)Hybrid retrieval could be useful for identifying documents that match specific keywords or terminology (e.g., names, codes, units), complementing semantic retrieval. In this implementation, it was not integrated, as the semantic retrieval with dense embeddings was sufficient for the use case.
Clone the repository:
git clone https://github.com/yakov-el/rag-project.git
cd rag-project
Create and activate a Python virtual environment:
bash
Copy
Edit
python -m venv env
On Windows:
bash
Copy
Edit
.\env\Scripts\activate
On Linux/Mac:
bash
Copy
Edit
source env/bin/activate
Install dependencies:
bash
Copy
Edit
pip install -r requirements.txt
Set your OpenAI API key as an environment variable (optional), or pass it directly when making search requests.
โ๏ธ Running the Application
Launch the FastAPI server:
bash
Copy
Edit
uvicorn main:app --reload
Visit: http://localhost:8000
๐ Usage
Upload Files
Send a POST request to /upload with .xlsx or .docx files.
The system will:
Load the documents
Chunk their content (large โ small)
Embed each chunk
Index them in FAISS
Search Query
Send a GET request to /search:
bash
Copy
Edit
/search?q=your_question&apikey=your_openai_api_key
Example:
perl
Copy
Edit
http://localhost:8000/search?q=What%20is%20the%20purpose%20of%20the%20home%20test?&apikey=sk-...
The system will return:
The most relevant chunks
Reranked results
A final answer generated by GPT-4o
๐๏ธ Architecture Overview
sql
Copy
Edit
+--------------------+
| Upload Excel/Word |
+--------------------+
โ
+----------------------------+
| Chunking (HybridChunker) |
+----------------------------+
โ
+----------------------------+
| Embedding (E5 model) |
+----------------------------+
โ
+----------------------------+
| FAISS Vector Store |
+----------------------------+
โ
+----------------------------+
| Query Embedding |
+----------------------------+
โ
+----------------------------+
| Retrieve Top-k Neighbors |
+----------------------------+
โ
+----------------------------+
| Re-Rank (Cross Encoder) |
+----------------------------+
โ
+----------------------------+
| Answer with GPT-4o |
+----------------------------+
๐ Notes
The system supports both English and Hebrew content
Your OpenAI API key should be kept private
Image-to-text alignment is implemented, but images are not embedded or passed to GPT-4o
You can extend the system to support additional file formats or search strategies
๐ซ Contact
Feel free to fork, star, or open issues on the GitHub repo.
5 commits
Python
73.5%
JavaScript
14.6%
HTML
11.9%
This project implements a Retrieval-Augmented Generation (RAG) system designed to load and process two types of documents:
The system ingests these files, chunks their content, converts the chunks into vector embeddings using a multilingual transformer model, and stores them in a FAISS vector index. It supports searching for relevant chunks based on a user query, applies a re-ranking model to improve result relevance, and finally generates an answer using an OpenAI GPT-4o large language model (LLM).
The application is built with Python and FastAPI, exposing endpoints for file upload and search queries.
intfloat/multilingual-e5-large โ for multilingual text embeddings (supports English and Hebrew)HybridChunker from docling:
Alibaba-NLP/gte-multilingual-reranker-base โ cross-encoder model improves final relevance score and selects the best-matching chunkWhile not currently included, the system design allows optional hybrid search, combining:
rank_bm25)Hybrid retrieval could be useful for identifying documents that match specific keywords or terminology (e.g., names, codes, units), complementing semantic retrieval. In this implementation, it was not integrated, as the semantic retrieval with dense embeddings was sufficient for the use case.
Clone the repository:
git clone https://github.com/yakov-el/rag-project.git
cd rag-project
Create and activate a Python virtual environment:
bash
Copy
Edit
python -m venv env
On Windows:
bash
Copy
Edit
.\env\Scripts\activate
On Linux/Mac:
bash
Copy
Edit
source env/bin/activate
Install dependencies:
bash
Copy
Edit
pip install -r requirements.txt
Set your OpenAI API key as an environment variable (optional), or pass it directly when making search requests.
โ๏ธ Running the Application
Launch the FastAPI server:
bash
Copy
Edit
uvicorn main:app --reload
Visit: http://localhost:8000
๐ Usage
Upload Files
Send a POST request to /upload with .xlsx or .docx files.
The system will:
Load the documents
Chunk their content (large โ small)
Embed each chunk
Index them in FAISS
Search Query
Send a GET request to /search:
bash
Copy
Edit
/search?q=your_question&apikey=your_openai_api_key
Example:
perl
Copy
Edit
http://localhost:8000/search?q=What%20is%20the%20purpose%20of%20the%20home%20test?&apikey=sk-...
The system will return:
The most relevant chunks
Reranked results
A final answer generated by GPT-4o
๐๏ธ Architecture Overview
sql
Copy
Edit
+--------------------+
| Upload Excel/Word |
+--------------------+
โ
+----------------------------+
| Chunking (HybridChunker) |
+----------------------------+
โ
+----------------------------+
| Embedding (E5 model) |
+----------------------------+
โ
+----------------------------+
| FAISS Vector Store |
+----------------------------+
โ
+----------------------------+
| Query Embedding |
+----------------------------+
โ
+----------------------------+
| Retrieve Top-k Neighbors |
+----------------------------+
โ
+----------------------------+
| Re-Rank (Cross Encoder) |
+----------------------------+
โ
+----------------------------+
| Answer with GPT-4o |
+----------------------------+
๐ Notes
The system supports both English and Hebrew content
Your OpenAI API key should be kept private
Image-to-text alignment is implemented, but images are not embedded or passed to GPT-4o
You can extend the system to support additional file formats or search strategies
๐ซ Contact
Feel free to fork, star, or open issues on the GitHub repo.
5 commits
Python
73.5%
JavaScript
14.6%
HTML
11.9%