Skip to content

Repository files navigation

SecAI

A fully local AI assistant with Retrieval-Augmented Generation (RAG), document chat, and streaming responses powered by Ollama, ChromaDB, FastAPI, React, and Docker.

PythonFastAPIReactDocker


Overview

SecAI is a privacy-first local AI assistant that runs entirely on your own machine.

Developed as an internship project at Necurity Solutions, the goal of SecAI is to demonstrate how a production-style Retrieval-Augmented Generation (RAG) system can be built using open-source technologies while keeping all data and AI inference local.

No cloud APIs.

No subscription fees.

No external data sharing.

Users can upload their own documents, ask questions about them, and receive answers with source citations generated from the actual content of those documents.


Features

General AI Chat

  • Local conversational AI using Mistral via Ollama
  • Real-time streaming responses using Server-Sent Events (SSE)
  • Persistent chat history
  • Multiple chat threads

RAG Document Assistant

  • Upload personal documents
  • Semantic search using embeddings
  • Context-aware responses
  • Source citations included in answers
  • Per-user document isolation

Supported File Types

  • PDF
  • DOCX
  • XLSX
  • TXT
  • CSV

Authentication & Security

  • JWT Authentication
  • Password hashing
  • Redis-based token revocation
  • User-level document isolation

Fully Local Deployment

  • No OpenAI API
  • No cloud vector database
  • No external AI services
  • All data remains on your machine

Architecture

Browser
│
▼
Nginx
│
├── React Frontend
│
└── FastAPI Backend
│
├── PostgreSQL
├── Redis
├── ChromaDB
└── Ollama (Host Machine)

Tech Stack

Frontend

  • React
  • Vite
  • Tailwind CSS
  • Axios

Backend

  • FastAPI
  • SQLAlchemy
  • Alembic
  • Pydantic

AI & RAG

  • Ollama
  • Mistral
  • LangChain
  • ChromaDB
  • Sentence Transformers
  • all-MiniLM-L6-v2

Infrastructure

  • Docker
  • Docker Compose
  • Nginx
  • PostgreSQL
  • Redis

Project Structure

secai/
│
├── backend/
│ ├── app/
│ │ ├── core/
│ │ ├── models/
│ │ ├── schemas/
│ │ ├── services/
│ │ ├── routers/
│ │ └── utils/
│ │
│ ├── alembic/
│ ├── requirements.txt
│ └── Dockerfile
│
├── frontend/
│ ├── src/
│ ├── public/
│ ├── Dockerfile
│ └── package.json
│
├── nginx/
├── uploads/
├── docker-compose.yml
├── .env.example
└── README.md

Core Workflow

Document Ingestion Pipeline

Upload File
│
▼
Text Extraction
│
▼
Chunking
│
▼
Embedding Generation
│
▼
ChromaDB Storage

RAG Query Pipeline

User Question
│
▼
Generate Query Embedding
│
▼
ChromaDB Similarity Search
│
▼
Retrieve Relevant Chunks
│
▼
Build Context
│
▼
Mistral via Ollama
│
▼
Stream Response + Citations

Supported Document Processing

File TypeProcessing Library
PDFpdfplumber
DOCXpython-docx
XLSXopenpyxl
TXTNative Reader
CSVPython csv

Getting Started

Prerequisites

Install the following:

  • Docker Desktop
  • Git
  • Ollama

Install Ollama

Linux / macOS

curl -fsSL https://ollama.ai/install.sh | sh

Windows

Download and install from:

https://ollama.com

Pull the default model:

ollama pull mistral

Verify installation:

ollama run mistral

Clone Repository

git clone https://github.com/YOUR_USERNAME/secai.git
cd secai

Configuration

A complete .env.example file is included in the repository.

Copy it to .env and adjust values if required for your environment.


Run the Project

Build and start all services:

docker compose up --build

Services

ServicePort
Frontend80
FastAPI Backend8000
PostgreSQL5432
Redis6379
ChromaDB8000
Ollama11434

API Overview

Authentication

POST /api/auth/registerPOST /api/auth/loginPOST /api/auth/logoutGET /api/auth/me

Documents

POST /api/files/uploadGET /api/filesGET /api/files/{id}/statusDELETE /api/files/{id}

Chat

POST /api/chat/threadsGET /api/chat/threadsDELETE /api/chat/threads/{id}GET /api/chat/threads/{id}/messagesGET /api/chat/threads/{id}/stream

Security Design

Each user receives an isolated ChromaDB collection:

user_{user_id}

Every document and chat operation is ownership-validated before access is granted.

This ensures users cannot access another user's documents, embeddings, or chat history.


Performance Targets

MetricTarget
First Token Latency< 5 seconds
API Response Time< 200 ms
10 Page PDF Processing< 30 seconds
Maximum Upload Size50 MB

Future Improvements

  • Hybrid search combining vector and keyword retrieval
  • Conversation memory
  • OCR support for scanned PDFs
  • Document summarization
  • Knowledge graph integration
  • Local model switching
  • GPU acceleration options
  • Advanced citation ranking
  • Multi-document retrieval optimization

Acknowledgements

This project was developed as part of an internship at Necurity Solutions Network Security Private Ltd.

The project explores modern AI application architecture including local LLM deployment, Retrieval-Augmented Generation, vector databases, semantic search, document processing, and real-time streaming systems.


Author

Subash Venkat

About

SecAI is a fully local AI assistant with Retrieval-Augmented Generation (RAG), built using FastAPI, React, PostgreSQL, ChromaDB, Ollama, and Docker. Upload documents, chat with a local LLM, and get cited answers from your own files. Privacy-first, no cloud APIs, no external dependencies, and fully self-hosted.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages