A micro-framework for building with LLMs, inspired by LangChain.
Project description
Mini-Chain
Mini-Chain is a micro-framework for building applications with Large Language Models, inspired by LangChain.
Core Features
- Modular Components: Swappable classes for Chat Models, Embeddings, Memory, and more.
- Local & Cloud Ready: Supports both local models (via LM Studio) and cloud services (Azure).
- Modern Tooling: Built with Pydantic for type-safety and Jinja2 for powerful templating.
- GPU Acceleration: Optional
faiss-gpusupport for high-performance indexing.
Installation
pip install chain-ai
#For Local FAISS (CPU) Support:
pip install chain-ai[local]
#For NVIDIA GPU FAISS Support:
pip install chain-ai[gpu]
#For pdf parser(pymupdf)
pip install chain-ai[pdf]
#For Azure Support (Azure AI Search, Azure OpenAI):
pip install chain-ai[azure]
#To install everything:
pip install chain-ai[all]
Quick Start Here is the simplest possible RAG pipeline with Mini-Chain:
pip install chain-ai[local]
from chain.rag_runner import create_rag_from_files
# Load knowledge from files
rag = create_rag_from_files(
file_paths=["path/manual.txt", "README.md"],
system_prompt="You are a documentation assistant.",
chunk_size=500,
retrieval_k=3
)
rag.run_chat()
To Read the full directory
from chain.rag_runner import create_rag_from_directory
# Load all Python files from a directory
rag = create_rag_from_directory(
directory="./src",
file_extensions=['.py', '.md'],
system_prompt="You are a code assistant."
)
rag.run_chat()
Custom RAG Configuration
from chain.rag_runner import RAGRunner, RAGConfig
config = RAGConfig(
knowledge_texts=["Your knowledge here..."],
knowledge_files=["file1.txt", "file2.md"],
# Chunking settings
chunk_size=1000,
chunk_overlap=200,
# Retrieval settings
retrieval_k=4,
similarity_threshold=0.7, # Only include high-similarity results
# Chat settings
system_prompt="Custom system prompt...",
conversation_keywords=["custom", "keywords", "for", "conversation", "detection"],
# Components (optional - uses defaults if not provided)
chat_model=None, # Will use LocalChatModel
embeddings=None, # Will use LocalEmbeddings
text_splitter=None, # Will use RecursiveCharacterTextSplitter
vector_store=None, # Will create FAISSVectorStore
debug=True # Enable debug output
)
rag = RAGRunner(config).setup()
rag.run_chat()
Using Custom Components
from chain.rag_runner import RAGConfig, RAGRunner
from chain.chat_models import LocalChatModel, LocalChatConfig
from chain.embeddings import LocalEmbeddings
from chain.text_splitters import RecursiveCharacterTextSplitter
# Custom components
custom_model = LocalChatModel(LocalChatConfig(temperature=0.7))
custom_embeddings = LocalEmbeddings()
custom_splitter = RecursiveCharacterTextSplitter(chunk_size=800)
config = RAGConfig(
knowledge_texts=["Your knowledge..."],
chat_model=custom_model,
embeddings=custom_embeddings,
text_splitter=custom_splitter,
)
rag = RAGRunner(config).setup()
rag.run_chat()
pip install chain-ai[pdf]
from chain.rag_runner import create_smart_rag
# Load PDF and create RAG
rag = create_smart_rag(knowledge_files=["resume.pdf"])
# Query the PDF
response = rag.query("Can he vibe code ?")
print(response)
for azure ai search pip install chain-ai[azure]
Project details
Release history Release notifications | RSS feed
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 chain_ai-0.0.1.tar.gz.
File metadata
- Download URL: chain_ai-0.0.1.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24488194c56716b362455aba93ab13f7dad0c944351e1bbdf2ae3191edf3bfcf
|
|
| MD5 |
b82553c7afc53c10aed2f52e01534383
|
|
| BLAKE2b-256 |
f02e37b1de38c7ba854905c7cdc50d6e6038da1f2b6f6de9a01f878d095ceb5e
|
File details
Details for the file chain_ai-0.0.1-py3-none-any.whl.
File metadata
- Download URL: chain_ai-0.0.1-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
477a904ea374617a6eabb3b960454f2989757424d0295f5fc9900ead03e9d62d
|
|
| MD5 |
c492d71e2ac73930bac924bd97aa6380
|
|
| BLAKE2b-256 |
d586e85c68cf12bdee9ed4eadbe71e090fd8127eb2fc2eb00e8bd8b6444862d8
|