A modular, production-grade Retrieval-Augmented Generation library
Project description
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
pip install raglib-py
Optional extras:
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:
python -c "from raglib import RAG; print('OK')"
Quickstart (Offline)
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:
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
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:
- local
- duckduckgo
- tavily
- serpapi
- brave
- bing
- google_cse
- exa
- searxng
Built-in RAG Strategies
- naive
- advanced
- corrective
- self
- agentic
- hybrid
- multi_query
- multi_hop
- routing
- memory
- web
- tool
Common Examples
Use a free web provider:
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:
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):
from raglib import RAG
rag = RAG(
source="docs/",
rag_type="web",
web_search_provider="local",
)
Useful Methods
- query(question)
- add(source)
- chat()
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raglib_py-0.1.8.tar.gz.
File metadata
- Download URL: raglib_py-0.1.8.tar.gz
- Upload date:
- Size: 60.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29668cce88b83410540d45c55a629fdba24b00798f33504cd529d73867e2dddf
|
|
| MD5 |
614c23ef5ba57d2360a4c5ed3a38ea55
|
|
| BLAKE2b-256 |
09d4c099e0b2c09222be615ec0577c08b2fb42254ceb0209f5bac1e510efdf2e
|
File details
Details for the file raglib_py-0.1.8-py3-none-any.whl.
File metadata
- Download URL: raglib_py-0.1.8-py3-none-any.whl
- Upload date:
- Size: 110.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d770293176dbbca4e886223f3969bcbdcd0e47b5d3b3bd03afea72e2e6146f45
|
|
| MD5 |
4577ddc3fea24621deea8a704b9e9eb5
|
|
| BLAKE2b-256 |
79e43adc7e9e9317e2f66371615a9c54671b33d574d00a1742c3426efb66ea82
|