yakov-el/rag-project

1

stars

5

commits

Python

primary language

Jul 24, 2025

updated

README

RAG Project โ€“ Retrieval-Augmented Generation for Excel and Word Documents

This project implements a Retrieval-Augmented Generation (RAG) system designed to load and process two types of documents:

  • Excel (.xlsx) files with structured data
  • Word (.docx) files with unstructured text

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.


๐Ÿ” Technical Highlights

  • Embedding model: intfloat/multilingual-e5-large โ€“ for multilingual text embeddings (supports English and Hebrew)
  • Chunking strategy: Two-step process using HybridChunker from docling:
    • First, documents are split into large, semantically coherent paragraph-level chunks
    • Then, each paragraph is further split into smaller sub-chunks, enhancing retrieval resolution
    • This strategy enables the re-ranking model to precisely select the most relevant sub-paragraph, improving answer quality and reducing hallucinations
  • Vector index: FAISS โ€“ efficient approximate nearest neighbor search
  • Re-ranking: Alibaba-NLP/gte-multilingual-reranker-base โ€“ cross-encoder model improves final relevance score and selects the best-matching chunk
  • Answer generation: OpenAI GPT-4o via Chat Completions API โ€“ composes a final answer using top-ranked context
  • API framework: FastAPI โ€“ for robust and async-ready endpoints
  • Image support: Images extracted from Word documents are linked to relevant text chunks (though not used in embeddings or generation)

๐Ÿง  Optional Hybrid Search (Not Implemented)

While not currently included, the system design allows optional hybrid search, combining:

  • Dense vector search (via FAISS)
  • Sparse keyword search (e.g., BM25 via Elasticsearch or 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.


๐Ÿš€ Installation

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.

Contributors

yakov-el

5 commits

yakov-el/rag-project

1

stars

5

commits

Python

primary language

Jul 24, 2025

updated

README

RAG Project โ€“ Retrieval-Augmented Generation for Excel and Word Documents

This project implements a Retrieval-Augmented Generation (RAG) system designed to load and process two types of documents:

  • Excel (.xlsx) files with structured data
  • Word (.docx) files with unstructured text

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.


๐Ÿ” Technical Highlights

  • Embedding model: intfloat/multilingual-e5-large โ€“ for multilingual text embeddings (supports English and Hebrew)
  • Chunking strategy: Two-step process using HybridChunker from docling:
    • First, documents are split into large, semantically coherent paragraph-level chunks
    • Then, each paragraph is further split into smaller sub-chunks, enhancing retrieval resolution
    • This strategy enables the re-ranking model to precisely select the most relevant sub-paragraph, improving answer quality and reducing hallucinations
  • Vector index: FAISS โ€“ efficient approximate nearest neighbor search
  • Re-ranking: Alibaba-NLP/gte-multilingual-reranker-base โ€“ cross-encoder model improves final relevance score and selects the best-matching chunk
  • Answer generation: OpenAI GPT-4o via Chat Completions API โ€“ composes a final answer using top-ranked context
  • API framework: FastAPI โ€“ for robust and async-ready endpoints
  • Image support: Images extracted from Word documents are linked to relevant text chunks (though not used in embeddings or generation)

๐Ÿง  Optional Hybrid Search (Not Implemented)

While not currently included, the system design allows optional hybrid search, combining:

  • Dense vector search (via FAISS)
  • Sparse keyword search (e.g., BM25 via Elasticsearch or 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.


๐Ÿš€ Installation

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.

Contributors

yakov-el

5 commits

Languages

Python

73.5%

JavaScript

14.6%

HTML

11.9%