RAG Tutorial
This tutorial will get you from zero to RAG-powered agent in just a few minutes. We'll cover how Railtracks can help you build the perfect RAG Agent for your needs.
Don't know what RAG is or why you might want to use it? Check out our brief explainer here
When you create a RAG node, Railtracks automatically take care of chunking, embedding, and searching for you making it easy to use. All you need to do is provide a text file and let Railtracks take care of it for you from there. Let's look at an example of what this could look like.
Quickstart: Prebuilt RAG Node
This is the easiest way to add RAG to your app. Let's build a simple knowledge base in under 10 lines of code:
import asyncio
import railtracks as rt
from railtracks.prebuilt import rag_node
retriever = rt.prebuilt.rag_node([
"Steve likes apples and enjoys them as snacks",
"John prefers bananas for their potassium content",
"Alice loves oranges for vitamin C",
])
question = "What does Steve like?"
results = asyncio.run(rt.call(retriever, question, top_k=3))
context = "\n".join(
f"Document {i+1} (score: {r.score:.4f}): {r.record.text}"
for i, r in enumerate(results)
)
print(f"Question: {question}")
print(f"Retrieved context:\n{context}")
Example Output
Your RAG node can now answer questions based on your documents:
Query: "Who is Steve?"
Response: "In our company, Steve is the lead engineer and ..."
Next Steps
Ready to build with RAG
- RAG Reference Documentation to learn how to build RAG applications in RT.
- Tools Documentation for integrating any type of tool.