Skip to main content

A project to show good CLI practices with a fully fledged RAG system.

Project description

RAG CLI

A project to show good CLI practices with a fully fledged RAG system.

Python version PyPI version GNU GPL

RAG CLI

Installation

pip install rag-cli

Features

  • CLI tooling for RAG
  • Embedder (Ollama)
  • Vector store (Qdrant)

Usage

Docker

If you don't have a running instance of Qdrant or Ollama, you can use the provided docker-compose file to start one.

docker-compose up --build -d

This will start Ollama on http://localhost:11434 and Qdrant on http://localhost:6333.

Development

This project uses a dev container, which is the easiest way to set up a consistent development environment. Dev containers provide all the necessary tools, dependencies, and configuration, so you can focus on coding right away.

Using Dev Containers

This project uses a dev container for a consistent development environment. To get started:

  1. Open the project in Visual Studio Code.
  2. On Windows/Linux, press Ctrl+Shift+P and run the command Remote-Containers: Reopen in Container. On Mac, press Cmd+Shift+P and run the same command.
  3. VS Code will build and start the dev container, providing access to the project's codebase and dependencies.

Other editors may have similar functionality but this project is optimised for Visual Studio Code.

Embedder

Before running this command, make sure you have a running instance of Ollama and the nomic-embed-text:v1.5 model is available:

ollama pull nomic-embed-text:v1.5
rag-cli embed --ollama-url http://localhost:11434 --file <INPUT_FILE>

You can alternatively use stdin to pass the text:

cat <INPUT_FILE> | rag-cli embed --ollama-url http://localhost:11434

Vector store

rag-cli vector-store \
--qdrant-url http://localhost:6333 \
--collection-name <COLLECTION_NAME> \
--data '{<JSON_DATA>}'
--embedding <EMBEDDING_FILE>

You can alternatively use stdin to pass embeddings:

cat <INPUT_FILE> | \
rag-cli vector-store \
--qdrant-url http://localhost:6333 \
--collection-name <COLLECTION_NAME> \
--data '{<JSON_DATA>}'

End-to-end Pipeline

Here is an example of an end-to-end pipeline. It takes the following steps:

  • Get a random Wikipedia article
  • Embed the article
  • Store the embedding in Qdrant

Before running the pipeline make sure you have the following installed:

sudo apt-get update && sudo apt-get install parallel jq curl

Also make sure that the data/articles and data/embeddings directories exist:

mkdir -p data/articles data/embeddings

Then run the pipeline:

bash scripts/run_pipeline.sh

Parallel Pipeline

The script scripts/run_pipeline.sh can be run in parallel with GNU Parallel to speed up the process.

parallel -j 5 -n0 bash scripts/run_pipeline.sh ::: {0..10}

Examples

Get 10 Random Wikipedia Articles

parallel -n0 -j 10 '
curl -L -s "https://en.wikipedia.org/api/rest_v1/page/random/summary" | \
jq -r ".title, .description, .extract" | \
tee data/articles/$(cat /proc/sys/kernel/random/uuid).txt
' ::: {0..10}

Run Embedder On All Articles

parallel '
rag-cli embed --ollama-url http://localhost:11434 --file {1} 2>> output.log | \
jq ".embedding" | \
tee data/embeddings/$(basename {1} .txt) 1> /dev/null
' ::: $(find data/articles/*.txt)

Store All Embeddings In Qdrant

parallel rag-cli vector-store --qdrant-url http://localhost:6333 --collection-name nomic-embed-text-v1.5 2>> output.log ::: $(find data/embeddings/*)

End-to-end Pipeline For A Single Article

curl -L -s "https://en.wikipedia.org/api/rest_v1/page/random/summary" | \
jq -r ".title, .description, .extract" | \
rag-cli embed --ollama-url http://localhost:11434 | \
jq ".embedding" | \
rag-cli vector-store --qdrant-url http://localhost:6333 --collection-name nomic-embed-text-v1.5

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

rag_cli-0.2.4.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

rag_cli-0.2.4-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file rag_cli-0.2.4.tar.gz.

File metadata

  • Download URL: rag_cli-0.2.4.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for rag_cli-0.2.4.tar.gz
Algorithm Hash digest
SHA256 4bd76d59f03b5b281286f43e9080723c642282c4ba42b7a7fc7fe6bce92be2a4
MD5 9721bf27a8b3c6aa974745e68929e3f3
BLAKE2b-256 f1ab59bfa732f37e68723e8f7d191ca9da00434b5af40c59a67f412cd71fc592

See more details on using hashes here.

File details

Details for the file rag_cli-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: rag_cli-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for rag_cli-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8428b736bcfaa20ba12a7fb6ec73059cd907d607ccf508d2c3109bc726cd1c18
MD5 ed75d2bafedf58a08a1aca125c1e14f0
BLAKE2b-256 36d4e919ce594488177a02d4eddf2647268b3db1ef949a5c5256f35f50939c2d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page