The ONGC Enterprise AI Knowledge Copilot is a state-of-the-art Retrieval-Augmented Generation (RAG) system built to help ONGC personnel securely interact with massive enterprise documents. It allows users to upload, manage, and query a variety of complex documents, providing highly accurate, cited answers powered by Large Language Models.
For enterprise environments like ONGC, data sensitivity is paramount. Uploading proprietary engineering diagrams, confidential exploration reports, and internal policy documents to public AI models like ChatGPT exposes the organization to severe data privacy risks and potential compliance breaches.
This Knowledge Copilot is designed specifically to solve this problem:
- 100% Data Privacy & Security: Your documents never leave the organization. The entire pipeline—from document parsing to the Large Language Model (powered locally via Ollama)—runs entirely on internal infrastructure. It can even be deployed in air-gapped environments with no internet access.
- Zero Data Training Exposure: Unlike public models that may use your prompts to train future iterations, your sensitive queries and uploaded data remain completely private and isolated.
- Eliminates Hallucinations: Standard LLMs often guess or make up facts when they don't know the answer. This system uses strict Retrieval-Augmented Generation (RAG). It only answers based on the exact documents you upload. If the answer isn't in your documents, the system will explicitly state that it doesn't know, rather than guessing.
- Verifiable Citations: Every single answer generated by the Copilot includes a direct citation to the source file, allowing engineers and analysts to immediately verify the information against the original document.
In large enterprises like ONGC, institutional knowledge is often locked within massive 500-1000+ page PDF reports, engineering manuals, spreadsheets, and scanned documents. Finding specific information is time-consuming and inefficient. The Knowledge Copilot solves this by ingesting these massive documents, breaking them down into semantic chunks, and utilizing AI to answer natural language questions directly based on the uploaded knowledge base.
- Enterprise Document Ingestion Pipeline: A highly advanced, memory-efficient, streaming architecture capable of processing 1000+ page PDFs incrementally without crashing or causing memory bloat.
- Intelligent Mixed Content Parsing:
- Extracts raw digital text directly using PyMuPDF.
- Automatically detects scanned pages and falls back to OCR (using Tesseract & OpenCV).
- Actively detects embedded images within PDFs, extracts them, runs OCR, and injects the text back into the context.
- Extracts complex tables using
pdfplumberand structures them into highly readable key-value pairs so the AI can understand tabular data.
- Fault-Tolerant Processing: If a single page in a massive document is corrupted, the system logs the error and continues processing the rest of the document seamlessly.
- Rich Document Metadata: Extracts and tags documents with metadata (Domain, Department, Document Type) to enable highly filtered and precise semantic searches.
- Document Management UI: Drag-and-drop multiple files at once. A dynamic sidebar lists all active documents in the knowledge base, allowing for easy one-click removal and instant index syncing.
- Conversational Memory: The chat interface remembers the context of the conversation, allowing for natural follow-up questions.
- Multi-Format Support: Natively processes PDFs, DOCX, Excel spreadsheets, raw Images (PNG/JPG), and Public GitHub Repositories (clones and indexes source code).
- Premium ONGC-Branded Interface: A modern, sleek Next.js App Router frontend customized with ONGC's deep maroon and gold brand colors, utilizing glassmorphism and micro-animations for a premium feel.
graph TD
%% Frontend Layer
subgraph UI ["Frontend (Next.js / React)"]
Chat["Chat Interface"]
Upload["Document Upload / Management"]
end
%% Backend API Layer
subgraph Backend ["Backend API (FastAPI)"]
API["FastAPI App (app.main:app)"]
ChatRouter["Chat Route"]
DocRouter["Documents / Upload Route"]
GitRouter["GitHub Route"]
end
%% Processing Services
subgraph Ingestion ["Ingestion & Parsing Services"]
IngestService["Ingestion Service"]
PDFLoader["PDF Loader (PyMuPDF / pdfplumber)"]
DocxLoader["DOCX Loader"]
ExcelLoader["Excel Loader"]
GitLoader["GitHub Loader"]
OCR["OCR Service (Tesseract & OpenCV)"]
end
%% Vector Store & Storage
subgraph Storage ["Storage & Vector DB"]
Chroma["ChromaDB Vector Store (Local)"]
UploadsDir["Local File Uploads (/data/uploads)"]
end
%% RAG & AI Execution
subgraph AI ["Local AI Engines & Models (Ollama)"]
EmbedModel["nomic-embed-text"]
LLMModel["llama3.2:3b"]
end
subgraph Retrieval ["RAG Retrieval & Generation"]
RAGChain["RAG Chain (LangChain)"]
Ensemble["Ensemble Retriever"]
BM25["BM25 Search"]
VectorRetriever["Vector MMR Search"]
Memory["Conversational Memory"]
end
%% Connections
Chat -->|1. Natural Language Query| ChatRouter
Upload -->|Upload Files| DocRouter
Upload -->|Submit Repo URL| GitRouter
ChatRouter --> RAGChain
DocRouter --> Ingestion
GitRouter --> Ingestion
IngestService --> PDFLoader
IngestService --> DocxLoader
IngestService --> ExcelLoader
IngestService --> GitLoader
PDFLoader -->|Scanned Pages| OCR
OCR --> IngestService
IngestService -->|2. Generate Embeddings| EmbedModel
EmbedModel -->|3. Save Vectors| Chroma
IngestService -->|Store original files| UploadsDir
RAGChain --> Ensemble
Ensemble --> BM25
Ensemble --> VectorRetriever
VectorRetriever -->|4. Search| Chroma
Ensemble -->|5. Context Chunks| RAGChain
Memory -->|6. Load Chat History| RAGChain
RAGChain -->|7. Structured Prompt| LLMModel
LLMModel -->|8. Generated Grounded Answer| RAGChain
RAGChain -->|9. Response + Citations| ChatRouter
ChatRouter -->|10. Stream / Return Answer| Chat
- Upload & Intake: Users upload documents (PDF, DOCX, Excel, Images) via drag-and-drop or provide a public GitHub repository URL.
- Specialized Loaders: Files are routed to specific loaders. For massive PDFs, pages are streamed one-by-one to prevent memory overload. GitHub repositories are cloned, and relevant code files (Python, TS/JS, Go, Java, etc.) are extracted.
- Intelligent Chunking: Text and code are broken down into semantic chunks. Code files utilize language-specific splitters to respect function and class boundaries.
- OCR & Data Extraction: For scanned pages and images, Tesseract-OCR and OpenCV are used. Tables are parsed and converted to key-value pairs.
- Embedding & Storage: Chunks are embedded using a local embedding model (e.g.,
nomic-embed-text) and stored in a persistent ChromaDB vector database along with rich metadata (document ID, filename, repository name, chunk index).
- Querying: The user asks a natural language question in the chat interface.
- Hybrid Search: The question is embedded, and the system performs a search against the vector database (semantic search) and BM25 (keyword search) to retrieve the most relevant chunks across all indexed documents and repositories.
- Contextual Generation: The retrieved chunks and conversation history are combined into a strict prompt. The prompt is sent to a local Large Language Model (e.g.,
llama3.2:3bvia Ollama). - Grounded Answer: The LLM generates a concise, accurate answer strictly constrained to the provided context.
- Citations: The frontend displays the answer alongside direct citations indicating exactly which document, page, or GitHub file the information was sourced from.
Frontend
- Next.js (App Router), React, TypeScript
- Tailwind CSS (Styling), Framer Motion (Animations)
- Lucide React (Icons)
Backend
- Python, FastAPI (REST API)
- LangChain (RAG orchestration, Prompting)
- GitPython (Repository cloning)
AI & Machine Learning
- Ollama (Local model execution)
- LLM:
llama3.2:3b(default for generation) - Embeddings:
nomic-embed-text(default for vectorization)
Database & Storage
- ChromaDB (Persistent local vector database)
Document Processing Engine
- PyMuPDF (
fitz), pdfplumber (PDFs and tables) - OpenCV, Tesseract-OCR (Image processing and OCR)
python-docx,openpyxl(Office documents)
The project is cleanly divided into a frontend and a backend repository:
ONGC-RAGAssistant/
│
├── backend/ # FastAPI & LangChain Backend
│ ├── app/
│ │ ├── api/routes/ # REST API endpoints (chat, upload, documents)
│ │ ├── core/ # Configuration, logging, singleton RAGEngine
│ │ ├── loaders/ # Document loaders (PDF streaming, DOCX, Excel)
│ │ ├── models/ # Pydantic models (Document, Page, Chunk)
│ │ ├── rag/ # RAG logic (Vector store, Embeddings, Splitter, Memory)
│ │ ├── services/ # Orchestration (Ingestion, OCR, Image, Table services)
│ │ └── utils/ # Utilities (Image processing, Metadata extraction)
│ ├── data/chroma/ # Persistent local ChromaDB vector store
│ └── requirements.txt # Python dependencies
│
└── frontend/ # Next.js UI Frontend
├── src/
│ ├── app/ # Next.js App Router & global layouts
│ ├── components/ # React components (Sidebar, ChatInterface)
│ └── services/ # API utilities (api.ts)
├── public/ # Static assets
└── package.json # Node.js dependencies
- Navigate to the backend directory:
cd backend - Create and activate a virtual environment:
python -m venv venvvenv\Scripts\activate(Windows)
- Install dependencies:
pip install -r requirements.txt - Ensure Ollama is running locally with the target model (default:
llama3.2:3b). - Ensure Tesseract-OCR is installed on the system path.
- Start the server:
uvicorn app.main:app --reload- API runs at:
http://127.0.0.1:8000
- API runs at:
- Navigate to the frontend directory:
cd frontend - Install dependencies:
npm install - Start the development server:
npm run dev - Open your browser to:
http://localhost:3000
- Make sure you have Docker and Docker Compose installed and running.
- Copy the environment configuration:
(For macOS/Linux, use
copy .env.example .env
cp .env.example .env) - Build and launch both services:
docker compose up --build -d
- Access the frontend UI at
http://localhost:3000and the backend REST API athttp://localhost:8000. - Check service logs with
docker compose logs -fand stop services withdocker compose down.