Skip to main content

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:

  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:

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()

Chat Continuity And Context

How chat works today:

  • You create one RAG instance and can ask many questions without re-running setup code.
  • By default (rag_type="corrective"), each query is processed independently for retrieval/generation quality.
  • If you need conversational memory across turns, use rag_type="memory".
  • Memory is in-process; if your script exits, memory resets.

One-time / stateless style (default):

from raglib import RAG

rag = RAG(
    source="docs/",
    rag_type="corrective",  # default behavior
)

answer_1 = rag.query("What is RAG?")
answer_2 = rag.query("Give me key benefits in 3 points")

print(answer_1.answer)
print(answer_2.answer)

Continuous chat with context (memory-enabled):

from raglib import RAG

rag = RAG(
    source="docs/",
    rag_type="memory",  # keeps previous turns in the same running instance
)

turn_1 = rag.query("Summarize the architecture")
turn_2 = rag.query("Now explain that in simpler terms")

print(turn_1.answer)
print(turn_2.answer)

# Optional interactive terminal chat loop (single run, continuous session)
rag.chat()

Interactive session kill-switch commands:

  • exit
  • quit
  • q
  • bye
  • stop

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

raglib_py-0.1.10.tar.gz (61.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

raglib_py-0.1.10-py3-none-any.whl (111.0 kB view details)

Uploaded Python 3

File details

Details for the file raglib_py-0.1.10.tar.gz.

File metadata

  • Download URL: raglib_py-0.1.10.tar.gz
  • Upload date:
  • Size: 61.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for raglib_py-0.1.10.tar.gz
Algorithm Hash digest
SHA256 ce104ad95299560e94dc8b3abee8b6fee592f81cec8a4160e638a4615a813ca8
MD5 94b5e95c123b87a65cd618593c80afa5
BLAKE2b-256 226d8e2d67689d086c891eaae4b61d58b8ae9f30ce466a58cd96fa1c847a40a8

See more details on using hashes here.

File details

Details for the file raglib_py-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: raglib_py-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 111.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for raglib_py-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 5e8b54ecab264b4793786c0a41226f02fb68a31fa70169ea84bcec6d48e27c31
MD5 a01c29e2e4fd3275858ef7065960e6f2
BLAKE2b-256 a37d6e5c83f957afcf20febd01fd1be59702e015fd68defbf992093f07a16b8c

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