Back to selected work

PROJECT 01 / AI infrastructure & retrieval

RAG Document Assistant.

From a PDF chatbot to an evaluated AI backend.

An evaluated document intelligence backend with persistent vector retrieval, asynchronous processing, configurable LLM integrations and MCP tooling.

The actual browser interface: upload a PDF, then ask a question grounded in it. The answer is about the AR-CITIZEN paper used as the test document.

RAG Document Assistant web interface: a PDF upload panel and a chat where the question “What is AR-CITIZEN?” receives a streamed answer about an augmented-reality civic interface.

Original, unmodified screenshot · Esc to close · Open full size

The actual browser interface: upload a PDF, then ask a question grounded in it. The answer is about the AR-CITIZEN paper used as the test document.APPLICATION · CLICK TO EXPAND
38evaluation questions
16passing automated tests
5 → 0retrieval truncation cases¹

¹ In one documented 38-question experiment (IVFFlat probes 1 → 10). This measures queries returning fewer than 3 chunks, not whether the retrieved chunks were relevant or answers accurate.

01 / OVERVIEW

A PDF chatbot, taken seriously.

The RAG Document Assistant started as a single-document prototype built on FAISS and Ollama. It grew into a backend with persistent, additive ingestion, an asynchronous request path, deployment and a repeatable evaluation harness.

In the browser, a user uploads PDFs and asks questions with streamed answers. Separately, an MCP stdio server exposes a search_documents tool that reuses the same retrieval and returns chunks directly, with no generation step.

  1. 01

    Prototype

    Single-document chat over a local FAISS index with Ollama.

  2. 02

    Persistence

    Additive ingestion into PostgreSQL with pgvector, so documents accumulate and survive a redeploy.

  3. 03

    Async backend

    FastAPI with async SQLAlchemy and asyncpg; CPU-bound work moved off the event loop.

  4. 04

    Deployment

    Dockerised, with a Render and Neon demo and an AWS EC2 and RDS migration exercise.

  5. 05

    Evaluation

    A 38-question golden set, a CI suite on real PostgreSQL and Langfuse tracing.

A successful upload followed by an “insufficient context” answer. Shown as behaviour, not as accuracy evidence: whether that answer was correct is not established.

The same interface after a successful upload. The question “What does Phase I of AR-CITIZEN target?” is answered with a statement that the provided context does not contain information about Phase I.

Original, unmodified screenshot · Esc to close · Open full size

A successful upload followed by an “insufficient context” answer. Shown as behaviour, not as accuracy evidence: whether that answer was correct is not established.INGESTION · CLICK TO EXPAND

02 / THE PROBLEM

An answer is only the beginning.

A fluent answer to an uploaded PDF makes a convincing demo. It does not show whether the right passage was retrieved, whether the index survives a redeploy, or whether one slow operation is blocking every other request.

I built the Document Assistant to work through those questions. The goal is not to claim perfect answers; it is to make the behaviour inspectable and the failures actionable.

03 / ARCHITECTURE

A small system with clear boundaries.

Ingestion: PDF parsing, then chunking, then fastembed ONNX embeddings, then storage in PostgreSQL with pgvector. Question answering: embed the query, cosine retrieval from pgvector, a relevance guard, then a streamed response from a configurable provider, with the response and a log written. Langfuse records retrieval and generation spans. A separate MCP stdio tool, search_documents, reuses retrieval and returns chunks without generating an answer.

EXPLANATORY ILLUSTRATION · NOT A LIVE UI Langfuse records separate retrieval and generation spans. The MCP search_documents tool reuses retrieval directly and does not pass through the answer-generation guard.

FastAPI orchestrates the request path. Async SQLAlchemy and asyncpg handle the database. Langfuse separates retrieval from generation, so a retrieval problem can be told apart from a model or cold-start problem.

The search_documents MCP tool returning chunks directly, with no generation. Two results look identical but carry different document IDs, consistent with the same file being ingested twice.

MCP Inspector calling the search_documents tool with the query “What is AR-CITIZEN?” and top_k 3. The result is a success with passages from AR_CITIZEN_Paper.pdf, two of which look identical but carry different document IDs.

Original, unmodified screenshot · Esc to close · Open full size

The search_documents MCP tool returning chunks directly, with no generation. Two results look identical but carry different document IDs, consistent with the same file being ingested twice.MCP INSPECTOR · CROPPED VIEW, CLICK FOR FULL IMAGE

The MCP tool shows the same retrieval from another interface. Its results are returned directly, which is also how the duplicate-ingestion issue became visible: two near-identical passages carry different document IDs.

04 / DECISIONS & TRADE-OFFS

The decisions behind the stack.

PostgreSQL and pgvector, rather than a local index.

A local FAISS index does not survive an ephemeral-host redeploy. PostgreSQL keeps vectors next to application metadata, supports many documents and makes persistence an explicit part of the architecture.

Trade-off. A database is one more moving part to run, migrate and secure than a file on disk.

Async across the whole request path.

Async SQLAlchemy, asyncpg and an asynchronous LLM client handle I/O. PDF parsing and embedding have no native async equivalent here, so they are offloaded with asyncio.to_thread.

Trade-off. Offloading to threads relieves the event loop but still competes for the same CPU. This is not a throughput claim.

fastembed and ONNX instead of a torch embedding stack.

The deployment exceeded its memory budget with a torch-based dependency. Swapping to ONNX-based fastembed kept the vector schema unchanged.

Trade-off. A smaller runtime footprint in exchange for a narrower choice of embedding models.

Five configurable generation paths, without hiding their differences.

Groq, Azure AI Foundry, direct OpenAI, Bedrock InvokeModel and Bedrock Converse are selectable through the API (not a UI dropdown). A background-thread to asyncio-queue bridge handles boto3's blocking streaming. I also packaged the provider-addition workflow as a Claude Code skill and plugin (add-llm-provider, rag-provider-tools).

Trade-off. Breadth of integration is not breadth of verification; each path has a different evidence level.

Guard at generation, not at retrieval.

The answer path can decline to call the model when context is insufficient. The MCP tool can still return low-similarity chunks for callers that want them.

Trade-off. The similarity threshold is a starting point that has not been tuned on labelled data.

05 / DEBUGGING

Where the real engineering happened.

The event loop was not as asynchronous as the routes looked. Blocking work inside async routes stopped other requests making progress. In a synthetic event-loop experiment the loop was blocked for 814 ms before the fix and 20–24 ms after thread offloading. That measures loop blocking, not request latency.

Memory use exceeded the budget. Local PDF embedding peaked at 669 MB; reducing the embedding batch size from 256 to 8 brought it to 283 MB. This is a local measurement, not a benchmark of the live host.

Retrieval was silently returning too few rows. The golden-set run showed IVFFlat returning fewer than 3 chunks for 5 of 38 questions. Raising ivfflat.probes from 1 to 10 brought that to 0 of 38 in the documented experiment. It removes a truncation failure mode; it does not prove the retrieved chunks are relevant.

One real request: 0.77s in total, 0.33s retrieval and 0.44s generation. A single observed trace, not an average or a benchmark.

Langfuse trace for stream_answer taking 0.77 seconds, with a retrieve_relevant_chunks span of 0.33 seconds and a groq-generation span of 0.44 seconds.

Original, unmodified screenshot · Esc to close · Open full size

One real request: 0.77s in total, 0.33s retrieval and 0.44s generation. A single observed trace, not an average or a benchmark.LANGFUSE TRACE · CLICK TO EXPAND

06 / TESTING & EVALUATION

Measured, not assumed.

16 automated tests exercise ingestion, retrieval and the API against a real PostgreSQL database with deterministic embeddings and mocked model responses. A separate live AI evaluation covers real model behaviour. GitHub Actions starts a fresh database for each run.

A captured GitHub Actions run: 16 passed, 1 warning in 2.66s. Tests use a real PostgreSQL instance with deterministic embeddings and mocked model responses.

GitHub Actions log: pytest collected 16 items, all passed, 1 warning in 2.66 seconds.

Original, unmodified screenshot · Esc to close · Open full size

A captured GitHub Actions run: 16 passed, 1 warning in 2.66s. Tests use a real PostgreSQL instance with deterministic embeddings and mocked model responses.CI RUN · CROPPED VIEW, CLICK FOR FULL IMAGE

A 38-question golden set ran against Groq, recorded in Langfuse. Faithfulness and relevance come from an LLM judge, so they describe judged behaviour, not general accuracy. Precision, recall and MRR use real chunk identifiers, over the 35 questions that have expected chunks.

38-question baseline run. Dashboard values are rounded.
MetricValueWhat it is
Faithfulness0.945LLM-judge score
Relevance1.000LLM-judge score
Precision@30.143Chunk-ID match, 35 questions
Recall@30.386Chunk-ID match, 35 questions
MRR@30.295Chunk-ID match, 35 questions

Aggregate scores from the 38-question baseline run in Langfuse. The dashboard rounds values; faithfulness and relevance are LLM-judge scores, not accuracy percentages.

Langfuse experiment summary for 38 items, run “groq-v1 real run”, baseline: faithfulness 0.94, MRR@3 0.30, precision@3 0.14, recall@3 0.39, relevance 1.00.

Original, unmodified screenshot · Esc to close · Open full size

Aggregate scores from the 38-question baseline run in Langfuse. The dashboard rounds values; faithfulness and relevance are LLM-judge scores, not accuracy percentages.LANGFUSE EVAL · CLICK TO EXPAND

HOW TO READ THIS

The strict chunk-match scores are reported as recorded, next to the judge scores, not hidden behind them. The evaluation also exposed cross-document mixing, so removing one failure mode did not remove every quality issue.

Read the documented experiments and limitations

07 / DEPLOYMENT

Beyond a running container.

The documented public demo runs on Render with a Neon-hosted PostgreSQL database. Free-tier services can sleep, so a first request may take 30–60 seconds. CI runs the tests; application deployment is manual.

A separate AWS EC2 and RDS deployment was a migration exercise, not a second permanent production service. It covered Docker restart behaviour, private RDS access through security-group references, IAM fundamentals and moving data with pg_dump and pg_restore.

DEMO LINK

The public demo is not linked from this site. Its upload route has no authentication or tenant isolation, so it must not be treated as a safe place for confidential documents.

08 / LIMITATIONS

What this system does not promise.

  • Cross-document contamination and duplicate ingestion. The same file can be ingested more than once, and retrieval can mix documents.
  • No tenant isolation or authentication in the inspected public upload route, and limited resource limits.
  • Provider verification varies. Groq is documented live; Azure was confirmed with one short call; Bedrock live verification was blocked by an account restriction and direct OpenAI was not tested against the real service.
  • A small evaluation corpus. The scores are not a general accuracy claim, and it is unclear whether the “insufficient context” answer shown above was right.
  • Streaming failure handling has a gap. A provider failure after headers are sent can surface as an empty HTTP 200, and failed generations are not written to the query log.

09 / NEXT STEPS

What I would do next.

  • Scope retrieval to a document, and de-duplicate ingestion by content hash.
  • Add upload safeguards, authentication and per-user isolation before any real documents.
  • Broaden the evaluation set, and tune the similarity threshold on labelled data.
  • Close the streaming error gap and finish live verification of the remaining providers.

These are planned improvements, not completed work.

Read the source and documentation on GitHub

WORK WITH ME

Need something like this built?

I take on focused tasks as well as larger implementations. Tell me what you are trying to build.

Let's build something
that works.

HIRING AN ENGINEER?Discuss a role

Open to full-time engineering roles. Relocation across India is fine.

View résumé
HAVE A PROJECT?Discuss a project

Focused tasks or full builds. Tell me what you are trying to ship.

See what I can build

Draft an email

What is this about?

This opens a draft in your email app. Nothing is sent or stored from this page.