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.3.tar.gz (25.7 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.3-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Muffakir-0.1.3.tar.gz
  • Upload date:
  • Size: 25.7 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.3.tar.gz
Algorithm Hash digest
SHA256 34c7ac93d57dad4db5e3a8093194a33aa1d61ffd5b709152b5778c499ed57670
MD5 4f03f45d7d71e2f642c6bc77e034a101
BLAKE2b-256 70ce65c9be560a35867fc493908169ac59f604d5689c155e0c2ac81565adfd6f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Muffakir-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 29.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ef76aca1f982f151397653f587b4725bd87c4af6088798bd67097d18b8276234
MD5 7d1628ae45f54aaec1bc696c41737acc
BLAKE2b-256 ae130c2e04e5d38fcec2118f25dbe8a2f2f069398d667c9ef6197151505518f7

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