Retrieval-augmented generation pipeline

Chunk a document, embed it with a real model in your browser, retrieve the best passages for a question, and see the prompt a RAG system would send.

IntermediateExplained in Retrieval-augmented generation

Retrieval-augmented generation, step by step

Answer questions about a document the model has never seen: split it, embed it, find the relevant pieces, and put them in the prompt.

Example questions

1 Split the document into chunks

Whole sentences are packed together up to the chunk size.

40
  1. #1Northwind Cycles staff handbook. This shop and handbook are fictional and exist only for this lesson. Opening hours. The shop opens at 9 am and closes at 6 pm from Tuesday to Saturday. It is closed on Sundays and Mondays.
  2. #2On public holidays the shop opens from 10 am to 3 pm. Returns. Customers may return an unused bike within 30 days of purchase for a full refund. Used bikes can be exchanged within 14 days but not refunded.
  3. #3Clothing and helmets must be returned in their original packaging. Warranty. Every new frame carries a five-year warranty against manufacturing defects. Wheels, brakes, and other parts are covered for one year.
  4. #4The warranty does not cover damage from crashes, racing, or ordinary wear. Repairs. A basic tune-up costs 45 dollars and takes one working day. Customers can book a repair online or at the counter.
  5. #5Bikes left more than 60 days after a repair is finished may be donated to the community bike program. Staff benefits.
  6. #6Employees receive a 25 percent discount on bikes and a 40 percent discount on parts and clothing after their first three months. Staff may borrow a demo bike for up to one week, twice a year. Bike fitting.
  7. #7A professional fitting takes about 90 minutes and costs 120 dollars. Customers who buy a bike within two weeks of a fitting get the fitting fee back as store credit.

Runs a real model in your browser

Embed the chunks and your question to find the most relevant passages. This uses all-MiniLM-L6-v2, a small sentence-embedding model that maps text to 384 numbers.

The first time, your browser downloads about 24 MB of model files from Hugging Face, plus a 14 MB runtime from this site. Both are cached for later visits. Everything runs on your device; nothing you type is sent anywhere.

Chunks7

Try this

  • Change the chunk size and watch which chunk wins for the same question.
  • Ask a question the handbook cannot answer, such as “Do you sell skateboards?”, and read what gets retrieved anyway.

Try "embedding", "softmax", "overfitting", or "backpropagation".