Skip to main content

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:

  1. Fork the repository
  2. Create a new feature branch
  3. Add your improvements and tests
  4. 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

Muffakir-0.1.4.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Muffakir-0.1.4-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

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

Hashes for Muffakir-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d09e5f10b88053254fa410018cea29a01c4e07c462f8958cb5fd7921fd09cca6
MD5 a10d46efc2844f36f5ac27b396e471cf
BLAKE2b-256 d174971faafc4885aa95316a9520a91c2681c8ecff42cde7c2a22cf339f2f254

See more details on using hashes here.

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

Hashes for Muffakir-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8e32bbe759a7535227251fe8f98eaca5788d8b8319d09c63cc4cd2f16d1da047
MD5 2347d790be73a21c1cf013f9a1f8f6cb
BLAKE2b-256 895672688b31a154f350e791fbbad16b6aa7fb053ea0bbb4afe2d64d62640081

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page