Chain AI Library
Chain AI is a streamlined micro-framework that simplifies LLM application development by providing modular, swappable components for RAG pipelines. It reduces LangChain complexity while maintaining flexibility through type-safe, GPU-accelerated document processing.
Built With
- Python
Technical Breakdown
Chain AI eliminates boilerplate with high-level convenience functions that create complete RAG pipelines from files or directories.
- File-based RAG: Direct pipeline creation from document paths with automatic processing.
- Directory Ingestion: Batch processing with configurable file type filtering.
- Smart Defaults: Optimized chunk sizes and retrieval parameters out-of-the-box.
- Interactive Chat: Built-in chat interface for immediate testing and validation.
1# Create RAG from files
2from chain.rag_runner import create_rag_from_files
3
4rag = create_rag_from_files(
5 file_paths=["manual.txt", "README.md"],
6 system_prompt="You are a documentation assistant.",
7 chunk_size=500,
8 retrieval_k=3
9)
10rag.run_chat()
11
12# Process entire directories
13from chain.rag_runner import create_rag_from_directory
14
15rag = create_rag_from_directory(
16 directory="./src",
17 file_extensions=['.py', '.md'],
18 system_prompt="You are a code assistant."
19)
Built on a foundation of swappable components, each implementing clear interfaces for maximum flexibility and testability.
- Chat Models: Abstract interface supporting local (LM Studio) and cloud (Azure OpenAI, OpenRouter) backends.
- Embeddings: Pluggable embedding providers with automatic dimension management.
- Text Splitters: Configurable chunking strategies including RecursiveCharacterTextSplitter.
- Memory Systems: FAISS-based vector storage with optional GPU acceleration.
1# Custom component configuration
2from chain.rag_runner import RAGConfig, RAGRunner
3from chain.chat_models import LocalChatModel, LocalChatConfig
4from chain.embeddings import LocalEmbeddings
5from chain.text_splitters import RecursiveCharacterTextSplitter
6
7# Compose custom pipeline
8custom_model = LocalChatModel(LocalChatConfig(temperature=0.7))
9custom_embeddings = LocalEmbeddings()
10custom_splitter = RecursiveCharacterTextSplitter(chunk_size=800)
11
12config = RAGConfig(
13 knowledge_texts=["Your knowledge..."],
14 chat_model=custom_model,
15 embeddings=custom_embeddings,
16 text_splitter=custom_splitter,
17)
18rag = RAGRunner(config).setup()
Optimized PDF parsing pipeline using PyMuPDF for high-performance document ingestion with intelligent text extraction.
- PyMuPDF Engine: Fast, accurate text extraction with layout preservation.
- Smart RAG Creation: Automated PDF-to-knowledge-base pipeline with optimized chunking.
- Metadata Extraction: Document structure analysis for improved retrieval accuracy.
- Batch Processing: Handle multiple PDFs efficiently in production scenarios.
1# Smart PDF RAG creation
2from chain.rag_runner import create_smart_rag
3
4# Process PDF with optimized settings
5rag = create_smart_rag(knowledge_files=["resume.pdf"])
6
7# Query the processed content
8response = rag.query("Can he vibe code ?")
9print(response)
Multiple installation profiles support different deployment scenarios from local development to enterprise cloud integration.
- Local Development: CPU-based FAISS for lightweight development environments.
- GPU Acceleration: Optional faiss-gpu for high-performance vector operations.
- Azure Integration: Built-in support for Azure AI Search and Azure OpenAI services.
- Hybrid Configurations: Mix local and cloud components based on requirements.
1# Installation options for different use cases
2pip install chain-ai # Base framework
3pip install chain-ai[local] # Local FAISS support
4pip install chain-ai[gpu] # NVIDIA GPU acceleration
5pip install chain-ai[pdf] # PyMuPDF PDF processing
6pip install chain-ai[azure] # Azure cloud services
7pip install chain-ai[all] # Everything included
Built with modern Python practices emphasizing type safety, developer experience, and maintainable code through Pydantic and clear APIs.
- Pydantic Models: Runtime type validation with clear error messages and auto-completion.
- Jinja2 Templating: Powerful prompt engineering with template inheritance and variables.
- Minimal Setup: High-level abstractions reduce configuration complexity.
- Extensible Design: Clear component interfaces for custom implementations.