Ceylon AI RAG Framework
A powerful, modular, and extensible Retrieval-Augmented Generation (RAG) framework built with Python, supporting multiple LLM providers, embedders, and document types.
🌟 Features
-
Multiple Document Types: Support for various document formats including:
- Text files (with extensive format support)
- PDF documents
- Images (with OCR capabilities)
- Source code files
-
Flexible Architecture:
- Modular component design
- Pluggable LLM providers (OpenAI, Ollama)
- Extensible embedding providers
- Vector store integration (LanceDB)
-
Advanced RAG Capabilities:
- Intelligent document chunking
- Context-aware searching
- Query expansion and reranking
- Metadata enrichment
- Source attribution
-
Specialized RAG Implementations:
FolderRAG: Process and analyze entire directory structuresCodeAnalysisRAG: Specialized for source code understandingSimpleRAG: Basic RAG implementation for text data- Support for custom RAG implementations
🚀 Getting Started
Installation
# Install via pip
pip install ceylon-rag
# Or install from source
git clone https://github.com/ceylonai/ceylon-rag.git
cd ceylon-rag
pip install -e .
Basic Usage
Here's a simple example using the framework:
import asyncio
from dotenv import load_dotenv
from ceylon_rag import SimpleRAG
async def main():
# Load environment variables
load_dotenv()
# Configure the RAG system
config = {
"llm": {
"type": "openai",
"model_name": "gpt-4",
"api_key": os.getenv("OPENAI_API_KEY")
},
"embedder": {
"type": "openai",
"model_name": "text-embedding-3-small",
"api_key": os.getenv("OPENAI_API_KEY")
},
"vector_store": {
"type": "lancedb",
"db_path": "./data/lancedb",
"table_name": "documents"
}
}
# Initialize RAG
rag = SimpleRAG(config)
await rag.initialize()
try:
# Process your documents
documents = await rag.process_documents("path/to/documents")
# Query the system
result = await rag.query("What are the main topics in these documents?")
print(result.response)
finally:
await rag.close()
if __name__ == "__main__":
asyncio.run(main())
🏗️ Architecture
Core Components
-
Document Loaders
TextLoader: Handles text-based filesPDFLoader: Processes PDF documentsImageLoader: Handles images with OCR- Extensible base class for custom loaders
-
Embedders
- OpenAI embeddings support
- Ollama embeddings support
- Modular design for adding new providers
-
LLM Providers
- OpenAI integration
- Ollama integration
- Async interface for all providers
-
Vector Store
- LanceDB integration
- Efficient vector similarity search
- Metadata storage and retrieval
Document Processing
The framework provides sophisticated document processing capabilities:
# Example: Processing a code repository
async def analyze_codebase():
config = {
"llm": {
"type": "openai",
"model_name": "gpt-4"
},
"embedder": {
"type": "openai",
"model_name": "text-embedding-3-small"
},
"vector_store": {
"type": "lancedb",
"db_path": "./data/lancedb",
"table_name": "code_documents"
},
"chunk_size": 1000,
"chunk_overlap": 200
}
rag = CodeAnalysisRAG(config)
await rag.initialize()
documents = await rag.process_codebase("./src")
await rag.index_code(documents)
result = await rag.analyze_code(
"Explain the main architecture of this codebase"
)
print(result.response)
🔧 Advanced Configuration
File Exclusions
Configure file exclusions using patterns:
config = {
# ... other config options ...
"excluded_dirs": [
"venv",
"node_modules",
".git",
"__pycache__"
],
"excluded_files": [
".env",
"package-lock.json"
],
"excluded_extensions": [
".pyc",
".pyo",
".pyd"
],
"ignore_file": ".ragignore" # Similar to .gitignore
}
Chunking Configuration
Customize document chunking:
config = {
# ... other config options ...
"chunk_size": 1000, # Characters per chunk
"chunk_overlap": 200, # Overlap between chunks
}
🤝 Contributing
Contributions are welcome! Please feel free to submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
📄 License
🙏 Acknowledgments
- OpenAI for GPT and embedding models
- Ollama for local LLM support
- LanceDB team for vector storage
- All contributors and users of the framework
📚 API Documentation
For detailed API documentation, please visit our API Documentation page.
🔗 Links
Metadata
Release files for ceylon-rag 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ceylon_rag-0.3.1.tar.gz | 40.6 kB | Without provenance | Details for ceylon_rag-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ceylon_rag-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for ceylon_rag-0.3.1-py3-none-any.whl |
Total release size: 61.1 kB
Release files / ceylon_rag-0.3.1.tar.gz
| Download URL | ceylon_rag-0.3.1.tar.gz |
|---|---|
| Size | 40.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2512ed18080f31a278e6ab831996f2438c69f0ae002819fa4cd0927c05487ab
|
|
BLAKE2b-256 checksum How to use checksums |
8b6798474bb3706533745aa052a87579ba867560034a862c0d33898f049d2d30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.12.6 Windows/11
|
Release files / ceylon_rag-0.3.1-py3-none-any.whl
| Download URL | ceylon_rag-0.3.1-py3-none-any.whl |
|---|---|
| Size | 20.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f51c81568b9c57be1b9a9d62d908c1e4a44aadf26ea116d02165923e25cfd7cc
|
|
BLAKE2b-256 checksum How to use checksums |
66212eb499487ebaa8b46346af8728ebab13fe92c6c7638e97b28aef51198449
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.12.6 Windows/11
|
Security for ceylon-rag 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.