02 · AI Engineering / Retrieval Evaluation
SecureBank-AI — Securing a RAG platform with RBAC and JWT
A hybrid RAG platform combining JWT authentication and RBAC access control with a reproducible comparison of BM25, vector search, Reciprocal Rank Fusion and reranking.
- Synthetic documents
- 30
- Evaluation questions
- 40
- Indexed chunks
- 172
Engineering question
How can we design and evaluate a relevant RAG system while integrating it into a reliable application with controlled access?
Application security
Application Security & Access Control
SecureBank-AI goes beyond comparing document retrieval engines. The project also includes an application-security layer for user identity, feature access and authentication data.
This complements the AI Engineering work: a RAG system must fit into a structured application with protected RAG APIs, controlled sessions and explicit authorization.
- 01
Authentication & authorization
JWT · RBAC · Protected RAG APIs
JWT validation checks signature, expiry, issuer and audience before identifying the user. Explicit FastAPI role dependencies then authorize access to RAG resources: authentication establishes identity, while authorization determines the permitted action. The environment-configured demo account uses the analyst role.
- 02
Credentials & sessions
bcrypt · HttpOnly cookie · CSRF
Passwords are hashed with bcrypt. Session and CSRF tokens are generated separately; session tokens are stored as hashes in SQLite, expire and are invalidated on logout. The session cookie is HttpOnly; SESSION_COOKIE_SECURE and SESSION_COOKIE_SAMESITE configure its transport policy. The frontend sends cookies with credentials: "include" and supplies the CSRF token for mutable requests.
- 03
API protection & configuration
Trusted origins · Environment variables · Secrets
Login origins are checked against the configured allowlist, and cookie-authenticated mutable requests require CSRF validation. Failed logins are rate-limited. AUTH_TRUSTED_ORIGINS, JWT_SECRET_KEY and DEMO_USER_PASSWORD keep deployment-sensitive configuration outside the public interface; no secret value is exposed here.
- 04
User management & persistence
SQLite · User repository · Role association
SQLiteUserRepository persists accounts, password hashes, activation state and role associations. At startup, an optional demo account is initialized idempotently from environment configuration with the analyst role, without replacing an existing account.
- User requestIdentity and credentials
- AuthenticationJWT validation or cookie session
- AuthorizationRBAC and role dependency
- Protected resourcesRAG and PII APIs
AI Engineering
Hybrid RAG, retrieval strategies, benchmarking and relevance evaluation.
Software Engineering
FastAPI, React, TypeScript, REST APIs, persistence, testing and deployment.
Application Security
JWT authentication, RBAC, password hashing, session management and access control.
SecureBank-AI combines RAG experimentation with a full-stack architecture that includes authentication, authorization and user-management mechanisms.
The answer starts upstream
A language model can only ground its response in the context it receives. If retrieval misses the relevant passage, ranks weak evidence too highly or returns redundant sources, generation begins with an information deficit.
SecureBank-AI treats retrieval as an observable engineering subsystem. Four alternative engines run against one experimental protocol so lexical, semantic, hybrid and reranked behavior can be compared rather than assumed.
Retrieval architecture
Documents are split into chunks, indexed for lexical and vector search, then queried through one of four evaluation configurations. RRF combines rankings; FlashRank is an optional reranking stage for the fourth configuration only.
Alternative configurations
- 01
BM25
A lexical baseline that scores passages from term relevance.
- 02
Qdrant
Semantic vector search using paraphrase-multilingual-MiniLM-L12-v2 embeddings.
- 03
RRF
Reciprocal Rank Fusion combines the independent BM25 and Qdrant rankings.
- 04
RRF + FlashRank
FlashRank reranks the hybrid candidate set as a separate experimental configuration.
Evaluation methodology
RAG v2: one corpus, four configurations
The benchmark uses 30 synthetic documents, 40 questions and 172 indexed chunks. Qwen judges 260 question-document pairs to construct experimental relevance annotations; 38 of 40 questions have at least one document judged relevant.
The same benchmark exposes ranking quality, retrieval success, source and evidence coverage, diversity, latency and errors across all four engines. Results are descriptive observations for this corpus and configuration.
LLM-generated relevance judgments are experimental annotations, not systematic human validation.
- RAG v2
- 30 documents
- 40 questions
- 172 chunks
- 4 strategies
- 260 judged pairs
- 38/40 with relevant evidence
Results
RRF is the strongest overall configuration on this benchmark
RRF leads the observed ranking and retrieval metrics while keeping average latency near 15 ms. This is a benchmark result, not an artificial aggregate score or a production guarantee.
Success@3 89.5%
- Precision@1
- 65.8%
- Recall@3
- 69.8%
- MAP@3
- 61.1%
- MRR@3
- 76.3%
- nDCG@3
- 64.3%
- Average latency
- 15.0 ms
| Metric | BM25 | Qdrant | RRF | RRF + FlashRank |
|---|---|---|---|---|
| Precision@1 | 52.6% | 63.2% | 65.8% — Best observed value | 52.6% |
| Recall@3 | 58.9% | 63.0% | 69.8% — Best observed value | 60.6% |
| MAP@3 | 50.5% | 56.4% | 61.1% — Best observed value | 50.9% |
| MRR@3 | 64.9% | 72.4% | 76.3% — Best observed value | 66.7% |
| nDCG@3 | 56.4% | 56.1% | 64.3% — Best observed value | 55.0% |
| Success@3 | 78.9% | 81.6% | 89.5% — Best observed value | 84.2% |
| Source Hit@3 | 89.5% — Best observed value | 86.8% | 89.5% — Best observed value | 89.5% — Best observed value |
| Evidence Hit@3 | 78.9% | 81.6% | 89.5% — Best observed value | 84.2% |
| Average latency | 0.4 ms — Best observed value | 14.0 ms | 15.0 ms | 421.6 ms |
| P95 latency | 0.7 ms — Best observed value | 18.3 ms | 17.2 ms | 541.9 ms |
View all 22 indicators
| Metric | BM25 | Qdrant | RRF | RRF + FlashRank |
|---|---|---|---|---|
| Precision@1 | 52.6% | 63.2% | 65.8% — Best observed value | 52.6% |
| Precision@3 | 42.1% | 46.5% | 50.0% — Best observed value | 42.1% |
| Recall@1 | 27.3% | 30.8% | 31.2% — Best observed value | 26.8% |
| Recall@3 | 58.9% | 63.0% | 69.8% — Best observed value | 60.6% |
| F1@1 | 34.2% | 39.9% | 40.7% — Best observed value | 33.6% |
| F1@3 | 46.9% | 51.3% | 55.4% — Best observed value | 46.8% |
| MAP@3 | 50.5% | 56.4% | 61.1% — Best observed value | 50.9% |
| Success@1 | 52.6% | 63.2% | 65.8% — Best observed value | 52.6% |
| Success@3 | 78.9% | 81.6% | 89.5% — Best observed value | 84.2% |
| Source Hit@1 | 71.1% | 71.1% | 78.9% — Best observed value | 63.2% |
| Source Hit@3 | 89.5% — Best observed value | 86.8% | 89.5% — Best observed value | 89.5% — Best observed value |
| Evidence Hit@1 | 52.6% | 63.2% | 65.8% — Best observed value | 52.6% |
| Evidence Hit@3 | 78.9% | 81.6% | 89.5% — Best observed value | 84.2% |
| MRR@3 | 64.9% | 72.4% | 76.3% — Best observed value | 66.7% |
| nDCG@3 | 56.4% | 56.1% | 64.3% — Best observed value | 55.0% |
| Average latency | 0.4 ms — Best observed value | 14.0 ms | 15.0 ms | 421.6 ms |
| P50 latency | 0.4 ms — Best observed value | 13.0 ms | 15.6 ms | 422.7 ms |
| P95 latency | 0.7 ms — Best observed value | 18.3 ms | 17.2 ms | 541.9 ms |
| Error rate | 0% — Best observed value | 0% — Best observed value | 0% — Best observed value | 0% — Best observed value |
| Average returned chunks | 3 | 3 | 3 | 3 |
| Distinct documents@3 | 2.37 | 2.29 | 2.21 | 2.45 — Best observed value |
| Source diversity@3 | 78.9% | 76.3% | 73.7% | 81.6% — Best observed value |
Engineering trade-offs
Reranking was not automatically beneficial
Against RRF, FlashRank reduced MAP@3 from 61.1% to 50.9%, nDCG@3 from 64.3% to 55.0% and Success@3 from 89.5% to 84.2%. Average latency rose from 15.0 ms to 421.6 ms—about 28×. This observed trade-off is specific to the target corpus, benchmark and configuration.
BM25 remains a useful baseline
BM25 reached 89.5% Source Hit@3 at 0.4 ms average latency. Lexical retrieval remains a credible low-latency option; vector retrieval is not inherently superior.
Hybrid retrieval earned its place
MAP@3 progressed from 50.5% for BM25 and 56.4% for Qdrant to 61.1% for RRF. The observation supports evaluating lexical, semantic and hybrid approaches instead of selecting an engine on assumptions.
Full-stack implementation
The evaluation framework is part of a complete web application, with explicit boundaries between retrieval services, product interface, deployment and quality controls.
Backend
- Python
- FastAPI
- REST API
- SQLite
Frontend
- React
- TypeScript
- Vite
- Analytical dashboard
- Multilingual interface
- Error and loading-state handling
Deployment
- Docker
- Render backend
- Vercel frontend
- Environment-based configuration
- API routing and proxy configuration
Quality
- Pytest
- Vitest
- ESLint
- Ruff
- Automated and regression testing
Benchmark dashboard
The dashboard makes retrieval evaluation inspectable rather than hiding it behind a chat interface.
Reference snapshots keep the analytical view usable when the backend is unavailable. They are resilience artifacts, not live measurements.
- Four-engine comparison
- 22 evaluation indicators
- Benchmark execution history
- Evaluation provenance
- Missing-value handling
- Reference snapshots




Methodology and limitations
- The benchmark uses synthetic documents.
- Qwen-generated relevance judgments are not equivalent to systematic human review.
- The results describe this experimental benchmark, not real banking production performance.
- The application is not a regulated banking system and makes no compliance claim.
- The project uses pretrained models; it does not train a foundation model from scratch.
- Availability of RAG features in a public deployment depends on backend configuration.
Possible next experiments
These are future directions, not implemented features.
- Agentic RAG
- Controlled tool calling
- Generated-answer evaluation
- AI observability
- Automated benchmarking
- Improved deployment of RAG components
Design → Experiment → Measure → Compare → Improve
SecureBank-AI turns retrieval choices into testable engineering decisions. The benchmark does not certify a banking product; it creates the evidence needed to choose, challenge and improve a RAG configuration.