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.
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.
01 / Capabilities
The repository combines model-backed vector search, tenant-context handling, defensive examples and observability into a cohesive Python workflow.
Encode text with BAAI/bge-small-en-v1.5 through Sentence Transformers; query a Qdrant collection using cosine similarity to retrieve relevant passages.
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.
Reuse similar results based on cosine similarity while distinguishing tenants, sessions and top_k; the cache is process-local and expires records by time.
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.
Explore regex-based PII redaction and heuristic prompt-injection flags. These are intentionally limited examples, not complete security defenses.
Run dependency diagnostics, offline self-tests, real retrieval demos and a Jupyter notebook walkthrough. CPU mode works without a CUDA GPU.
02 / System architecture
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.
Query + bearer token
Resolve tenant context
PII patterns + heuristics
Tenant, session, TTL
BGE-small-en-v1.5
Cosine + tenant filter
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
The workflow separates retrieval behavior, simple defenses and operational instrumentation so each can be inspected directly in code.
Core algorithmic and data-layer ideas in the repository.
BAAI/bge-small-en-v1.5tenant_idQDRANT_PATHOperational concepts for local experimentation.
04 / REST interface
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.
| Method | Route | Access | Purpose |
|---|---|---|---|
| GET | /health | Public | Basic service health status |
| POST | /v1/query | Tenant bearer token | Tenant-scoped vector retrieval and excerpts |
| GET | /v1/cache/stats | Tenant bearer token | Cache statistics for the authorized tenant |
| GET | /v1/metrics | Optional admin token | Runtime metrics, when an admin token is set |
05 / Getting started
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.
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 --demo06 / Execution modes
The recommended diagnostics implementation provides four command-line entry points.
--doctorDependency checks and optional GPU diagnostics.
--self-testOffline exercises with mock embeddings and no model download.
--demoBGE/Qdrant retrieval over two fictional tenant knowledge bases.
--apiLocal FastAPI interface using environment-provided access tokens.
07 / Source and documentation
Open the code, notebook, dependencies and documentation. Source artifacts are maintained in the public repository.
08 / Common questions
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.
No. The embedding model and retrieval can run on CPU. A compatible CUDA-enabled NVIDIA GPU and PyTorch installation are optional for embeddings.
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.
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.