-
Step 1 of 7Edge case
Get the text out of the PDF
PyMuPDF reads the text first because it handles Bengali script and complex layouts well. If that fails, PyPDF2 tries next, and scanned pages go through Tesseract OCR with Bengali and English language packs.
-
Step 2 of 7Ingest
Split on sentence boundaries
Text is cut into 500-character chunks with a 50-character overlap, without breaking sentences. NLTK finds English sentence ends and BNLP finds Bengali ones.
-
Step 3 of 7Ingest
Embed and store
Each chunk is embedded with paraphrase-multilingual-MiniLM-L12-v2, which puts Bengali and English text in the same vector space. ChromaDB stores the vectors on disk with an HNSW index.
-
Step 4 of 7Query
Ask in either language
A question arrives through the FastAPI service. The pipeline keeps up to 10 chat turns in short-term memory and adds the last few to the prompt, so follow-up questions make sense.
-
Step 5 of 7Query
Find the closest passages
The question is embedded with the same model, and ChromaDB returns the 5 most similar chunks by cosine similarity. A Bengali question can match an English passage, and the other way round.
-
Step 6 of 7Generate
Answer from the passages
The retrieved chunks and the question go to the LLM (an OpenAI model, set in config), which answers from that context. The answer comes back with the passages it used.
-
Step 7 of 7Quality
Measure, secure and monitor
An evaluation module scores each answer for groundedness and relevance. The production API adds JWT and API-key auth, rate limiting, Redis caching and Prometheus metrics, and it all runs in Docker behind nginx.
Tip: the ← and → keys work too.