Two examples of building RAG (Retrieval-Augmented Generation) systems in Python. One runs locally, one uses AWS cloud.
| Example | Where it runs | Vector DB | Best for |
|---|---|---|---|
| local-rag | Your computer | FAISS | Learning, privacy, no costs |
| bedrock-rag | AWS Cloud | Bedrock KB | Production, scale |
Runs everything on your machine. Uses Ollama for the AI and FAISS to search through documents.
Your Question → Search documents → Add context → AI responds
Uses AWS Bedrock. Can connect to a Knowledge Base for document search.
Your Question → AWS Knowledge Base → Add context → Claude responds
These are just examples. The code shows you how to connect the pieces together.
The real work in RAG is how you prepare your data:
- How you split documents into chunks
- What metadata you add
- How you structure the information
- What you choose to index
Good data preparation = good results. Bad data = bad answers, no matter how fancy your code is.
You need Ollama installed first.
# Install Ollama from ollama.ai, then:
ollama pull llama3
ollama pull nomic-embed-text
cd local-rag
pip install -r requirements.txt
uvicorn main:app --reloadYou need AWS credentials set up.
cd bedrock-rag
pip install -r requirements.txt
uvicorn main:app --reloadLocal RAG:
- Ollama - runs AI models locally
- FAISS - searches through documents fast
- LangChain - connects everything
- FastAPI - web API
Bedrock RAG:
- AWS Bedrock - Claude AI in the cloud
- Bedrock Knowledge Base - document search (optional)
- FastAPI - web API
RAG = Retrieval-Augmented Generation
Instead of just asking the AI a question, you:
- Retrieve - find relevant info from your documents
- Augment - add that info to your question
- Generate - AI answers using your documents
This way the AI can answer questions about YOUR data, not just what it learned in training.
Both examples are generic on purpose. Replace the data with yours:
Local RAG:
- Put your CSV/docs in
local-rag/data/ - Update the assistant name in config
Bedrock RAG:
- Create your own Knowledge Base in AWS
- Edit
prompts.pyfor your use case
.
├── local-rag/ # Ollama + FAISS example
│ ├── main.py # API endpoints
│ ├── rag_chain.py # RAG logic
│ ├── config.py # Settings
│ └── data/ # Sample data
│
└── bedrock-rag/ # AWS Bedrock example
├── main.py # API endpoints
├── bedrock_client.py # Bedrock + KB logic
├── prompts.py # System instructions
└── config.py # Settings
MIT - use it however you want.