Spaces:
Sleeping
Sleeping
metadata
license: mit
title: ChatQnA RAG Service
sdk: docker
emoji: ⚡
colorFrom: red
colorTo: yellow
RAG Service (Python)
apps/rag-service is now the production Python intelligence engine used by apps/api.
It contains migrated retrieval + LLM routing behavior from the Streamlit reference (app.py).
Run locally
python -m pip install -r requirements.txt
uvicorn app.main:app --reload --port 8002 --app-dir .
API contract
POST /queryaccepts:sessionId,message,history,topK- optional
documentobject (documentName,documentKind,documentText)
- returns:
answerretrievedChunks[]withid,page,chunkType,text- optional span mapping fields:
startOffset,endOffset,sourceDocument,score citations[]aligned to returned chunks
Runtime behavior
- Primary retrieval:
- Uploaded document text (if provided) is chunked and ranked.
- Default mode is
lexicalfor low-memory/free-tier reliability. - Optional mode
semanticusesall-MiniLM-L6-v2embeddings (higher memory).
- Secondary retrieval:
- Qdrant if configured, else FAISS local fallback (
faiss_store/).
- Qdrant if configured, else FAISS local fallback (
- Answer generation:
- HF Router->Groq primary route, Groq fallback.
- Local guarded fallback answer if LLM route is unavailable.
Required/optional env
RAG_SERVICE_URL(set in API, points to this service)- Optional:
QDRANT_URL,QDRANT_API_KEY,QDRANT_COLLECTIONKB_BACKEND(qdrantorfaiss)RAG_RETRIEVAL_MODE(lexicalorsemantic, defaultlexical)HUGGINGFACE_API_TOKEN,GROQ_API_KEYRAG_MODEL_ID,RAG_TEMPERATURE,RAG_MAX_TOKENSUPLOAD_CHUNK_SIZE,UPLOAD_CHUNK_OVERLAP
Deploy on Hugging Face Spaces (free CPU)
- Create a new Space with SDK =
Docker. - Point the Space to
apps/rag-service. - The included
Dockerfileexposes FastAPI on port7860. - Add secrets:
QDRANT_URL,QDRANT_API_KEY,HUGGINGFACE_API_TOKEN,GROQ_API_KEY
- Add variables:
KB_BACKEND=qdrantRAG_RETRIEVAL_MODE=lexicalQDRANT_COLLECTION=doc_kb