RAG / RetrievalAI ENGINEERING · SOURCE PROJECT
Menu ☰
Open-source Python engineering · 2026

Multi-tenant RAG.
Retrieval by design.

Explore a tenant-aware retrieval service built with Python, FastAPI, Qdrant and Sentence Transformers. It combines vector embeddings, semantic caching, contextual filtering and an API interface into a reproducible engineering demonstration.

Focus: retrieval, tenant boundaries and API behavior. Responses are knowledge-base excerpts, not LLM-generated text.

2Sample tenants in the demo
BGE-smallSentence Transformer embeddings
4Documented API routes
CPU + GPUCPU default; CUDA optional

01 / Capabilities

Inside the retrieval stack.

The repository combines model-backed vector search, tenant-context handling, defensive examples and observability into a cohesive Python workflow.

Six implementation areas
01 / VECTOR SEARCH

Semantic embeddings

Encode text with BAAI/bge-small-en-v1.5 through Sentence Transformers; query a Qdrant collection using cosine similarity to retrieve relevant passages.

02 / TENANCY

Tenant-filtered retrieval

Attach a tenant_id payload filter to vector search so the example knowledge bases for tenant_a and tenant_b remain separated by retrieval context.

03 / CACHING

Semantic caching + TTL

Reuse similar results based on cosine similarity while distinguishing tenants, sessions and top_k; the cache is process-local and expires records by time.

04 / API

FastAPI interface

Expose a local query endpoint with bearer-token checks, health status, tenant cache statistics and optional protected metrics. Request throttling is included as a demo control.

05 / SAFEGUARDS

Input handling patterns

Explore regex-based PII redaction and heuristic prompt-injection flags. These are intentionally limited examples, not complete security defenses.

06 / DEVELOPER WORKFLOW

Diagnostics + notebooks

Run dependency diagnostics, offline self-tests, real retrieval demos and a Jupyter notebook walkthrough. CPU mode works without a CUDA GPU.

02 / System architecture

From query to evidence.

A conceptual view of the request path, based on the repository README. The semantic cache can return a prior result before a new vector search.

Tenant-scoped retrieval
01Client request

Query + bearer token

02Authentication

Resolve tenant context

03Input checks

PII patterns + heuristics

04Semantic cache

Tenant, session, TTL

05Embeddings

BGE-small-en-v1.5

06Qdrant retrieval

Cosine + tenant filter

07Evidence response

Excerpts and sources

Retrieval, not generation: the current implementation returns matching knowledge-base excerpts. It does not call a generative language model to compose final answers. Example records are fictional and intended for demonstrations.

03 / Engineering details

Built for reproducible exploration.

The workflow separates retrieval behavior, simple defenses and operational instrumentation so each can be inspected directly in code.

Retrieval and isolation

Core algorithmic and data-layer ideas in the repository.

  • Vector representation with BAAI/bge-small-en-v1.5
  • Qdrant payload conditions based on tenant_id
  • Cosine-similarity nearest-neighbor passage search
  • Tenant and session scope in the process-memory cache
  • Cache expiration using a time-to-live policy
  • Optional local Qdrant persistence through QDRANT_PATH

API and observability

Operational concepts for local experimentation.

  • FastAPI routes for query, health and cache statistics
  • Per-tenant bearer tokens read from environment variables
  • Client-IP rate limiting in the demonstration
  • Request count, error, latency and cache-hit metrics
  • Optional process-memory metrics
  • Offline checks of isolation, caching and validation behavior

04 / REST interface

Four documented API routes.

Local development endpoints described in the README. API mode binds to loopback by default; keep tokens private and do not expose it publicly without security hardening.

FastAPI endpoint reference
MethodRouteAccessPurpose
GET/healthPublicBasic service health status
POST/v1/queryTenant bearer tokenTenant-scoped vector retrieval and excerpts
GET/v1/cache/statsTenant bearer tokenCache statistics for the authorized tenant
GET/v1/metricsOptional admin tokenRuntime metrics, when an admin token is set

05 / Getting started

Run it locally.

Clone the repository, install dependencies, check the environment, and run either an offline test or the model-backed demonstration. The first real demo downloads embedding model weights.

Windows PowerShell
POWERSHELL / LOCAL SETUP
git clone https://github.com/su394611-del/RAG-service.git
cd RAG-service

py -3.12 -m venv .venv-rag
.\.venv-rag\Scripts\python.exe -m pip install -U pip
.\.venv-rag\Scripts\python.exe -m pip install -r requirements.txt

# Inspect installed packages; no model download
.\.venv-rag\Scripts\python.exe RAG_Service_Corrected_2026_Diagnostics.py --doctor

# Exercise offline validation checks
.\.venv-rag\Scripts\python.exe RAG_Service_Corrected_2026_Diagnostics.py --self-test

# Load embeddings and run tenant-scoped queries
.\.venv-rag\Scripts\python.exe RAG_Service_Corrected_2026_Diagnostics.py --demo

06 / Execution modes

Choose your workflow.

The recommended diagnostics implementation provides four command-line entry points.

--doctor

Dependency checks and optional GPU diagnostics.

--self-test

Offline exercises with mock embeddings and no model download.

--demo

BGE/Qdrant retrieval over two fictional tenant knowledge bases.

--api

Local FastAPI interface using environment-provided access tokens.

07 / Source and documentation

Inspect the implementation.

Open the code, notebook, dependencies and documentation. Source artifacts are maintained in the public repository.

08 / Common questions

Questions before running.

Does this application generate LLM responses?

No. The currently documented response path returns knowledge-base excerpts, using embeddings to find relevant passages. The name describes a RAG-oriented retrieval component, not a full generative pipeline.

Do I need a GPU?

No. The embedding model and retrieval can run on CPU. A compatible CUDA-enabled NVIDIA GPU and PyTorch installation are optional for embeddings.

How are the two sample tenants separated?

Qdrant payload filters select records for the authorized tenant context. Cache entries are also scoped by tenant and session. These examples should not be treated as formal production security validation.

Does it connect to a production data source?

The included demonstration uses fictional subscription and product documents. They do not represent verified information about a real company, and the metrics are local demo observations rather than measured production benchmarks.