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.5.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.5-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file Muffakir-0.1.5.tar.gz.

File metadata

  • Download URL: Muffakir-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 82d1d74127bfdd40ff2e9b66a034389ea34761bbd2eb24760324728a4a9288b0
MD5 4642b48dad01b279707ca40cd14d2d05
BLAKE2b-256 6b7f39eebf917d657bad1aac8a38d6d37dc1e39a6ac080702cacde8cfe098585

See more details on using hashes here.

File details

Details for the file Muffakir-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: Muffakir-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 37.9 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a06007f62966738cffab9c3b43e41764ff66c8ea63d9c108220bece253b38172
MD5 794bc896a3af83369b576332fc2b7fb0
BLAKE2b-256 a4e1c7d731780b5dbe8e1b0c1e4d1079394b2fc7c273fc6cce4b334989e3bab4

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