Repository navigation
Project Overview
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.
- A static four-document example KB across
tenant_aandtenant_b, with categoriesproduct,billing, andsecurity. - Sentence Transformers model
BAAI/bge-small-en-v1.5to encode documents at startup and questions at request time. - Qdrant collection
rag_demo_kbwith cosine distance; vector search filters payloadtenant_id. -
PIIFilter: regex redaction for US-style phone numbers, emails, SSNs, Luhn-valid payment-card numbers and IPv4 addresses. -
PromptInjectionDetector: regex-based heuristics, not a complete injection defense. -
SemanticCache: exact-or-embedding similarity hits (default threshold 0.98) withintenant_id+session_id+top_k, TTL 3600 seconds, max 1000 entries. -
SystemMonitor: requests, errors, cache hits, blocked attempts, latency, PII detections and optional machine RAM usage. - FastAPI routes with bearer-token tenant resolution, request validation and an illustrative 60/minute per-client-IP rate limit.
- 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_PROMPTand requestmax_tokensexist but are unused by the extractive responder.
| 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 |
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.
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.
Project scope: tenant-filtered extractive retrieval demo. Review Security and Limitations before deployment. This project is licensed under the Apache License, Version 2.0.© 2026 Sudhanshu Shukla · Licensed under the Apache License, Version 2.0.
RAG Service Wiki
Architecture and design
Development and operations
Engineering guidance