Arabic Retrieval-Augmented Generation Library
Project description
๐ง Muffakir RAG
Advanced Arabic Retrieval-Augmented Generation (RAG) Library
Muffakir RAG is a powerful Python library designed specifically for building sophisticated Retrieval-Augmented Generation (RAG) systems tailored to the Arabic language. It supports advanced document processing, semantic search, and intelligent answer generation powered by multiple LLM providers.
โจ Key Features
- ๐ Arabic Language Focus: Optimized for accurate processing of Arabic texts
- ๐ค Multi-Provider Support: Seamless integration with Together AI, OpenAI, Groq, and Open Router
- ๐ Advanced Document Processing: Handles PDF (including OCR for scanned documents), DOCX, TXT, and images with OCR support
- ๐ Smart Retrieval: Multiple retrieval methods including hybrid and contextual search, with built-in reranking
- โก Simple API: Intuitive interface for quick integration and usage
- ๐ก๏ธ Hallucination Check: Validates answers to reduce hallucinations
- ๐ Query Transformer: Automatically optimizes user queries for better retrieval
- ๐ Reranker: Enhances retrieval results through semantic similarity reranking
๐ Installation
pip install Muffakir
For development:
git clone https://github.com/yourusername/muffakir-rag.git
cd muffakir-rag
pip install -e .
๐ Quick Start
from Muffakir import MuffakirRAG
config = {
"data_dir": "path/to/your/documents",
"llm_provider": "together",
"api_key": "your_api_key_here",
"embedding_model": "mohamed2811/Muffakir_Embedding",
"k": 5,
"query_transformer": True,
"hallucination_check": True,
"reranking": True
}
rag = MuffakirRAG(config)
response = rag.ask("What is the definition of artificial intelligence?")
print(response["answer"])
๐ง Configuration Parameters
Core
| Parameter | Description | Default | Required |
|---|---|---|---|
data_dir |
Path to documents folder | None | Yes |
api_key |
API key for LLM provider | None | Yes |
llm_provider |
Language model provider | "together" |
Yes |
embedding_model |
Embedding model to use | "mohamed2811/Muffakir_Embedding" |
No |
Advanced Options
config = {
# Basic
"data_dir": "documents/",
"api_key": "your_api_key",
"llm_provider": "together",
# LLM
"llm_model": "meta-llama/Llama-3.3-70B-Instruct-Turbo-Free",
"llm_temperature": 0.0,
"llm_max_tokens": 1000,
# Text Processing
"chunk_size": 600,
"chunk_overlap": 200,
"chunking_method": "recursive",
# Retrieval
"retrieval_method": "max_marginal_relevance_search",
"k": 5,
"fetch_k": 15,
# Features
"query_transformer": True,
"hallucination_check": True,
"reranking": True,
"reranking_method": "semantic_similarity"
}
๐ฏ Usage Examples
Search Similar Documents
similar_docs = rag.get_similar_documents(
query="ุงููุงููู ุงูุฌูุงุฆู",
k=3,
method="similarity_search"
)
for doc in similar_docs:
print(f"Source: {doc.metadata.get('source', 'N/A')}")
print(f"Content: {doc.page_content[:200]}...")
Add New Documents
new_docs = ["path/to/new_doc1.pdf", "path/to/new_doc2.docx"]
success = rag.add_documents(new_docs)
if success:
print("Documents added successfully!")
Customize Parameters for Asking
response = rag.ask(
"Explain neural networks.",
k=10,
retrieval_method="hybrid",
temperature=0.3
)
๐๏ธ Project Structure
muffakir-rag/
โโโ Muffakir/ # Core module
โโโ TextProcessor/ # Document processing and chunking
โโโ LLMProvider/ # Language model interfaces
โโโ Embedding/ # Embedding models and management
โโโ Generation/ # Answer generation pipeline
โโโ VectorDB/ # Vector database management
โโโ Reranker/ # Semantic reranking
โโโ RAGPipeline/ # End-to-end RAG pipeline control
โโโ PromptManager/ # Prompt templates and management
โโโ QueryTransformer/ # Query optimization and transformation
๐ Supported Providers
| Provider | Enum Name | Description |
|---|---|---|
| Together AI | TOGETHER |
Together AI LLM provider |
| OpenAI | OPENAI |
OpenAI GPT models |
| Groq | GROQ |
Groq's AI platform |
| Open Router | OPENROUTER |
Open Router API |
๐ Supported File Types
- PDF: Including OCR for scanned documents
- DOCX: Microsoft Word files
- TXT: Plain text files
- Images: Processed with Azure Computer Vision OCR
๐ Performance
- โก Fast processing of large-scale Arabic documents
- ๐ฏ Optimized for high accuracy on Arabic text
- ๐พ Efficient memory and resource usage
- ๐ Scalable to thousands of documents
๐ค Contribution
Contributions are welcome! Please:
- Fork the repository
- Create a new feature branch
- Add your improvements and tests
- Submit a pull request for review
Built with โค๏ธ for the Arabic community
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 Muffakir-0.1.4.tar.gz.
File metadata
- Download URL: Muffakir-0.1.4.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d09e5f10b88053254fa410018cea29a01c4e07c462f8958cb5fd7921fd09cca6
|
|
| MD5 |
a10d46efc2844f36f5ac27b396e471cf
|
|
| BLAKE2b-256 |
d174971faafc4885aa95316a9520a91c2681c8ecff42cde7c2a22cf339f2f254
|
File details
Details for the file Muffakir-0.1.4-py3-none-any.whl.
File metadata
- Download URL: Muffakir-0.1.4-py3-none-any.whl
- Upload date:
- Size: 38.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e32bbe759a7535227251fe8f98eaca5788d8b8319d09c63cc4cd2f16d1da047
|
|
| MD5 |
2347d790be73a21c1cf013f9a1f8f6cb
|
|
| BLAKE2b-256 |
895672688b31a154f350e791fbbad16b6aa7fb053ea0bbb4afe2d64d62640081
|