Metadata-Version: 2.4
Name: raglib-py
Version: 0.1.8
Summary: A modular, production-grade Retrieval-Augmented Generation library
Project-URL: Homepage, https://github.com/himanshau/raglib
Project-URL: Repository, https://github.com/himanshau/raglib
Project-URL: Bug Tracker, https://github.com/himanshau/raglib/issues
Author: raglib maintainers
License: MIT License
        
        Copyright (c) 2026 raglib maintainers
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai,llm,nlp,rag,retrieval,vector-search
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Requires-Dist: chromadb>=0.5.0
Requires-Dist: ddgs>=6.0.0
Requires-Dist: duckduckgo-search>=3.9
Requires-Dist: langchain-anthropic>=0.1.0
Requires-Dist: langchain-community>=0.4.1
Requires-Dist: langchain-core>=0.2.0
Requires-Dist: langchain-google-genai>=1.0.0
Requires-Dist: langchain-groq>=0.1.0
Requires-Dist: langchain-huggingface>=0.0.3
Requires-Dist: langchain-ollama>=0.1.0
Requires-Dist: langchain-openai>=0.1.0
Requires-Dist: pymupdf>=1.23.0
Requires-Dist: python-docx>=1.0.0
Requires-Dist: python-pptx>=0.6.21
Requires-Dist: sentence-transformers>=2.6.0
Provides-Extra: all
Requires-Dist: chromadb>=0.5.0; extra == 'all'
Requires-Dist: langchain-anthropic>=0.1.0; extra == 'all'
Requires-Dist: langchain-core>=0.2.0; extra == 'all'
Requires-Dist: langchain-google-genai>=1.0.0; extra == 'all'
Requires-Dist: langchain-groq>=0.1.0; extra == 'all'
Requires-Dist: langchain-huggingface>=0.0.3; extra == 'all'
Requires-Dist: langchain-ollama>=0.1.0; extra == 'all'
Requires-Dist: langchain-openai>=0.1.0; extra == 'all'
Requires-Dist: pillow>=10.0.0; extra == 'all'
Requires-Dist: pymupdf>=1.23.0; extra == 'all'
Requires-Dist: pytesseract>=0.3.10; extra == 'all'
Requires-Dist: python-docx>=1.0.0; extra == 'all'
Requires-Dist: python-pptx>=0.6.21; extra == 'all'
Requires-Dist: sentence-transformers>=2.6.0; extra == 'all'
Provides-Extra: all-llm
Requires-Dist: langchain-anthropic>=0.1.0; extra == 'all-llm'
Requires-Dist: langchain-core>=0.2.0; extra == 'all-llm'
Requires-Dist: langchain-google-genai>=1.0.0; extra == 'all-llm'
Requires-Dist: langchain-groq>=0.1.0; extra == 'all-llm'
Requires-Dist: langchain-ollama>=0.1.0; extra == 'all-llm'
Requires-Dist: langchain-openai>=0.1.0; extra == 'all-llm'
Provides-Extra: anthropic
Requires-Dist: langchain-anthropic>=0.1.0; extra == 'anthropic'
Provides-Extra: chroma
Requires-Dist: chromadb>=0.5.0; extra == 'chroma'
Provides-Extra: dev
Requires-Dist: build>=1.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.11.0; extra == 'dev'
Requires-Dist: pytest>=7.4.0; extra == 'dev'
Requires-Dist: twine>=4.0.0; extra == 'dev'
Provides-Extra: docx
Requires-Dist: python-docx>=1.0.0; extra == 'docx'
Provides-Extra: faiss
Requires-Dist: faiss-cpu>=1.7.0; extra == 'faiss'
Provides-Extra: free-embed
Requires-Dist: langchain-huggingface>=0.0.3; extra == 'free-embed'
Requires-Dist: sentence-transformers>=2.6.0; extra == 'free-embed'
Provides-Extra: google
Requires-Dist: langchain-google-genai>=1.0.0; extra == 'google'
Provides-Extra: groq
Requires-Dist: langchain-groq>=0.1.0; extra == 'groq'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.2.0; extra == 'langchain'
Provides-Extra: ocr
Requires-Dist: pillow>=10.0.0; extra == 'ocr'
Requires-Dist: pytesseract>=0.3.10; extra == 'ocr'
Provides-Extra: ollama
Requires-Dist: langchain-ollama>=0.1.0; extra == 'ollama'
Provides-Extra: openai
Requires-Dist: langchain-openai>=0.1.0; extra == 'openai'
Provides-Extra: pdf
Requires-Dist: pymupdf>=1.23.0; extra == 'pdf'
Provides-Extra: pptx
Requires-Dist: python-pptx>=0.6.21; extra == 'pptx'
Provides-Extra: serpapi
Requires-Dist: google-search-results>=2.4.0; extra == 'serpapi'
Provides-Extra: tavily
Requires-Dist: tavily-python>=0.2.0; extra == 'tavily'
Provides-Extra: vision
Requires-Dist: langchain-anthropic>=0.1.0; extra == 'vision'
Requires-Dist: langchain-google-genai>=1.0.0; extra == 'vision'
Requires-Dist: langchain-openai>=0.1.0; extra == 'vision'
Description-Content-Type: text/markdown

# raglib-py

raglib-py is a production-focused Retrieval-Augmented Generation library for Python.

Important naming:

- PyPI package name: raglib-py
- Python import name: raglib

## Current Support Counts

- RAG strategies: 12
- Built-in chat providers: 5
- Built-in web providers: 9 total
- Internet web providers: 8
- Offline local web provider: 1

## Web Provider Count In The Library

- Total web providers: 9
- Free default: duckduckgo
- Auth-required: tavily, serpapi, brave, bing, google_cse, exa, searxng
- Offline/local: local

## Installation

```bash
pip install raglib-py
```

Optional extras:

```bash
pip install "raglib-py[ollama]"
pip install "raglib-py[chroma]"
pip install "raglib-py[pdf,docx,pptx]"
pip install "raglib-py[all]"
```

Quick import check:

```bash
python -c "from raglib import RAG; print('OK')"
```

## Quickstart (Offline)

```python
from raglib import RAG

rag = RAG("RAG improves grounded generation using retrieved context.")
result = rag.query("What does RAG improve?")

print(result.answer)
print([doc.id for doc in result.sources])
```

## Recommended Production Input (3 Main Keys)

Use this pattern when you want cloud chat + cloud embedding + live web search:

```python
from raglib import RAG

rag = RAG(
    source="docs/",
    rag_type="web",  # web/hybrid/routing/corrective can involve web search

    # 1) Chat API key
    chat_llm="openai",
    chat_api_key="YOUR_CHAT_API_KEY",

    # 2) Embedding API key
    embedding_llm="openai",
    embedding_api_key="YOUR_EMBEDDING_API_KEY",

    # 3) Web search API key (required for authenticated web providers)
    web_search_provider="tavily",
    web_search_api_key="YOUR_WEB_SEARCH_API_KEY",

    # Optional: verify provider credentials/connectivity during init
    validate_web_search_api_key=True,
)

print(rag.query("latest AI news and key trends").answer)
```

## RAG Constructor

```python
RAG(
    source=None,
    chat_llm=None,
    embedding_llm=None,
    vision_llm=None,
    llm_key=None,
    chat_api_key=None,
    embedding_api_key=None,
    vision_api_key=None,
    rag_type="corrective",
    top_k=5,
    chunk_size=400,
    chunk_overlap=50,
    output_dir=None,
    chat_model=None,
    chat_base_url=None,
    embedding_model=None,
    embedding_base_url=None,
    vision_model=None,
    vision_base_url=None,
    web_search_provider="duckduckgo",
    web_search_api_key=None,
    web_search_base_url=None,
    web_search_cse_id=None,
    web_search_provider_kwargs=None,
    validate_web_search_api_key=False,
    vector_db=None,
    vector_db_kwargs=None,
    **rag_type_kwargs,
)
```

## API Key Rules

raglib never provides API keys. Users must provide their own valid keys.

Chat keys:

- chat_llm=openai, anthropic, groq, google -> requires chat_api_key or llm_key (or env var)
- chat_llm=ollama -> no cloud key required

Embedding keys:

- embedding_llm=openai, google -> requires embedding_api_key (or llm_key/chat_api_key/env)
- embedding_llm=ollama, huggingface/local/free, mock -> no cloud key required

Web keys:

- web_search_provider=duckduckgo -> free, no API key required
- web_search_provider=local -> offline local search over ingested docs
- web_search_provider=tavily, serpapi, brave, bing, google_cse, exa, searxng -> requires web_search_api_key
- web_search_provider=google_cse -> also requires web_search_cse_id
- web_search_provider=searxng -> may require web_search_base_url

If web provider fails at runtime, raglib returns empty web results instead of crashing the whole RAG run.

If you do not set web_search_provider, raglib defaults to duckduckgo.

## Web Providers

Supported web_search_provider values:

1. local
2. duckduckgo
3. tavily
4. serpapi
5. brave
6. bing
7. google_cse
8. exa
9. searxng

## Built-in RAG Strategies

1. naive
2. advanced
3. corrective
4. self
5. agentic
6. hybrid
7. multi_query
8. multi_hop
9. routing
10. memory
11. web
12. tool

## Common Examples

Use a free web provider:

```python
from raglib import RAG

rag = RAG(
    source="docs/",
    rag_type="web",
    chat_llm="openai",
    chat_api_key="YOUR_CHAT_API_KEY",
    embedding_llm="openai",
    embedding_api_key="YOUR_EMBEDDING_API_KEY",
    web_search_provider="duckduckgo",
)
```

Use Google CSE:

```python
from raglib import RAG

rag = RAG(
    source="docs/",
    rag_type="hybrid",
    chat_llm="openai",
    chat_api_key="YOUR_CHAT_API_KEY",
    embedding_llm="openai",
    embedding_api_key="YOUR_EMBEDDING_API_KEY",
    web_search_provider="google_cse",
    web_search_api_key="YOUR_GOOGLE_API_KEY",
    web_search_cse_id="YOUR_CSE_ID",
)
```

Use local-only web mode (offline):

```python
from raglib import RAG

rag = RAG(
    source="docs/",
    rag_type="web",
    web_search_provider="local",
)
```

## Useful Methods

- query(question)
- add(source)
- chat()

## License

MIT
