Skip to content

Project Overview

Sudhanshu edited this page Nov 11, 2026 · 1 revision

Project Overview

Problem being demonstrated

Given a text question and an authenticated tenant, retrieve relevant KB passages belonging to that tenant, block simple suspicious prompts, mask certain types of PII, and avoid redundant retrieval using an in-process semantic cache. Expose the functionality through both Python and a local HTTP API.

What is implemented

  1. A static four-document example KB across tenant_a and tenant_b, with categories product, billing, and security.
  2. Sentence Transformers model BAAI/bge-small-en-v1.5 to encode documents at startup and questions at request time.
  3. Qdrant collection rag_demo_kb with cosine distance; vector search filters payload tenant_id.
  4. PIIFilter: regex redaction for US-style phone numbers, emails, SSNs, Luhn-valid payment-card numbers and IPv4 addresses.
  5. PromptInjectionDetector: regex-based heuristics, not a complete injection defense.
  6. SemanticCache: exact-or-embedding similarity hits (default threshold 0.98) within tenant_id + session_id + top_k, TTL 3600 seconds, max 1000 entries.
  7. SystemMonitor: requests, errors, cache hits, blocked attempts, latency, PII detections and optional machine RAM usage.
  8. FastAPI routes with bearer-token tenant resolution, request validation and an illustrative 60/minute per-client-IP rate limit.

Explicitly not implemented

  • No generative model, prompt-template assembly, streamed model tokens or text synthesis.
  • No file-upload/indexing API, file chunker, metadata enrichment or document lifecycle management. KB contents are hard-coded.
  • No distributed cache, central observability, external identity provider, per-tenant billing quotas, encryption policy enforcement, data retention policy or production security audit.
  • SYSTEM_PROMPT and request max_tokens exist but are unused by the extractive responder.

File map

File Purpose Usage
RAG_Service_Corrected_2026_Diagnostics.py Main implementation with diagnostics Recommended CLI: --doctor, --self-test, --demo, --api
RAG_Service_Corrected_2026_Windows.py Windows-oriented implementation --self-test, --demo, --api
rag_fixed_v2.py Earlier core implementation --self-test, --demo, --api
RAG_Service_Corrected_2026_Diagnostics.ipynb Notebook walkthrough for main implementation Select matching Python kernel; optional model demo
requirements_rag_2026.txt Runtime and notebook dependencies pip install -r requirements_rag_2026.txt
docs/wiki/*.md Wiki source Publish to separate .wiki.git remote
docs/diagrams/*.mmd Editable diagram sources Mermaid-compatible preview tooling

Implemented processing order

API authentication / validation (API only) → RAGRequest validation → injection check → query PII redaction → cache lookup → (Qdrant retrieval on miss) → extractive response → output PII masking on miss → cache write → metrics.

Other design considerations

RAGResponse.query contains the original caller query, including any PII (even though sanitized text is used for retrieval). This privacy limitation matters if the API is exposed, responses are logged or the client stores history. See Security-and-Limitations.

Clone this wiki locally