Metadata-Version: 2.4
Name: rago
Version: 0.14.4
Summary: RAG framework
Author-email: Ivan Ogasawara <ivan.ogasawara@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/osl-incubator/rago
Project-URL: Issues, https://github.com/osl-incubator/rago/issues
Requires-Python: <4,>=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typeguard>=4.0
Requires-Dist: pydantic>=2
Requires-Dist: joblib>=1.4.2
Requires-Dist: pypdf>=5
Requires-Dist: torch>=2
Requires-Dist: langchain>=0.3.7
Requires-Dist: langchain-community>=0.3.7
Requires-Dist: instructor>=1
Requires-Dist: openai>=1.52.2
Requires-Dist: numpy<2,>=1.26; python_version < "3.13" and sys_platform == "darwin"
Requires-Dist: numpy>=2; python_version >= "3.13" and sys_platform == "darwin"
Requires-Dist: numpy<2.1,>=2; python_version < "3.10" and sys_platform != "darwin"
Requires-Dist: numpy<2.2,>=2; python_version == "3.10" and sys_platform != "darwin"
Requires-Dist: numpy>=2; python_version >= "3.11" and sys_platform != "darwin"
Requires-Dist: faiss-cpu<1.9,>=1.8.0; sys_platform == "darwin" and python_version < "3.13"
Requires-Dist: faiss-cpu>=1.9.0; sys_platform != "darwin" or python_version >= "3.13"
Requires-Dist: typing-extensions>=4.8; python_version < "3.11"
Provides-Extra: chromadb
Requires-Dist: chromadb>=0.3.23; extra == "chromadb"
Provides-Extra: google
Requires-Dist: google-generativeai>=0.8.3; extra == "google"
Provides-Extra: cohere
Requires-Dist: cohere>=5.13.4; extra == "cohere"
Provides-Extra: fireworks
Requires-Dist: fireworks-ai<1.0.0,>=0.15.11; extra == "fireworks"
Provides-Extra: together
Requires-Dist: together>=1.4.0; extra == "together"
Provides-Extra: ollama
Requires-Dist: ollama>=0.4.8; extra == "ollama"
Provides-Extra: base
Requires-Dist: transformers>=4; extra == "base"
Requires-Dist: sentence-transformers>=3.2.0; extra == "base"
Requires-Dist: sentencepiece>=0.2.0; extra == "base"
Requires-Dist: langdetect>=1; extra == "base"
Provides-Extra: all
Requires-Dist: google-generativeai>=0.8.3; extra == "all"
Requires-Dist: cohere>=5.13.4; extra == "all"
Requires-Dist: fireworks-ai<1.0.0,>=0.15.11; extra == "all"
Requires-Dist: together>=1.4.0; extra == "all"
Requires-Dist: ollama>=0.4.8; extra == "all"
Requires-Dist: spacy>=3.8.0; extra == "all"
Requires-Dist: chromadb>=0.3.23; extra == "all"
Requires-Dist: transformers>=4; extra == "all"
Requires-Dist: sentence-transformers>=3.2.0; extra == "all"
Requires-Dist: sentencepiece>=0.2.0; extra == "all"
Requires-Dist: langdetect>=1; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=6; extra == "dev"
Requires-Dist: pytest-cov>=6.2; extra == "dev"
Requires-Dist: coverage>=7.10; extra == "dev"
Requires-Dist: pre-commit>=4.3; extra == "dev"
Requires-Dist: ruff>=0.12.0; extra == "dev"
Requires-Dist: mypy>=1.17.0; extra == "dev"
Requires-Dist: bandit>=1.8; extra == "dev"
Requires-Dist: vulture>=2.14; extra == "dev"
Requires-Dist: mccabe>=0.7; extra == "dev"
Requires-Dist: ipython>=6; extra == "dev"
Requires-Dist: ipykernel>=5; extra == "dev"
Requires-Dist: python-dotenv>=1.1; extra == "dev"
Requires-Dist: Jinja2>=3.1.2; extra == "dev"
Requires-Dist: makim==1.27.0; extra == "dev"
Requires-Dist: mkdocs>=1.6; extra == "dev"
Requires-Dist: mkdocs-exclude>=1.0.2; extra == "dev"
Requires-Dist: mkdocs-jupyter>=0.25; extra == "dev"
Requires-Dist: mkdocs-literate-nav>=0.6; extra == "dev"
Requires-Dist: mkdocs-macros-plugin>=1.3; extra == "dev"
Requires-Dist: mkdocs-material>=9.6; extra == "dev"
Requires-Dist: mkdocstrings>=0.30; extra == "dev"
Requires-Dist: mkdocstrings-python>=1.17; extra == "dev"
Requires-Dist: mkdocs-gen-files>=0.5.0; extra == "dev"
Requires-Dist: build>=1.3.0; extra == "dev"
Requires-Dist: twine>=6.1.0; extra == "dev"
Dynamic: license-file

# Rago

![CI](https://img.shields.io/github/actions/workflow/status/osl-incubator/rago/main.yaml?logo=github&label=CI)
[![Python Versions](https://img.shields.io/pypi/pyversions/rago)](https://pypi.org/project/rago/)
[![Package Version](https://img.shields.io/pypi/v/rago?color=blue)](https://pypi.org/project/rago/)
![License](https://img.shields.io/pypi/l/rago?color=blue)
[![Discord](https://img.shields.io/discord/796786891798085652?logo=discord&color=blue)](https://opensciencelabs.org/discord)

Rago is a lightweight framework for RAG.

- Software License: BSD 3 Clause
- Documentation: https://osl-incubator.github.io/rago

## Features

- Vector Database support
  - FAISS
- Retrieval features
  - Support pdf extraction via langchain
- Augmentation (Embedding + Vector Database Search)
  - Support for Sentence Transformer (Hugging Face)
  - Support for Open AI
  - Support for SpaCy
- Generation (LLM)
  - Support for Hugging Face
  - Support for llama (Huggin FAce)
  - Support for OpenAI
  - Support for Gemini

## Roadmap

### 1. Add new Backends

As noted in several GitHub issues, our initial goal is to support as many
backends as possible. This approach will provide valuable insights into user
needs and inform the structure for the next phase.

### 2. Declarative API for Rago

#### Objective

To simplify and streamline the user experience in configuring RAG by introducing
a declarative, composable API—similar to how Plotnine or Altair allows users to
build visualizations.

#### Overview

The current procedural approach in Rago requires users to instantiate and
connect individual components (retrieval, augmentation, generation, etc.)
manually. This can become cumbersome as support for multiple backends grows. We
propose a new declarative interface that lets users define their entire RAG
steps in a single, fluent expression using operator overloading.

#### Proposed Syntax Example

```python
from rago import Rago, Retrieval, Augmentation, Generation, DB, Cache

datasource = ...

rag = (
    Rago()
    + DB(backend="faiss", top_k=5)
    + Cache(backend="file")
    + Retrieval(backend="dummy")
    + Augmentation(backend="openai", model="text-embedding-3-small")
    + Generation(
        backend="openai",
        model="gpt-4o-mini",
        prompt_template="Question: {query}\nContext: {context}\nAnswer:"
    )
)

result = rag.run(query="What is the capital of France?", data=datasource)
```

#### Key Benefits

- **Intuitive Composition:** Users can build complex pipelines by simply adding
  layers together.
- **Modularity:** Each component is encapsulated, making it easy to swap or
  extend backends without altering the overall architecture.
- **Reduced Boilerplate:** The declarative syntax minimizes the need for
  repetitive setup code, focusing on the "what" rather than the "how."
- **Enhanced Readability:** The pipeline’s structure becomes immediately clear,
  promoting easier maintenance and collaboration.

#### Implementation Plan

1. **Define Base Classes:** Develop abstract base classes for each component
   (DB, Cache, Retrieval, Augmentation, Generation) to standardize interfaces
   and facilitate future extensions.
2. **Operator Overloading:** Implement the `__add__` method in the main `Rago`
   class to allow chaining of components, effectively building the pipeline
   through a fluent interface.
3. **Configuration and Defaults:** Integrate sensible defaults and validation
   (using tools like Pydantic) so that users can override only when necessary.
4. **Documentation and Examples:** Provide comprehensive documentation and
   examples to illustrate the new declarative syntax and usage scenarios.

## Installation

If you want to install it for `cpu` only, you can run:

```bash
$ pip install rago[cpu]
```

But, if you want to install it for `gpu` (cuda), you can run:

```bash
$ pip install rago[gpu]
```

## Setup

### Llama 3

In order to use a llama model, visit its page on huggingface and request your
access in its form, for example: https://huggingface.co/meta-llama/Llama-3.2-1B.

After you are granted access to the desired model, you will be able to use it
with Rago.

You will also need to provide a hugging face token in order to download the
models locally, for example:

```python

from rago import Rago
from rago.generation import LlamaGen
from rago.retrieval import StringRet
from rago.augmented import SentenceTransformerAug

# For Gated LLMs
HF_TOKEN = 'YOUR_HUGGING_FACE_TOKEN'

animals_data = [
    "The Blue Whale is the largest animal ever known to have existed, even "
    "bigger than the largest dinosaurs.",
    "The Peregrine Falcon is renowned as the fastest animal on the planet, "
    "capable of reaching speeds over 240 miles per hour.",
    "The Giant Panda is a bear species endemic to China, easily recognized by "
    "its distinctive black-and-white coat.",
    "The Cheetah is the world's fastest land animal, capable of sprinting at "
    "speeds up to 70 miles per hour in short bursts covering distances up to "
    "500 meters.",
    "The Komodo Dragon is the largest living species of lizard, found on "
    "several Indonesian islands, including its namesake, Komodo.",
]

rag = Rago(
    retrieval=StringRet(animals_data),
    augmented=SentenceTransformerAug(top_k=2),
    generation=LlamaGen(api_key=HF_TOKEN),
)
rag.prompt('What is the faster animal on Earth?')
```

### Ollama

For testing the generation with Ollama, run first the following commands:

```bash
$ ollama pull llama3.2:1b
$ ollama serve
```
