A lightweight, modular Retrieval-Augmented Generation (RAG) framework for Python.
- Modular Design - Easy to extend and customize
- Multiple LLM Providers - Support for various AI models
- Multiple Vector Stores - ChromaDB, Milvus support
- Agentic RAG - Advanced retrieval with tool usage
- Multi-modal Support - Text, code, and image processing
- RAG Evaluation - RAGAS metrics for quality assessment
- Training Data Generation - Auto-generate QA pairs from documents
- Local & Cloud - Run locally with Ollama or use cloud APIs
- π₯ Parent-Child Chunking - Small chunks for retrieval, large chunks for generation
- π₯ Query Rewriting - Auto/Direct/HyDE/Subquery strategies with LLM-based selection
| Provider | Status | Notes |
|---|---|---|
| OpenAI | β Supported | GPT-4, GPT-3.5, etc. |
| Ollama | β Supported | Local models |
| Mistral | β Supported | Mistral AI API |
| Google Gemini | β Supported | Gemini Pro, etc. |
| LM Studio | β Supported | Local GUI management |
| Kimi (Moonshot) | β Supported | OpenAI-compatible API |
| DeepSeek | β Supported | With reasoning support |
| Vector Store | Status | Notes |
|---|---|---|
| ChromaDB | β Supported | Default, local/remote |
| Milvus | β Supported | With vector indexing (IVF_FLAT, HNSW, etc.) |
| Model | Status | Notes |
|---|---|---|
| Sentence Transformers | β Supported | all-MiniLM-L6-v2, etc. |
| BGE-M3 | β Supported | Multilingual, 1024-dim |
| OpenAI | β Supported | text-embedding-ada-002 |
| Google Gemini | β Supported | gemini-embedding-001 |
pip install raglightOr install from source:
git clone https://github.com/stargazerwh/RAG-Lighter.git
cd RAG-Lighter
pip install -e .from raglight.rag.builder import Builder
from raglight.config.settings import Settings
# Create RAG pipeline
rag = (
Builder()
.with_embeddings(Settings.HUGGINGFACE, model_name="all-MiniLM-L6-v2")
.with_vector_store(Settings.CHROMA, collection_name="my_docs")
.with_llm(Settings.OLLAMA, model_name="llama3.1:8b")
.build_rag(k=5)
)
# Index documents
rag.vector_store.ingest("./documents")
# Query
response = rag.generate("What is the main topic?")
print(response)Small chunks for precise retrieval, large chunks for complete context:
from raglight.config.rag_config import RAGConfig
# Configure parent-child chunking
config = RAGConfig(
llm="llama3.1:8b",
provider=Settings.OLLAMA,
use_parent_child_chunking=True,
parent_chunk_size=2000, # Large chunks for LLM context
child_chunk_size=400, # Small chunks for retrieval
query_rewrite_strategy="Auto" # Auto-select strategy
)
rag = (
Builder()
.with_embeddings(Settings.HUGGINGFACE, model_name="all-MiniLM-L6-v2")
.with_vector_store(Settings.CHROMA, collection_name="pc_docs")
.with_llm(Settings.OLLAMA, model_name="llama3.1:8b")
.with_cross_encoder(Settings.HUGGINGFACE, model_name="cross-encoder/ms-marco-MiniLM-L-6-v2")
.build_rag(config=config)
)
# Cross-encoder reranks child chunks, returns parent chunks
response = rag.generate("Your complex question?")
print(f"Strategy used: {rag.get_last_strategy()}") # Direct/HyDE/Subqueryfrom raglight.config.rag_config import RAGConfig
config = RAGConfig(
llm="llama3.1:8b",
provider=Settings.OLLAMA,
query_rewrite_strategy="HyDE" # or "Direct", "Subquery", "Auto"
)
rag = Builder().with_embeddings(...).with_vector_store(...).with_llm(...).build_rag(config=config)
# HyDE: Generates hypothetical document for better retrieval
# Subquery: Decomposes complex questions into sub-queries
# Auto: LLM selects the best strategy dynamically| Strategy | Use Case | Description |
|---|---|---|
| Direct | Simple, clear questions | Query as-is |
| HyDE | Abstract/conceptual questions | Generate hypothetical answer document |
| Subquery | Complex multi-part questions | Decompose into sub-queries |
| Auto | Unknown question type | LLM dynamically selects strategy |
from raglight.llm import KimiModel
kimi = KimiModel(model_name="kimi-k2.5")
response = kimi.generate({"question": "Hello, how are you?"})
print(response)from raglight.lll import DeepSeekModel
# Standard chat model
deepseek = DeepSeekModel(model_name="deepseek-chat")
response = deepseek.generate({"question": "Explain quantum computing"})
# Reasoning model (R1)
21 = DeepSeekModel(model_name="deepseek-reasoner")
result = r1.generate_with_thinking({"question": "Solve this complex problem..."})
print(result["reasoning"]) # Chain of thought
print(result["answer"]) # Final answerfrom raglight.vectorstore import MilvusVS
from raglight.embeddings import HuggingfaceEmbeddingsModel
# Initialize Milvus with vector indexing
embeddings = HuggingfaceEmbeddingsModel("all-MiniLM-L6-v2")
# Local Milvus
vector_store = MilvusVS(
collection_name="my_collection",
embeddings_model=embeddings,
persist_directory="./milvus_db", # Milvus Lite mode
index_type="HNSW", # or "IVF_FLAT", "IVF_SQ8"
metric_type="COSINE" # or "L2", "IP")
# Or connect to Milvus server
vector_store = MilvusVS(
collection_name="my_collection",
embeddings_model=embeddings,
host="localhost",
port=19530,
index_type="HNSW",
metric_type="COSINE"
)from raglight.embeddings import BgeM3EmbeddingsModel
# BGE-M3 for multilingual retrieval
embeddings = BgeM3EmbeddingsModel(
model_name="BAAI/bge-m3",
use_fp16=True # Use half precision for faster inference
)
# Or use BGE-Large
embeddings = BgeM3EmbeddingsModel("BAAI/bge-large-en-v1.5")from raglight.evaluation import RAGASEvaluator, RAGResult
# Initialize evaluator
evaluator = RAGASEvaluator()
# Create RAG result
result = RAGResult(
question="What is the main topic?",
answer="The document discusses...",
contexts=retrieved_documents
)
# Evaluate
scores = evaluator.evaluate(result)
print(f"Faithfulness: {scores.faithfulness}")
print(f"Answer Relevancy: {scores.answer_relevance}")
print(f"Context Relevancy: {scores.context_relevance}")
print(f"Context Recall: {scores.context_recall}")
# Batch evaluation
results = [result1, result2, result3]
report = evaluator.generate_report(results)Automatically generate question-answer pairs from your documents for fine-tuning or evaluation:
from raglight.embeddings.build.traindata import load_corpus, documents_to_qa
from raglight.llm import OpenAIModel
# Load and chunk documents
docs = load_corpus(["train.pdf"], chunk_size=512, verbose=True)
# Generate QA pairs using LLM
llm = OpenAIModel(model_name="gpt-4")
qa_df = documents_to_qa(docs, llm=llm, verbose=True)
# Save for training
qa_df.to_csv("train_qa.csv", index=False)from raglight.agent import Agent
agent = Agent(rag=rag)
response = agent.chat("Find information about X in my documents")Create a .env file:
# OpenAI
OPENAI_API_KEY=your_openai_key
# Mistral
MISTRAL_API_KEY=your_mistral_key
# Google Gemini
GEMINI_API_KEY=your_gemini_key
# Kimi (Moonshot)
KIMI_API_KEY=your_kimi_key
# DeepSeek
DEEPSEEK_API_KEY=your_deepseek_key
# Milvus (optional)
MILVUS_HOST=localhost
MILVUS_PORT=19530
MILVUS_URI=your_milvus_uri # For Zilliz Cloud
MILVUS_TOKEN=your_token# Interactive chat
raglight chat
# Agentic chat with tools
raglight agentic-chat
# Index documents
raglight index ./my_documentssrc/raglight/
βββ cli/ # Command line interface
βββ config/ # Configuration management
βββ cross_encoder/ # Re-ranking models
βββ document_processing/ # Document parsing
βββ embeddings/ # Embedding models
βββ evaluation/ # RAG evaluation (RAGAS)
βββ llm/ # LLM implementations
βββ models/ # Data models
βββ rag/ # Core RAG implementationβββ scrapper/ # Web scraping
βββ vectorstore/ # Vector database (Chroma, Milvus)
- TXT / Markdown
- HTML
- Code files (Python, JavaScript, TypeScript, Java, C++, C#, etc.)
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Built with LangChain for document processing
- Vector storage powered by ChromaDB
- Embeddings via Sentence Transformers