Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Company RAG Assistant

A lightweight Retrieval-Augmented Generation (RAG) application for company documents. The project lets users upload text-based documents, split them into searchable chunks, store metadata in MySQL, create a FAISS vector index, and ask questions using a local LLM through Ollama.

Overview

This project combines:

  • FastAPI backend for document upload and chat APIs
  • Streamlit frontend for a simple web UI
  • MySQL for document metadata and chunk storage
  • FAISS for vector search
  • Hugging Face embeddings for semantic retrieval
  • Ollama + Llama 3.1 for answer generation

The app is designed around a per-user document workflow, so each user only sees documents and chunks associated with their own user ID.

Project Structure

company_rag/
├── app/
│   ├── database/
│   │   ├── connection.py
│   │   ├── models.py
│   │   └── repository.py
│   ├── generation/
│   │   └── llm.py
│   ├── ingestion/
│   │   ├── cleaner.py
│   │   ├── chunker.py
│   │   ├── embedder.py
│   │   ├── loader.py
│   │   └── __init__.py
│   ├── rag/
│   │   └── pipeline.py
│   ├── retrieval/
│   │   ├── retriever.py
│   │   └── vector_store.py
│   ├── config.py
│   └── main.py
├── frontend/
│   └── app.py
├── data/
│   ├── faiss/
│   └── uploads/
├── .env
├── .gitignore
├── check_env.py
├── create_tables.py
├── requirements.txt
├── README.md
└── venv/

Features

  • Upload .txt, .pdf, and .docx files
  • Clean and chunk document text with page tracking
  • Store documents and chunk metadata in MySQL
  • Build and update a FAISS vector store
  • Search relevant chunks using semantic similarity
  • Generate answers grounded in retrieved document context
  • Expose REST API and simple Streamlit UI

Tech Stack

  • Python
  • FastAPI
  • Streamlit
  • SQLAlchemy
  • PyMySQL
  • FAISS
  • LangChain
  • Hugging Face Embeddings
  • Ollama

Prerequisites

Before running the app, make sure you have:

  • Python installed
  • MySQL server running
  • Ollama installed and running locally
  • The Llama 3.1 model downloaded in Ollama

Install the model with:

ollama pull llama3.1

Environment Setup

Create a .env file in the project root with your MySQL connection details:

DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=company_rag

The app reads these values from .env in the database connection layer.

Installation

  1. Create and activate a virtual environment:
python -m venv venv

On Windows:

venv\Scripts\activate

On macOS/Linux:

source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create the database tables:
python create_tables.py
  1. Optional environment check:
python check_env.py

Running the Application

Start the backend API

uvicorn app.main:app --reload

The API runs by default at:

Start the Streamlit UI

streamlit run frontend/app.py

The user interface is typically available at:

API Endpoints

Health

  • GET /health — checks API status
  • GET / — basic welcome message

Documents

  • POST /documents/upload — uploads a document and ingests it
  • GET /documents — lists all documents for a user
  • GET /documents/{document_id} — fetches one document by ID
  • DELETE /documents/{document_id} — deletes a document

Chat

  • POST /chat — asks a question using the user-specific vector store

Example request body for chat:

{
  "user_id": 1,
  "question": "What is the company's leave policy?"
}

Data Storage

  • Uploaded files are saved under data/uploads/
  • FAISS indexes are saved under data/faiss/
  • MySQL stores user, document, and chunk metadata

Notes

  • This project currently uses a local Ollama LLM and does not include authentication.
  • The vector store is user-aware when retrieving results, but the application assumes the caller passes a valid user_id.
  • Document ingestion may take time on first run because the embedding model and LLM model are downloaded from external sources.

Typical Workflow

  1. Start MySQL and Ollama.
  2. Run the FastAPI backend.
  3. Run the Streamlit frontend.
  4. Upload a document for a specific user ID.
  5. Ask a question in the UI or via the API.
  6. Review the answer and source file references.

License

This project is provided as a starter application for company document Q&A and can be adapted for your own use case.

About

A beginner-friendly RAG project that uses document chunking, embeddings, FAISS vector search, and Ollama to answer questions from custom documents.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages