Repository navigation
Data Model and Tenant Isolation
RAGRequest(
query="What are the Pro rate limits?",
tenant_id="tenant_a",
session_id=None,
max_tokens=300, # accepted but unused by extractive stub
top_k=3,
)Validation in RAGRequest.__post_init__ enforces query length 1–4000 characters after stripping, nonblank tenant_id, integer top_k between 1 and 20, and integer max_tokens between 1 and 2048.
{
"query": "original user query (not necessarily redacted)",
"response": "Relevant knowledge-base excerpts:\n- ...",
"sources": ["0:product"],
"latency_ms": 12.34,
"cached": false,
"request_id": "random12chars"
}The example numeric latency is illustrative, not a benchmark. sources entries concatenate Qdrant point IDs and category. The answer is not generated by an LLM.
{
"id": 0,
"vector": "normalized BGE-small embedding, dimension inferred at runtime",
"payload": {
"tenant_id": "tenant_a",
"category": "product",
"text": "fictional knowledge-base passage"
}
}The built-in DOCUMENTS list contains four fictional points split between two tenants. Startup embeds all four and upserts into collection rag_demo_kb using cosine similarity.
result = self.client.query_points(
collection_name=COLLECTION,
query=vec,
query_filter=Filter(must=[FieldCondition(
key="tenant_id", match=MatchValue(value=tenant_id))]),
limit=top_k,
with_payload=True,
score_threshold=self.retrieval_min_score,
)API mode determines tenant_id by matching the bearer token to TENANT_A_API_KEY or TENANT_B_API_KEY (configured via environment variables). The client cannot choose a tenant ID in /v1/query JSON. Direct Python calls accept any string tenant ID and do not authenticate a principal.
Entries are only considered when all of the following match: tenant_id, session_id (including None), and top_k. Query text matches exactly or by normalized cosine similarity at/above the threshold. The response and sources are cached together.
This is demo-layer filtering, not proof of end-to-end tenant authorization, auditability, encryption or leakage prevention. 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