Reconquer your documents with Ragna
Tags: ai, rag, ragna, llm
Published: 2023-11-22 12:41:17

Ragna, a very [young project](https://quansight.com/post/unveiling-ragna-an-open-source-rag-based-ai-orchestration-framework-designed-to-scale-from-research-to-production/) announced at the end of October 2023, demonstrates its power and user-friendly nature in this brief tutorial.

![Ragna Logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76ro7ytpssve4cqwus42.png)

It draws from the expertise of professionals experienced in LLM projects and RAG applications. Unlike generic frameworks like LangChain or LlamaIndex, Ragna involves less abstraction, facilitating faster prototyping with CLI tools for easier configuration, while maintaining a scalable architecture.

![Ragna Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37dsyz30iu79uaeh4lqd.png)

In the diagram from Ragna's official website, we see various components connected through an API, utilizing concepts of queues and workers to enhance scalability.

Ragna is developed in Python and is distributed under a BSD-3-Clause license.

## Install

For local installation, follow these steps, elaborated further than the [official documentation](https://ragna.chat/en/stable/install/):

- Install Ragna and its dependencies:
```bash
pip install 'ragna[all]'
```

- Address any dependency issues, such as with *jinja2*:
```bash
pip install jinja2==3.1.2
```

- Initialize the configuration file using the `ragna init` CLI:
```bash
$ ragna init
				Welcome to the Ragna config creation wizard!

I'll help you create a configuration file to use with ragna.
Due to the large amount of parameters, I unfortunately can't cover everything. If you want to customize
everything, please have a look at the documentation instead.

? Which of the following statements describes best what you want to do? I want to try Ragna and its builtin source storages and assistants, which potentially require additional dependencies or setup.

ragna has the following components builtin. Select the ones that you want to use. If the requirements of a
selected component are not met, I'll show you instructions how to meet them later.

? Which source storages do you want to use? [Chroma]

? Which assistants do you want to use? [OpenAI/gpt-4]

The output path /home/raph/Dev/ragna/ragna.toml already exists and you didn't pass the --force flag to
overwrite it.

? What do you want to do? Overwrite the existing file.

And with that we are done 🎉 I'm writing the configuration file to /home/raph/Dev/ragna/ragna.toml.
```

You can choose different options or directly edit the `ragna.toml` file. For using the GPT-4 model, provide your OpenAI API key:
```bash
export OPENAI_API_KEY="sk-<the-rest-of-the-key>"
```

Verify Ragna's configuration with the `ragna check` command:
```bash
$ ragna check
                       source storages
┏━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    ┃ name   ┃ environment variables ┃ packages            ┃
┡━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ ✅ │ Chroma │                       │ ✅ chromadb>=0.4.13 │
│    │        │                       │ ✅ tiktoken         │
└────┴────────┴───────────────────────┴─────────────────────┘
                       assistants
┏━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃    ┃ name         ┃ environment variables ┃ packages ┃
┡━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ ✅ │ OpenAI/gpt-4 │ ✅ OPENAI_API_KEY     │          │
└────┴──────────────┴───────────────────────┴──────────┘
```

## Use

To start using Ragna:

- Start the API component:
```bash
$ ragna api
INFO:   RagnaDemoAuthentication: You can log in with any username and a matching password.
INFO:     Started server process [4016]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:31476 (Press CTRL+C to quit)
```

Ragna's REST API is detailed in the [OpenAPI format](https://ragna.chat/en/stable/references/rest-api/). The project also offers a [Python API](https://ragna.chat/en/stable/references/python-api/).

- Use the built-in Web UI:
```bash
$ ragna ui
Launching server at http://localhost:31477
```

You can now log in and start chats by uploading documents:

![Upload Document](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbvtdfcapb06zfev0b3d.png)

And querying their content:

![Chat with Document](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49j9cyfilgaj7830shbg.png)

## Extend

Ragna's architecture facilitates easy extension. Its dynamic community is likely to soon offer new features, vectorstores, and models.

Inspired by an [article](https://blog.beachgeek.co.uk/getting-started-with-ragna/), I was able to easily add basic Azure OpenAI support:

![Azure OpenAI Support](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/px7ku16mo4lotyiz7gld.png)

And to connect Ragna to my company instance:

![Chat with Azure OpenAI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlrnv0nl1qj6psao2rk3.png)

---

In conclusion, Ragna stands out as a robust and versatile tool for RAG orchestration, offering ease of use and extensibility, which positions it as a promising asset for AI-enhanced document management.