Skip to content

Repository files navigation

DocOps Agent

A production-grade agentic Retrieval-Augmented Generation (RAG) system built with FastAPI, LangGraph, pgvector, and Redis. The system features an autonomous self-healing loop that evaluates its own answers for faithfulness, relevance, and confidence, automatically adjusting its search parameters and query structure to correct itself when an answer fails validation.


πŸš€ System Architecture

Here is the real-time agent workflow orchestrated using LangGraph:

LangGraph Self-Healing Agent Loop

Ingestion Pipeline

  1. Parsing & Tokenization: Documents (.pdf, .md, .txt, .py, .js, etc.) are processed, sanitized, and broken down into chunks of 500 tokens (~2,000 characters) with a 50 token overlap.
  2. Embeddings: Real-time vector representations are generated using a locally run, high-efficiency sentence embedding model (sentence-transformers/all-MiniLM-L6-v2) running on CPU-optimized PyTorch.
  3. Indexing: Chunks are stored in a PostgreSQL table backed by an HNSW cosine distance index for sub-millisecond similarity lookups.

Query Routing & Self-Healing Loop

  1. Semantic Caching: Before running the agent, incoming queries are checked against a Redis cache using semantic similarity. If a similar question (score $\ge 0.95$) was answered recently, the response is served instantly ($< 200\text{ms}$).
  2. Retrieve Node: Performs vector or hybrid searches across the index to fetch relevant chunks.
  3. Reason Node: Synthesizes a candidate answer based only on retrieved context, appending cited source mappings.
  4. Verify Node: Evaluates the response:
    • Faithfulness Check: Determines if the generated answer contains hallucinated claims unsupported by the context.
    • Relevance Check: Determines if the answer actually answers the user's question.
    • Confidence Rating: The LLM scores its own confidence from 1 to 10.
  5. Healing Routing:
    • If all checks pass (relevance is high, faithful, confidence $\ge 7/10$), the answer is cached and returned.
    • If any check fails and retry_count $< 2$: the agent rephrases the query, switches the retrieval strategy to Hybrid Reciprocal Rank Fusion (RRF), increases retrieval top_k to 10, and loops back to Retrieve.
    • If retries are exhausted, it returns the final candidate flagged with a low-confidence badge.

πŸ› οΈ Technology Stack

  • Backend API: FastAPI (Python 3.11+)
  • Orchestration: LangGraph
  • Vector Database: PostgreSQL 16 + pgvector extension
  • Caching Layer: Redis (semantic similarity index)
  • Embeddings: sentence-transformers/all-MiniLM-L6-v2 (Local, CPU PyTorch)
  • LLM Inference: Groq API (Primary LPU Llama-3.3-70b/8b), Anthropic API (Reasoning Fallback)
  • Frontend Interface: Next.js (TypeScript/React, Custom Vanilla CSS Glassmorphism)
  • Deployments: Docker & Docker Compose

🏁 Getting Started

1. Configure Secret Environments

Copy the template configuration file:

cp .env.template .env

Open .env and fill in your keys:

  • GROQ_API_KEY: Get a free key from the Groq Console.
  • ANTHROPIC_API_KEY: (Optional fallback).

2. Launch the Application Cluster

To download dependencies, compile static assets, and launch all services in detached (background) mode:

docker-compose up --build -d

Once healthy, services will be accessible at:

3. Ingest Documents (Two Options)

  1. Direct File Upload: Go to the File Ingestion tab in the dashboard sidebar, click Select File, and select any .pdf, .md, .txt, or source code file to upload and index it instantly.
  2. Server Directory Ingestion: Type a folder path (like /app/documents to index pre-mounted files) in the "Folder Absolute Path" input and click Index Folder.

4. Query & Inspect Traces

Ask questions in the chat box. You will see badges displaying verification traces:

  • ⚑ Semantic Cache Hit (<200ms): Answer loaded directly from Redis.
  • βš™οΈ Auto-healed (N retries): Shows that the answer failed verification first-pass and corrected itself.
  • ⚠️ Low Confidence Response: Returned if the context does not contain enough info.

🐳 Common CLI Operations

Stopping the System

docker-compose down

Note: Databases and caches are preserved in Docker volumes, so your indexed documents are safe.

Restarting

docker-compose up -d

Running the Test Suite

Verify security, prompt-injection guardrails, and verification node classification accuracy inside the container:

docker-compose exec -T backend python -m pytest

About

Production-ready agentic self-healing RAG system built with FastAPI, LangGraph, pgvector, and Redis.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages