WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Simple RAG examples in Python. One uses Ollama locally, one uses AWS Bedrock. Shows how to connect documents to AI responses. The hard part is preparing your data, not the code.

License

Notifications You must be signed in to change notification settings

davidefalcone21/python-rag-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python RAG Patterns

Python FastAPI License

Two examples of building RAG (Retrieval-Augmented Generation) systems in Python. One runs locally, one uses AWS cloud.

What's Inside

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

Quick Look

Local RAG

Runs everything on your machine. Uses Ollama for the AI and FAISS to search through documents.

Your Question → Search documents → Add context → AI responds

Bedrock RAG

Uses AWS Bedrock. Can connect to a Knowledge Base for document search.

Your Question → AWS Knowledge Base → Add context → Claude responds

Important Note

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.

Get Started

Local RAG

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 --reload

Bedrock RAG

You need AWS credentials set up.

cd bedrock-rag
pip install -r requirements.txt
uvicorn main:app --reload

Tech Used

Local 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

What is RAG?

RAG = Retrieval-Augmented Generation

Instead of just asking the AI a question, you:

  1. Retrieve - find relevant info from your documents
  2. Augment - add that info to your question
  3. Generate - AI answers using your documents

This way the AI can answer questions about YOUR data, not just what it learned in training.

Customize It

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.py for your use case

Project Structure

.
├── 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

License

MIT - use it however you want.

About

Simple RAG examples in Python. One uses Ollama locally, one uses AWS Bedrock. Shows how to connect documents to AI responses. The hard part is preparing your data, not the code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages