Skip to content

rac4os Documentation

rac4os is an experimental package for applying Retrieval-Augmented Generation (RAG) to classification tasks based on hierarchical statistical taxonomies. It is aimed at practitioners in official statistics, the social sciences and economics who want to use RAG-based and agentic approaches to classify data against statistical taxonomies. The package provides modular, adaptable components for modelling each stage of a RAG classification pipeline. You can use every component as it is or adapt and extend it for new use cases.

rac4os offers three approaches to classification: agentic hierarchy traversal (quickstart), linear RAG (quickstart) and agentic RAG (quickstart). Linear RAG comes in two variants, a naïve RAG implementation and a more advanced Rephrase-Retrieve-Respond RAG.

All three approaches are built on two shared components you can adapt and customize:

  • Classification system: a shared interface for working with the statistical taxonomy. It stores metadata about the taxonomy's codes and handles code lookups. It also supports more advanced operations, such as finding the child codes of a given higher-level code.
  • Retriever: used by the RAG-based approaches to find the taxonomy codes most relevant to an input text through semantic search.

Both components are built around your taxonomy. You describe a classification once — how its source file is read and how its codes nest — and all three approaches work on it without further wiring. Worked entries for three official classifications (COICOP 2018, SEA 2021, ICATUS 2016) ship with the package as examples, but none of them is a precondition for anything.

Don't hesitate to open an issue on the repository if something is broken or if you have further questions.

Usage

See also

See the Quickstart for more quick information on how to use rac4os.

Installation

You can install rac4os using pip:

pip install "rac4os[local]"

Requires Python ≥ 3.12. The core install covers only parsing and navigating taxonomies; the retrieval-based approaches need one embedding backend, which comes as an optional extra. See Installation for the other backends and for installing the current state of master from the repository.

Describing your taxonomy

from rac4os.classification_system import get_classification_system

cs = get_classification_system("SPEND_2026")       # a taxonomy you registered

cs.get_root_categories()
# [{'code': '10', 'description': 'Office supplies and consumables'},
#  {'code': '20', 'description': 'IT equipment and services'}]

cs.get_code_trace("101010")
# [('10', 'Office supplies and consumables'),
#  ('1010', 'Paper and paper products'),
#  ('101010', 'Printing and copying paper')]

Classifying an item

prediction = classifier(query="two boxes of A4 paper for the printer", k=3)

prediction.spend_code
# '101010'
prediction.explanation
# 'Chosen 101010 because the item is copying paper, which that category covers; ...'

What Next?

Consider reading one of the following sections to answer the related question:

Your own taxonomy:

Hierarchy traversal:

Linear RAG:

Agentic RAG:

Utilities:

Which approach should I use?

Approach Retrieval Loop Needs a retriever Model calls per item
Hierarchy traversal none — walks your taxonomy yes no several
Linear RAG once, on the raw item no yes one
Rephrase-Retrieve-Respond once, on a rewritten query no yes two
Agentic RAG as often as the agent calls for it yes yes several

Start with linear RAG: one retrieval call and one generation call per item, and the baseline the others have to beat. If retrieval misses because your items are worded nothing like your labels, add the Rephrase step. If retrieval misses and you cannot improve the retriever, let the agent re-query. If your taxonomy's structure carries more signal than its labels — or you have no embedding backend at all — traverse the hierarchy instead.

Citing

If you use rac4os in published work, please cite it:

@software{montag_rac4os,
  author  = {Montag, Adrian},
  title   = {{rac4os}: Retrieval Augmented Classification for Official Statistics},
  version = {0.2.16},
  year    = {2026},
  url     = {https://github.com/adimo20/rac4os},
  license = {EUPL-1.2}
}