genai.college · Learn · Leagues · Advertise

Basics of NLP and RAG · Lesson 4

Building a Basic RAG Pipeline

A minimal pipeline in plain Python: read files, chunk them, embed chunks with an embedding model, store them in Chroma or FAISS, then for each question retrieve the top 4 chunks and send them with the question to an LLM.

The prompt should tell the model to answer only from the provided context and to say it does not know when the context lacks the answer. Ask it to cite chunk sources.

Test with real questions, inspect which chunks were retrieved, and fix retrieval first — a great model cannot answer from the wrong passages.

Key points

question = "What is our refund window?"
hits = collection.query(query_texts=[question], n_results=4)
context = "\n\n".join(hits["documents"][0])
prompt = f"""Answer only from the context. If it is not there, say "I don't know".
<context>{context}</context>
Question: {question}"""

·

About · Contact · Privacy · Terms