Inspiration

Medical Q&A needs answers that can be checked against source material. We wanted to combine a local retrieval-augmented generation pipeline with a simple pay-per-query experience, using PayPal sandbox to make payment part of the application workflow.

What it does

MediQuery Agent lets a user enter a medical question, approve a $1.00 PayPal sandbox payment, and receive an answer generated from a small demonstration knowledge base. The interface displays the answer, retrieved document chunks, and the payment capture receipt. No real money moves.

When the supplied documents do not answer a question, the model is instructed to say so. The video demonstrates this with an asthma question outside the seeded knowledge base. This is an educational prototype, not medical advice.

How we built it

The backend uses Java 17 and Spring Boot 3.2. The frontend is a browser-based interface with the PayPal JavaScript SDK.

The server creates an order through the PayPal sandbox Orders v2 REST API. After the buyer approves checkout, the server captures the order. Only a completed capture triggers answer generation.

For RAG, documents are divided into overlapping chunks. Ollama's nomic-embed-text generates 768-dimensional embeddings stored in PostgreSQL with pgvector. A question is embedded and matched to nearby chunks using cosine distance. Ollama's llama3.1:8b then generates a response using the retrieved context, with instructions to cite chunk IDs and acknowledge missing information.

Challenges we ran into

The main challenge was connecting the payment lifecycle to retrieval and generation: create an order, wait for approval, capture payment, and then answer the associated question. Other challenges included the pgvector/Hibernate integration, matching embedding dimensions to the database schema, and distinguishing retrieved documents from documents that support an answer.

Accomplishments that we're proud of

The demo connects a real PayPal sandbox checkout to a local RAG application. It shows a grounded-answer example, retrieved sources, a payment receipt, and an out-of-knowledge-base abstention example. Local Ollama inference avoids a paid AI API subscription.

What we learned

Payment integration affects the backend flow, not just the checkout interface. Retrieval makes supporting text visible, but retrieving nearby chunks does not guarantee relevance or correct citations. Abstention needs to be evaluated alongside successful answers.

What's next

Future work includes persistent order storage, stronger relevance and citation checks, automated evaluation, authenticated document ingestion, and a clearer experience when the knowledge base cannot answer a paid question. The current prototype does not implement persistent payer/query history or automatic refunds.

Try the functional demo

The functional application runs locally. Complete free setup and testing instructions, including sample data and PayPal sandbox configuration:

https://github.com/jiabeiliu/mediquery-agent/blob/main/docs/JUDGES.md

The guide uses local Ollama inference and PayPal sandbox with no real-money charges. Evaluators use their own free sandbox app and Personal sandbox buyer account.

Existing work and hackathon contributions

We began the project in September 2026. The medical RAG core existed before October 1. During the hackathon submission period in October, we added the PayPal sandbox pay-per-query integration, server-side order creation and capture gating, the browser demo with sources and payment receipts, and the demo recording, testing guide, and submission documentation. The submitted application builds upon the existing RAG core.

Built With

Share this project:

Updates

Submission history