Ambuj123-lab/indian-legal-ai-expert

GitHub: Ambuj123-lab/indian-legal-ai-expert

面向印度法律领域的企业级 Agentic RAG 平台,通过置信度门控、语义路由和隐私护栏实现可靠的法律问答与检索。

Stars: 2 | Forks: 0

# ⚖️ Agentic Legal AI (置信度门控 HITL) [![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi)](https://fastapi.tiangolo.com) [![React](https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB)](https://reactjs.org) [![LangGraph](https://img.shields.io/badge/LangGraph-Organized-orange?style=for-the-badge)](https://github.com/langchain-ai/langgraph) [![Qdrant](https://img.shields.io/badge/Qdrant-Vector_DB-red?style=for-the-badge&logo=qdrant)](https://qdrant.tech) [![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white)](https://www.docker.com) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT) ## 📺 实时演示 🚀 **[访问专家顾问](https://indian-legal-ai-expert.onrender.com)** ## 🏗️ 技术架构 该系统建立在模块化的**微服务单体架构** (Monolith-over-Microservices) 之上,利用 **LangGraph** 实现确定性的状态控制 RAG 编排。

Animated Architecture

## 🚀 核心工程特性 ### 🧠 强大的 RAG 编排 - **LangGraph 状态机**:使用 4 节点状态图(CLASSIFY → RETRIEVE → GENERATE → POST_PROCESS)进行确定性流控制。 - **父子分块 (Parent-Child Chunking)**:结合 Jina AI embeddings 实现递归字符分割。子块(较小)用于优化向量搜索检索,而父块(提供上下文)为 LLM 提供周边知识以减轻幻觉。 - **置信度门控 HITL 回退**:动态阈值设定(80% 置信度截断值)。当 Vector DB 相似度得分过低时,自动通过 Tavily 触发交互式 Human-in-the-Loop Web Search,有效消除数据库外查询产生的幻觉。 - **双重搜索策略**:混合检索机制,将语义向量搜索与针对特定法律术语(例如 FIR、BNS Sections)的基于关键词的扩展相结合。 ### 🛡️ 隐私与可靠性 - **意图分类护栏**:LangGraph 节点在请求到达 LLM 之前,自主识别 Prompt Injections、时间敏感型问题和超出范围 (OOS) 的查询,并将其重定向到安全的回退路径。 - **PII 遮盖集成**:利用 **Microsoft Presidio + spaCy** 在传输至 LLM 之前检测并匿名化姓名、电话号码和身份数据。 - **断路器模式**:在外部 LLM 调用周围集成 `pybreaker`(fail_max=10),以确保在上游提供商中断期间的系统稳定性。 - **速率限制**:通过 SlowAPI 实现基于 IP 的速率限制(5 req/min),防止 API 滥用并控制运营成本。 ### 🔄 智能同步引擎 - **自动重新索引**:使用 Supabase Storage 和 PostgreSQL 注册表之间的 SHA-256 哈希比较的自定义引擎。 - **孤儿清理**:自动检测并删除从知识库中移除的文件的向量 embeddings。 - **管理仪表板**:实时监控文档状态(已索引、待处理、已删除),并通过 UI 驱动同步触发。 ### ⚡ 性能与可观测性 - **三层缓存**:通过 **Upstash Redis** 实现响应缓存、活跃用户跟踪和流模拟。 - **可观测性**:使用 **Langfuse** 对每个用户意图和 LLM 推理链进行实时追踪。 - **GDPR 合规**:由 MongoDB 支持的聊天记录,配备自动 30 天 TTL 索引,以保护静态数据。 ## 🛠️ 技术栈 - **前端**:React 18, Tailwind CSS (Glassmorphism UI), Lucide Icons - **后端**:FastAPI, Uvicorn, LangChain, LangGraph, Pydantic - **AI 模型**:Qwen 3 235B (通过 OpenRouter), Jina AI Embeddings v2, Tavily Search API - **基础设施**:Docker, Render (计算), Qdrant Cloud (向量存储), MongoDB Atlas (NoSQL), Supabase (Postgres + 对象存储), Upstash (Redis) ## 📂 企业级文件夹结构(后端) 后端采用领域驱动设计 (DDD) 架构,以确保可扩展性、安全性和关注点分离。 ``` backend/ ├── app/ │ ├── auth/ # Authentication, JWT, and Google OAuth │ │ ├── __init__.py │ │ ├── jwt.py │ │ ├── oauth.py │ │ ├── routes.py │ │ └── schemas.py # Auth-specific Pydantic models │ ├── core/ # Application Brain (Logging, Config, Rate Limiting) │ │ ├── __init__.py │ │ ├── config.py │ │ ├── limiter.py │ │ └── logger.py │ ├── db/ # Database Clients (MongoDB, Supabase) │ │ ├── __init__.py │ │ ├── database.py │ │ └── supabase_client.py │ ├── rag/ # Retrieval-Augmented Generation Logic │ │ ├── __init__.py │ │ ├── graph.py # LangGraph State Machine │ │ ├── pipeline.py# Processing, Qdrant, Presidio PII │ │ ├── routes.py # Endpoints for RAG Chat │ │ └── schemas.py # RAG-specific Pydantic models │ ├── utils/ # Generic Helper Functions │ │ ├── __init__.py │ │ └── helpers.py # e.g., calculate_sha256 │ └── main.py # FastAPI Entry Point ├── .env.example # Example Environment Variables ├── requirements.txt # Python Dependencies └── Dockerfile # Multi-stage production build ``` ## 💻 本地开发 1. **克隆仓库**: git clone https://github.com/Ambuj123-lab/indian-legal-ai-expert.git cd indian-legal-ai-expert 2. **后端设置**: cd backend python -m venv venv source venv/bin/activate # 或 venv\Scripts\activate pip install -r requirements.txt 3. **前端设置**: cd frontend npm install 4. **环境变量**: 使用 `.env.example` 作为模板,在根目录下创建一个 `.env` 文件。 ## ⚖️ 免责声明 *本应用是一款由 AI 驱动的教育工具,旨在协助进行法律研究。它不构成法律建议。在处理关键事务时,用户应咨询合格的法律专业人士。* **由 [Ambuj Kumar Tripathi](https://github.com/Ambuj123-lab) 用 ❤️ 构建**
标签:AV绕过, FastAPI, LangGraph, Qdrant, RAG, React, Syscalls, 人工智能, 提示词防御, 搜索引擎查询, 法律科技, 用户模式Hook绕过, 自定义脚本, 请求拦截, 逆向工具