How rrpatil-1/qna_rag_doc_management works
Project Type & Purpose
• The project is a full-stack backend system built to support a QnA system with Retrieval-Augmented Generation (RAG). Its main purpose is to answer user questions by retrieving relevant document context (from a PostgreSQL vector database) and processing it using an LLM (via Ollama).
• Key functionalities include document ingestion, document processing, question answering, and listing available documents.
Major System Components
a. Backend Application:
• Contains the main business logic with the core modules organized under various directories:
• db_service – Manages database operations and connections, including SQL and vector database (pgvector) functionality.
• document_process – Handles processing and parsing of PDF documents.
• driver_services – Exposes API endpoints for ingestion, QA, and document listing.
• llm_service – Responsible for interfacing with the Ollama language model; includes a dedicated module for Ollama integration.
• utils – Contains logger, custom exceptions, parameter checks, etc.
b. Database Service:
• PostgreSQL with the pgvector extension is used, as indicated in the docker_compose.yaml.
c. Language Model Service:
• Uses Ollama as the LLM provider. There’s an Ollama-specific Dockerfile and startup script (pull-llama3.sh) to manage the model.
d. Containerization & Deployment:
• Dockerfiles for both backend and Ollama, along with a docker-compose file (in the deployment directory) that ties together the backend, the pgvector database, and the Ollama service on a defined network.
e. API Endpoints & External Interfaces:
• Endpoints include /ollamahealth, /qa_service, /ingest_documents, and /list_documents. These expose the system’s capabilities via REST.
f. Configuration & Environment Variables:
• The .env file provides necessary configurations for connecting to the database and the LLM service.
Interactions and Data Flows
• Incoming API requests (for QA, ingestion, document listing) are routed to the backend’s driver_services modules.
• For document ingestion, files are passed through the document_process modules for parsing (specifically handling PDFs).
• The database service (via db_service) manages storage and retrieval of document embeddings and metadata.
• When a query is received at the /qa_service endpoint, the query is processed by:
• Retrieving relevant document context using vector search against PostgreSQL (with pgvector).
• Sending the context to the llm_service (specifically the Ollama integration) for language model processing.
• Responses flow back from the database and the language model to the user via the backend API.
Architectural Patterns & Principles
• Modular and Layered Architecture: The code distinguishes separate services (db_service, document_process, driver_services, llm_service). Clearly defined modules ensure that components can be understood, tested, and maintained independently.
• Containerization: The services are containerized using Docker, promoting isolated and consistent deployments. Docker Compose orchestrates the multi-container deployment.
• Service Decoupling: Each service (backend API, database, and LLM) runs in its own container and communicates over a defined network (pg-network), which is a key design principle for scalability and maintenance.