{"id":18538108,"url":"https://github.com/bigmb/mb_rag","last_synced_at":"2026-04-02T12:05:19.864Z","repository":{"id":250967283,"uuid":"833712228","full_name":"bigmb/mb_rag","owner":"bigmb","description":"RAG files for mb","archived":false,"fork":false,"pushed_at":"2026-03-24T19:44:49.000Z","size":39826,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-26T00:58:28.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigmb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-25T15:34:40.000Z","updated_at":"2026-03-24T19:44:51.000Z","dependencies_parsed_at":"2024-07-31T03:58:08.875Z","dependency_job_id":"6c5e3e92-be87-487b-9f7e-500a80a1fd68","html_url":"https://github.com/bigmb/mb_rag","commit_stats":null,"previous_names":["bigmb/mb_rag"],"tags_count":243,"template":false,"template_full_name":null,"purl":"pkg:github/bigmb/mb_rag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmb%2Fmb_rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmb%2Fmb_rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmb%2Fmb_rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmb%2Fmb_rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigmb","download_url":"https://codeload.github.com/bigmb/mb_rag/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmb%2Fmb_rag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31305973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T09:48:21.550Z","status":"ssl_error","status_checked_at":"2026-04-02T09:48:19.196Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T19:42:21.832Z","updated_at":"2026-04-02T12:05:19.856Z","avatar_url":"https://github.com/bigmb.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MB-RAG: Modular Building Blocks for Retrieval-Augmented Generation\n\nMB-RAG is a flexible Python package that provides modular building blocks for creating RAG (Retrieval-Augmented Generation) applications. It integrates multiple LLM providers, embedding models, and utility functions to help you build powerful AI applications.\n\n## Features\n\n- **Multiple LLM Support**: \n  - OpenAI (GPT-4, GPT-3.5)\n  - Anthropic (Claude)\n  - Google (Gemini)\n  - Ollama (Local models)\n  - Groq\n\n- **RAG Capabilities**:\n  - Text splitting and chunking\n  - Multiple embedding models\n  - Vector store integration\n  - Conversation history management\n  - Context-aware retrieval\n\n- **Image Processing**:\n  - Bounding box generation with Gemini Vision\n  - Custom image annotations\n  - Multiple output formats\n  - Batch processing capabilities\n\n## Installation\n\n1. Basic Installation:\n```bash\npip install mb_lang\n```\n\n## Quick Start\n\n### Basic Chat Examples\n## check example_llm.ipynb for more details\n```python\nfrom mb.lang.basic import ModelFactory\n\n# 1. Simple Query with ModelFactory\nmodel = ModelFactory(model_type=\"openai\", model_name=\"gpt-4o\")\nresponse = model.invoke_query(\"What is artificial intelligence?\")\nprint(response)\n\n# 2. Image Analysis\nmodel = ModelFactory(model_type=\"openai\", model_name=\"gpt-4o\")\nresponse = model.invoke_query(\n    \"What's in these images?\",\n    images=[\"image1.jpg\", \"image2.jpg\"]\n)\nprint(response)\n\n## other models\n# Anthropic Claude\nclaude_model = ModelFactory(\n    model_type=\"anthropic\",\n    model_name=\"claude-3-opus-20240229\"\n)\nresponse = claude_model.invoke_query(\"Explain quantum computing\")\n\n# Google Gemini\ngemini_model = ModelFactory(\n    model_type=\"google\",\n    model_name=\"gemini-1.5-pro-latest\"\n)\nresponse = gemini_model.invoke_query(\"Describe the solar system\")\n\n# Local Ollama\nollama_model = ModelFactory(\n    model_type=\"ollama\",\n    model_name=\"llama3.1\"\n)\nresponse = ollama_model.invoke_query(\"What is the meaning of life?\")\n\n## Running in threads \nresponse = model.invoke_query_threads(query_list=['q1','q2'],input_data=[[images_data],[images_data]],n_workers=4)\n\n\n## check example_conversation.ipynb for more details\n\nfrom mb.lang.chatbot.conversation import ConversationModel\n# 3. Conversation with Context : if file_path/message_list is not provided, it will create a new conversation\nconversation = ConversationModel(llm=ModelFactory(model_type=\"openai\", model_name=\"gpt-4o\"),\n                                file_path=None,\n                                message_list=None)\n\nconversation.initialize_conversation()\n\n# Continue the conversation\nresponse = conversation.add_message(\"How is it different from deep learning?\")\nprint(response)\n\n# Access conversation history\nprint(\"\\nAll messages:\")\nfor message in conversation.all_messages_content:\n    print(message)\n\n# Save conversation\nconversation.save_conversation(\"chat_history.txt\")\n\n```\n\n### Embeddings and RAG Example\n```python\nfrom mb.lang.rag.embeddings import embedding_generator\n\n# Initialize embedding generator\nem_gen = embedding_generator(\n    model=\"openai\",\n    model_type=\"text-embedding-3-small\",\n    vector_store_type=\"chroma\"\n)\n\n# Generate embeddings from text files\nem_gen.generate_text_embeddings(\n    text_data_path=['./data.txt'],\n    chunk_size=500,\n    chunk_overlap=5,\n    folder_save_path='./embeddings'\n)\n\n# Load embeddings and create retriever\nem_loading = em_gen.load_embeddings('./embeddings')\nem_retriever = em_gen.load_retriever(\n    './embeddings',\n    search_params=[{\"k\": 2, \"score_threshold\": 0.1}]\n)\n\n# Generate RAG chain for conversation\nrag_chain = em_gen.generate_rag_chain(retriever=em_retriever)\n\n# Have a conversation with context\nresponse = em_gen.conversation_chain(\n    \"What is this document about?\",\n    rag_chain,\n    file='conversation_history.txt'  # Optional: Save conversation\n)\n\n# Query specific information\nresults = em_gen.query_embeddings(\n    \"What are the key points discussed?\",\n    em_retriever\n)\n\n# Add new data to existing embeddings\nem_gen.add_data(\n    './embeddings',\n    ['new_data.txt'],\n    chunk_size=500\n)\n\n# Web scraping and embedding\ndb = em_gen.firecrawl_web(\n    website=\"https://github.com\",\n    mode=\"scrape\",\n    file_to_save='./web_embeddings'\n)\n```\n\n### Image Processing with Bounding Boxes\n```python\nfrom mb.lang.utils.bounding_box import BoundingBoxProcessor, BoundingBoxConfig\n\n# Initialize processor with configuration\nconfig = BoundingBoxConfig(\n    model_name=\"gemini-1.5-pro-latest\",\n    api_key=\"your-api-key\"  # Or use environment variable GOOGLE_API_KEY\n)\nprocessor = BoundingBoxProcessor(config)\n\n# Generate bounding boxes\nboxes = processor.generate_bounding_boxes(\n    \"image.jpg\",\n    prompt=\"Return bounding boxes of objects\"\n)\n\n# Add boxes to image with custom styling\nprocessed_img = processor.add_bounding_boxes(\n    \"image.jpg\",\n    boxes,\n    color=(0, 255, 0),  # Green color\n    thickness=2,\n    font_scale=0.5,\n    show=True  # Display result\n)\n\n# Save processed image\nprocessor.save_image(processed_img, \"output.jpg\")\n\n# Complete processing pipeline\nresult = processor.process_image(\n    \"image.jpg\",\n    output_path=\"result.jpg\",\n    show=True\n)\n\n# Batch processing\ndef batch_process_images(processor, image_paths, output_dir, **kwargs):\n    \"\"\"Process multiple images with same settings.\"\"\"\n    import os\n    os.makedirs(output_dir, exist_ok=True)\n    \n    results = []\n    for img_path in image_paths:\n        try:\n            output_path = os.path.join(\n                output_dir,\n                f\"processed_{os.path.basename(img_path)}\"\n            )\n            result = processor.process_image(\n                img_path,\n                output_path=output_path,\n                **kwargs\n            )\n            results.append((img_path, output_path, True))\n        except Exception as e:\n            results.append((img_path, None, False))\n            print(f\"Error processing {img_path}: {e}\")\n    return results\n\n# Example batch processing\nimages = [\"image1.jpg\", \"image2.jpg\", \"image3.jpg\"]\nresults = batch_process_images(\n    processor,\n    images,\n    \"./batch_output\",\n    show=False\n)\n```\n\n## Package Structure\n\n```\nmb/lang/\n├── __init__.py\n├── basic.py                    # Multi-provider LLM factory (OpenAI, Anthropic, Google, Ollama, Groq, DeepSeek, Qwen, HuggingFace)\n├── prompts_bank.py             # Prompt template storage and rendering\n├── version.py                  # Package version constants\n├── agents/\n│   ├── __init__.py\n│   ├── bb_autolabel.py         # Bounding box auto-labeling agent with LangGraph\n│   ├── get_langsmith.py        # LangSmith environment configuration\n│   ├── middleware.py           # SQL guard rails, logging, and timing middleware\n│   ├── run_agent.py            # Base agent runner\n│   ├── seg_autolabel.py        # SAM2 segmentation auto-labeling agent\n│   ├── sql_agents.py           # SQL query agent\n│   ├── tools.py                # Agent tools (SQL, bounding box, segmentation)\n│   └── web_browser_agent.py    # Web browsing agent with DuckDuckGo and LangGraph\n├── chatbot/\n│   ├── __init__.py\n│   ├── chains.py               # LangChain chaining utilities (sequential, parallel, branching)\n│   └── conversation.py         # Conversation management with local/S3 persistence\n├── rag/\n│   ├── __init__.py\n│   └── embeddings.py           # RAG embeddings engine (Chroma, text splitting, FireCrawl)\n└── utils/\n    ├── __init__.py\n    ├── all_data_extract.py     # Document extraction via Docling\n    ├── bounding_box.py         # Bounding box generation with Gemini Vision\n    ├── document_extract.py     # CSV and PowerPoint extraction\n    ├── extra.py                # Environment loading, package checks, PDF conversion, SAM2 processing\n    ├── llm_wrapper.py          # LLM wrapper for LangChain agent compatibility\n    ├── pdf_extract.py          # PDF extraction (pypdf, pdfplumber, pymupdf)\n    └── viewer.py               # LangGraph visualization utilities\n```\n\n## Dependencies\n\nCore dependencies:\n- langchain-core\n- langchain-community\n- langchain\n- python-dotenv\n\nOptional dependencies by feature:\n- Language Models: langchain-openai, langchain-anthropic, langchain-google-genai, langchain-ollama\n- Image Processing: Pillow, opencv-python, google-generativeai\n- Vector Stores: chromadb\n- Web Tools: firecrawl\n\nSee `requirements.txt` for a complete list.\n\n## Environment Setup\n\nCreate a `.env` file in your project root:\n```env\nOPENAI_API_KEY=your_openai_key\nANTHROPIC_API_KEY=your_anthropic_key\nGOOGLE_API_KEY=your_google_key\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigmb%2Fmb_rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigmb%2Fmb_rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigmb%2Fmb_rag/lists"}