A minimal Python library for Retrieval-Augmented Generation with codebase indexing and multiple vector store backends
Project description
TinyRag ๐
A lightweight, powerful Python library for Retrieval-Augmented Generation (RAG) that works locally without API keys. Features advanced codebase indexing, multiple document formats, and flexible vector storage backends.
๐ฏ Perfect for developers who need RAG capabilities without complexity or mandatory cloud dependencies.
๐ Key Features
๐ Works Locally - No API Keys Required
- ๐ง Local Embeddings: Uses all-MiniLM-L6-v2 by default
- ๐ Direct Search: Query documents without LLM costs
- โก Zero Setup: Works immediately after installation
๐ Advanced Document Processing
- ๐ Multi-Format: PDF, DOCX, CSV, TXT, and raw text
- ๐ป Code Intelligence: Function-level indexing for 7+ programming languages
- ๐งต Multithreading: Parallel processing for faster indexing
- ๐ Chunking Strategies: Smart text segmentation
๐๏ธ Flexible Storage Options
- ๐ Multiple Backends: Memory, Pickle, Faiss, ChromaDB
- ๐พ Persistence: Automatic or manual data saving
- โก Performance: Choose speed vs. memory trade-offs
- ๐ง Configuration: Customizable for any use case
๐ฌ Optional AI Integration
- ๐ค Custom System Prompts: Tailor AI behavior for your domain
- ๐ Provider Support: OpenAI, Azure, Anthropic, local models
- ๐ฐ Cost Control: Use only when needed
- ๐ฏ RAG-Powered Chat: Contextual AI responses
๐ Quick Start
๐ก New to TinyRag? Check out our comprehensive ๐ Documentation with step-by-step guides!
Installation
# Basic installation
pip install tinyrag
# With all optional dependencies
pip install tinyrag[all]
# Specific vector stores
pip install tinyrag[faiss] # High performance
pip install tinyrag[chroma] # Persistent storage
pip install tinyrag[docs] # Document processing
Usage Examples
๐โโ๏ธ 30-Second Example (No API Key Required)
from tinyrag import TinyRag
# 1. Create TinyRag instance
rag = TinyRag()
# 2. Add your content
rag.add_documents([
"TinyRag makes RAG simple and powerful.",
"docs/user_guide.pdf",
"research_papers/"
])
# 3. Search your content
results = rag.query("How does TinyRag work?", k=3)
for text, score in results:
print(f"Score: {score:.2f} - {text[:100]}...")
Output:
Score: 0.89 - TinyRag makes RAG simple and powerful.
Score: 0.76 - TinyRag is a lightweight Python library for...
Score: 0.72 - The system processes documents using semantic...
๐ค AI-Powered Chat (Optional)
from tinyrag import Provider, TinyRag
# Set up AI provider
provider = Provider(
api_key="sk-your-openai-key",
model="gpt-4"
)
# Create smart assistant
rag = TinyRag(
provider=provider,
system_prompt="You are a helpful technical assistant."
)
# Add knowledge base
rag.add_documents(["technical_docs/", "api_guides/"])
rag.add_codebase("src/") # Index your codebase
# Get intelligent answers
response = rag.chat("How do I implement user authentication?")
print(response)
# AI response based on your specific docs and code!
๐ Complete Documentation
๐ Full Documentation - Comprehensive guides from beginner to expert
๐ Getting Started
- Quick Start - 5-minute introduction
- Installation - Complete setup guide
- Basic Usage - Core features without AI
๐ง Core Features
- Document Processing - PDF, DOCX, CSV, TXT
- Codebase Indexing - Function-level code search
- Vector Stores - Choose the right storage
- Search & Query - Similarity search techniques
๐ค AI Integration
- System Prompts - Customize AI behavior
- Chat Functionality - Build conversations
- Provider Configuration - AI model setup
๐ง Core API Reference
Provider Class
from tinyrag import Provider
# ๐ No API key needed - works locally
provider = Provider(embedding_model="default")
# ๐ค With AI capabilities
provider = Provider(
api_key="sk-your-key",
model="gpt-4", # GPT-4, GPT-3.5, local models
embedding_model="text-embedding-ada-002", # or "default" for local
base_url="https://api.openai.com/v1" # OpenAI, Azure, custom
)
TinyRag Class
from tinyrag import TinyRag
# ๐๏ธ Choose your vector store
rag = TinyRag(
provider=provider, # Optional: for AI chat
vector_store="faiss", # memory, pickle, faiss, chromadb
chunk_size=500, # Text chunk size
max_workers=4, # Parallel processing
system_prompt="Custom prompt" # AI behavior
)
๐๏ธ Vector Store Comparison
| Store | Performance | Persistence | Memory | Dependencies | Best For |
|---|---|---|---|---|---|
| Memory | โก Fast | โ None | ๐ High | โ None | Development, testing |
| Pickle | ๐ Fair | ๐พ Manual | ๐ Medium | โ Minimal | Simple projects |
| Faiss | ๐ Excellent | ๐พ Manual | ๐ Low | ๐ฆ faiss-cpu | Large datasets, speed |
| ChromaDB | โก Good | ๐ Auto | ๐ Medium | ๐ฆ chromadb | Production, features |
๐ก Recommendation: Start with
memoryfor development, usefaissfor production performance.
๐ง Essential Methods
# ๐ Document Management
rag.add_documents(["file.pdf", "text"]) # Add any documents
rag.add_codebase("src/") # Index code functions
rag.clear_documents() # Reset everything
# ๐ Search & Query (No AI needed)
results = rag.query("search term", k=5) # Find similar content
code = rag.query("auth function") # Search code too
# ๐ค AI Chat (Optional)
response = rag.chat("Explain this code") # Get AI answers
rag.set_system_prompt("Be helpful") # Customize AI
# ๐พ Persistence
rag.save_vector_store("my_data.pkl") # Save your work
rag.load_vector_store("my_data.pkl") # Load it back
๐ Complete API Reference - Full method documentation
๐ป Code Intelligence
TinyRag indexes your codebase at the function level for intelligent code search:
๐ Supported Languages
| Language | Extensions | Detection |
|---|---|---|
| Python | .py |
def function_name |
| JavaScript | .js, .ts |
function name(), const name = |
| Java | .java |
public/private type name() |
| C/C++ | .c, .cpp, .h |
return_type function_name() |
| Go | .go |
func functionName() |
| Rust | .rs |
fn function_name() |
| PHP | .php |
function functionName() |
๐ Code Search Examples
# Index your entire project
rag.add_codebase("my_app/")
# Find authentication code
auth_code = rag.query("user authentication login")
# Database functions
db_code = rag.query("database query SELECT")
# API endpoints
api_code = rag.query("REST API endpoint")
# Get AI explanations (with API key)
response = rag.chat("How does user authentication work?")
# AI analyzes your actual code and explains it!
๐ก Learn More - Advanced code search techniques
โ๏ธ Configuration Examples
๐ Performance Optimized
# Large datasets, maximum speed
rag = TinyRag(
vector_store="faiss",
chunk_size=800,
max_workers=8 # Parallel processing
)
๐พ Production Setup
# Persistent, multi-user ready
rag = TinyRag(
provider=provider,
vector_store="chromadb",
vector_store_config={
"collection_name": "company_docs",
"persist_directory": "/data/vectors/"
}
)
๐ค Custom AI Assistant
# Domain-specific AI behavior
rag = TinyRag(
provider=provider,
system_prompt="""You are a senior software engineer.
Provide detailed technical explanations with code examples."""
)
๐ง Full Configuration Guide - All options explained
๐ฆ Installation
๐ฏ Choose Your Setup
# ๐ Quick start (works immediately)
pip install tinyrag
# โก High performance (recommended)
pip install tinyrag[faiss]
# ๐ Document processing (PDF, DOCX)
pip install tinyrag[docs]
# ๐๏ธ Production database
pip install tinyrag[chroma]
# ๐ Everything included
pip install tinyrag[all]
๐ง What Each Option Includes
| Option | Includes | Use Case |
|---|---|---|
| Base | Memory store, local embeddings | Development, testing |
| [faiss] | + High-performance search | Large datasets |
| [docs] | + PDF/DOCX processing | Document analysis |
| [chroma] | + Persistent database | Production apps |
| [all] | + Everything | Full features |
๐ก Installation Guide - Detailed setup instructions
๐ฏ Real-World Use Cases
๐ข Business Applications
- ๐ Customer Support: Query company docs and policies
- ๐ Knowledge Management: Searchable internal documentation
- ๐ Research Tools: Semantic search through research papers
- ๐ Report Analysis: Find insights across business reports
๐จโ๐ป Developer Tools
- ๐ง Code Documentation: Auto-generate code explanations
- ๐ Legacy Code Explorer: Understand large codebases
- ๐ API Assistant: Query technical documentation
- ๐งช Testing Helper: Find relevant test patterns
๐ Educational & Research
- ๐ Study Assistant: Query textbooks and notes
- ๐ Writing Helper: Research paper analysis
- ๐ง Learning Companion: Personalized explanations
- ๐ Data Analysis: Explore datasets semantically
๐ก See Complete Examples - Production-ready applications
๐ ๏ธ Contributing
We welcome contributions! Here's how to get started:
# 1. Fork and clone
git clone https://github.com/Kenosis01/TinyRag.git
cd TinyRag
# 2. Install development dependencies
pip install -e ".[all,dev]"
# 3. Run tests
python -m pytest
# 4. Make your changes and submit a PR!
๐ Development Setup
- Python 3.7+ required
- Core dependencies: sentence-transformers, requests, numpy
- Optional: faiss-cpu, chromadb, PyPDF2, python-docx
๐ง Development Guide - Detailed contributor guidelines
๐ค Community & Support
๐ Get Help
- ๐ Complete Documentation - Comprehensive guides
- ๐ GitHub Issues - Bug reports & feature requests
- ๐ฌ Discussions - Community Q&A
- ๐ FAQ - Common questions answered
๐ Show Your Support
- โญ Star this repo if TinyRag helps you!
- ๐ฆ Share on Twitter - spread the word
- โ Buy me a coffee - support development
- ๐ค Contribute - help make TinyRag better
๐ License
MIT License - see LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tinyrag-0.3.4.tar.gz.
File metadata
- Download URL: tinyrag-0.3.4.tar.gz
- Upload date:
- Size: 87.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6113b63d8b4e9101cb7788cb20c9752864a2860d70fcf981c66498e7226e0d3e
|
|
| MD5 |
892cceccbb7450b1b2174144f64a37a7
|
|
| BLAKE2b-256 |
fb0863131668017bc68113d95a5ce122d683d64f2f9d1dca2e57919850f76b14
|
File details
Details for the file tinyrag-0.3.4-py3-none-any.whl.
File metadata
- Download URL: tinyrag-0.3.4-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
959eb53a334a5c9577bbd2eed52257aecebfa334cfe3deee43afe93a41d4c530
|
|
| MD5 |
53729f70249ad44f6625df194050f7fc
|
|
| BLAKE2b-256 |
89e09cd079730d30bedd845145a7d75d7c80581c5c7783d77b51fe509b6abfa7
|