Skip to main content

RankFlow

pypi version badge python version badge license badge monthly downloads badge

Library for plotting multiple ranks evolved over processing steps - drawing a rankflow.

RankFlow

RankFlow is a Python package that allows you to create rank flow plots (bump charts), helping visualize the changes in ranking of nodes.

Initially it was applied to re-ranking visualization of nodes (parts of documents, document chunks) during the retrieval and re-ranking processes within a Retrieval Augmented Generation (RAG) retriever, but the usage is not limited to RAG.

⭐️ Please star the repository if you find it useful.

Installation

pip install rankflow

Usage

plot from pandas DataFrame

Start with creating pandas DataFrame with ranks for each document at each step.

import pandas as pd
import matplotlib.pyplot as plt
from rankflow import RankFlow

data = {"Doc 1": [2, 1, 3, 2], "Doc 2": [1, 2, 1, 3], "Doc 3": [3, 3, 2, 1]}
df = pd.DataFrame(data, index=["Step_1", "Step_2", "Step_3", "Step_4"])

This creates the following DataFrame:

NOTE: The rows of the DataFrame are the steps and the columns are the documents. The values are the ranks of the documents at each step. Remember to define proper column names and index values since they will be used as labels in the plot.

When the DataFrame is ready, then it is time to create RankFlow object and call plot() method.

rf = RankFlow(df=df)
rf.plot()

# save the plot to png
plt.savefig("rankflow.png")

plt.show()

Here is the expected output:

plot from numpy array

You can also create RankFlow object without using pandas DataFrame. You can pass numpy array with ranks for each document at each step and provide labels for steps and documents.

import matplotlib.pyplot as plt
from rankflow import RankFlow
import numpy as np

my_step_labels: list[str] = [
    "Hybrid Search",
    "Cross-encoder",
    "Graph-reranker",
    "Booster",
]
my_chunk_labels: list[str] = [
    "Doc 0",
    "Doc 1",
    "Doc 2",
    "Doc 3",
    "Doc 4",
    "Doc 5",
    "Doc 6",
    "Doc 7",
    "Doc 8",
    "Doc 9",
]
my_ranks = np.array(
    [
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [3, 0, 2, 4, 1, 6, 7, 9, 5, 8],
        [2, 3, 0, 4, 6, 1, 7, 8, 5, 9],
        [5, 3, 2, 1, 0, 4, 6, 7, 8, 9],
    ]
)

rf = RankFlow(
    ranks=my_ranks,
    step_labels=my_step_labels,
    chunk_labels=my_chunk_labels,
    fig_size=(6, 6),
    title_font_size=24,
)
_ = rf.plot()
plt.show()

This should produce the following plot:

RankFlow

License

MIT © Krystian Safjan.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rankflow-0.1.3.tar.gz (60.7 kB view details)

Uploaded Source

Built Distribution

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

rankflow-0.1.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file rankflow-0.1.3.tar.gz.

File metadata

  • Download URL: rankflow-0.1.3.tar.gz
  • Upload date:
  • Size: 60.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.16.1 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for rankflow-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f49b87e69d0ea5484dc9431d205a3e2bcbee79ceeb8970691280f15d4f960b7e
MD5 830eeab3a4f36cd7628754ee3cd4e02e
BLAKE2b-256 a0a6354b0e7ba0e5edc43b49c0e18ac5c402f3bd4bea402c4b7682188f647dd7

See more details on using hashes here.

File details

Details for the file rankflow-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: rankflow-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.16.1 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for rankflow-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dd21ea66fa26611ee05c9456ecd1478dad1bb124ed9a45c8b90f7add82724d3e
MD5 1a579d74714f2b1bc93bbcefa7b9c7ea
BLAKE2b-256 bc0983eb319d3cf640fbfaf01ef94560e8b709b7a773f285211fc0e3449f60fd

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 Sentry Error logging StatusPage Status page