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" No
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="Artificial Intelligence",
    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.2.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.2-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Muffakir-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 0a05c384876201e5b49a00160218cc2bf73d44494eb51508285dac8f06e02441
MD5 373922789da3d71d6d4cc57a405a3ea4
BLAKE2b-256 087ef9ec25e91f81abc665c8629331d6c45520d851651a7947539328c8ec6c5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Muffakir-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8c3b3a909ab5e0062727feccd89fffb7ee21819db891f2f5998510bf28c8d740
MD5 a255da2b02464a69cd53aa44488fd792
BLAKE2b-256 13e34f7e347e30aa919fa944dbb789bb8eb43f8ffc9ad93788f861dafd1446f6

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