rac4os 0.2.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. rac4os-0.2.16/LICENSE +128 -0
  2. rac4os-0.2.16/NOTICE.md +30 -0
  3. rac4os-0.2.16/PKG-INFO +165 -0
  4. rac4os-0.2.16/README.md +124 -0
  5. rac4os-0.2.16/pyproject.toml +55 -0
  6. rac4os-0.2.16/rac4os/__init__.py +23 -0
  7. rac4os-0.2.16/rac4os/__version__.py +6 -0
  8. rac4os-0.2.16/rac4os/_data/COICOP_2018_English_structure.xlsx +0 -0
  9. rac4os-0.2.16/rac4os/_data/UNSD_Time_Use_Statistics.csv +231 -0
  10. rac4os-0.2.16/rac4os/_data/__init__.py +0 -0
  11. rac4os-0.2.16/rac4os/_data/sea2021.xml +16802 -0
  12. rac4os-0.2.16/rac4os/_data/sea_2021_augmented.json +21667 -0
  13. rac4os-0.2.16/rac4os/_shared/Code.py +44 -0
  14. rac4os-0.2.16/rac4os/_shared/__init__.py +1 -0
  15. rac4os-0.2.16/rac4os/_vector_database/Retriever.py +91 -0
  16. rac4os-0.2.16/rac4os/_vector_database/__init__.py +0 -0
  17. rac4os-0.2.16/rac4os/_vector_database/vector_store.py +233 -0
  18. rac4os-0.2.16/rac4os/agents/HierarchicalNavigation/BaseAgent.py +171 -0
  19. rac4os-0.2.16/rac4os/agents/HierarchicalNavigation/HierarchicalNavigationAgent.py +43 -0
  20. rac4os-0.2.16/rac4os/agents/HierarchicalNavigation/__init__.py +3 -0
  21. rac4os-0.2.16/rac4os/agents/HierarchicalNavigation/registry.py +603 -0
  22. rac4os-0.2.16/rac4os/agents/RAG/BaseAgentRAG.py +153 -0
  23. rac4os-0.2.16/rac4os/agents/RAG/RAGAgent.py +58 -0
  24. rac4os-0.2.16/rac4os/agents/RAG/__init__.py +0 -0
  25. rac4os-0.2.16/rac4os/agents/RAG/registry.py +316 -0
  26. rac4os-0.2.16/rac4os/agents/__init__.py +0 -0
  27. rac4os-0.2.16/rac4os/classification_system/BaseClassificationSystem.py +281 -0
  28. rac4os-0.2.16/rac4os/classification_system/__init__.py +2 -0
  29. rac4os-0.2.16/rac4os/classification_system/mapping.py +52 -0
  30. rac4os-0.2.16/rac4os/classification_system/registry.py +69 -0
  31. rac4os-0.2.16/rac4os/classification_system/systems/ClassificationSystems.py +126 -0
  32. rac4os-0.2.16/rac4os/classification_system/systems/__init__.py +0 -0
  33. rac4os-0.2.16/rac4os/dataloaders/BaseDataLoader.py +37 -0
  34. rac4os-0.2.16/rac4os/dataloaders/__init__.py +7 -0
  35. rac4os-0.2.16/rac4os/dataloaders/loaders/CoicopDataLoader.py +52 -0
  36. rac4os-0.2.16/rac4os/dataloaders/loaders/ICATUSLoader.py +64 -0
  37. rac4os-0.2.16/rac4os/dataloaders/loaders/KlassServerDataLoader.py +105 -0
  38. rac4os-0.2.16/rac4os/dataloaders/loaders/PredefinedJsonLoader.py +38 -0
  39. rac4os-0.2.16/rac4os/dataloaders/loaders/__init__.py +0 -0
  40. rac4os-0.2.16/rac4os/dataloaders/registry.py +52 -0
  41. rac4os-0.2.16/rac4os/inference/__init__.py +3 -0
  42. rac4os-0.2.16/rac4os/inference/parallel_inference.py +53 -0
  43. rac4os-0.2.16/rac4os/rag/BaseRAG.py +153 -0
  44. rac4os-0.2.16/rac4os/rag/RAG.py +252 -0
  45. rac4os-0.2.16/rac4os/rag/__init__.py +0 -0
  46. rac4os-0.2.16/rac4os/rag/registry.py +368 -0
  47. rac4os-0.2.16/rac4os/taxonomy_refinement/TaxonomyRefinement.py +162 -0
  48. rac4os-0.2.16/rac4os/taxonomy_refinement/__init__.py +0 -0
  49. rac4os-0.2.16/rac4os.egg-info/PKG-INFO +165 -0
  50. rac4os-0.2.16/rac4os.egg-info/SOURCES.txt +62 -0
  51. rac4os-0.2.16/rac4os.egg-info/dependency_links.txt +1 -0
  52. rac4os-0.2.16/rac4os.egg-info/requires.txt +20 -0
  53. rac4os-0.2.16/rac4os.egg-info/top_level.txt +1 -0
  54. rac4os-0.2.16/setup.cfg +4 -0
  55. rac4os-0.2.16/tests/test_agents.py +177 -0
  56. rac4os-0.2.16/tests/test_classification_system.py +194 -0
  57. rac4os-0.2.16/tests/test_code.py +50 -0
  58. rac4os-0.2.16/tests/test_dataloaders.py +102 -0
  59. rac4os-0.2.16/tests/test_hierarchy_rules.py +34 -0
  60. rac4os-0.2.16/tests/test_inference.py +61 -0
  61. rac4os-0.2.16/tests/test_integration.py +81 -0
  62. rac4os-0.2.16/tests/test_packaging.py +122 -0
  63. rac4os-0.2.16/tests/test_rag.py +223 -0
  64. rac4os-0.2.16/tests/test_vector_store.py +180 -0
rac4os-0.2.16/LICENSE ADDED
@@ -0,0 +1,128 @@
1
+ Licence text
2
+ European Union Public Licence v. 1.2
3
+
4
+ EUPL © the European Union 2007, 2016
5
+
6
+ This European Union Public Licence (the 'EUPL') applies to the Work (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work).
7
+
8
+ The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Work:
9
+
10
+ Copyright (c) 2026 Adrian Montag
11
+ Licensed under the EUPL
12
+
13
+ or has expressed by any other means his willingness to license under the EUPL.
14
+
15
+ 1. Definitions
16
+ In this Licence, the following terms have the following meaning:
17
+
18
+ — 'The Licence': this Licence.
19
+ — 'The Original Work': the work or software distributed or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be.
20
+ — 'Derivative Works': the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15.
21
+ — 'The Work': the Original Work or its Derivative Works.
22
+ — 'The Source Code': the human-readable form of the Work which is the most convenient for people to study and modify.
23
+ — 'The Executable Code': any code which has generally been compiled and which is meant to be interpreted by a computer as a program.
24
+ — 'The Licensor': the natural or legal person that distributes or communicates the Work under the Licence.
25
+ — 'Contributor(s)': any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work.
26
+ — 'The Licensee' or 'You': any natural or legal person who makes any usage of the Work under the terms of the Licence.
27
+ — 'Distribution' or 'Communication': any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person.
28
+ 2. Scope of the rights granted by the Licence
29
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for the duration of copyright vested in the Original Work:
30
+
31
+ — use the Work in any circumstance and for all usage,
32
+ — reproduce the Work,
33
+ — modify the Work, and make Derivative Works based upon the Work,
34
+ — communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work,
35
+ — distribute the Work or copies thereof,
36
+ — lend and rent the Work or copies thereof,
37
+ — sublicense rights in the Work or copies thereof.
38
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so.
39
+
40
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed.
41
+
42
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence.
43
+
44
+ 3. Communication of the Source Code
45
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute or communicate the Work.
46
+
47
+ 4. Limitations on copyright
48
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations thereto.
49
+
50
+ 5. Obligations of the Licensee
51
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following:
52
+
53
+ Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification.
54
+
55
+ Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence — for example by communicating 'EUPL v. 1.2 only'. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence.
56
+
57
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, 'Compatible Licence' refers to the licences listed in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
58
+
59
+ Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute or communicate the Work.
60
+
61
+ Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice.
62
+
63
+ 6. Chain of Authorship
64
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
65
+
66
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
67
+
68
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions to the Work, under the terms of this Licence.
69
+
70
+ 7. Disclaimer of Warranty
71
+ The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work and may therefore contain defects or 'bugs' inherent to this type of development.
72
+
73
+ For the above reason, the Work is provided under the Licence on an 'as is' basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence.
74
+
75
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
76
+
77
+ 8. Disclaimer of Liability
78
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
79
+
80
+ 9. Additional agreements
81
+ While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any warranty or additional liability.
82
+
83
+ 10. Acceptance of the Licence
84
+ The provisions of this Licence can be accepted by clicking on an icon 'I agree' placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions.
85
+
86
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution or Communication by You of the Work or copies thereof.
87
+
88
+ 11. Information to the public
89
+ In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee.
90
+
91
+ 12. Termination of the Licence
92
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence.
93
+
94
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence.
95
+
96
+ 13. Miscellaneous
97
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work.
98
+
99
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid and enforceable.
100
+
101
+ The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number.
102
+
103
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice.
104
+
105
+ 14. Jurisdiction
106
+ Without prejudice to specific agreement between parties,
107
+
108
+ — any litigation resulting from the interpretation of this License, arising between the European Union institutions, bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
109
+ — any litigation arising between other parties and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
110
+ 15. Applicable Law
111
+ Without prejudice to specific agreement between parties,
112
+
113
+ — this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, resides or has his registered office,
114
+ — this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside a European Union Member State.
115
+ Appendix
116
+
117
+ 'Compatible Licences' according to Article 5 EUPL are:
118
+
119
+ — GNU General Public License (GPL) v. 2, v. 3
120
+ — GNU Affero General Public License (AGPL) v. 3
121
+ — Open Software License (OSL) v. 2.1, v. 3.0
122
+ — Eclipse Public License (EPL) v. 1.0
123
+ — CeCILL v. 2.0, v. 2.1
124
+ — Mozilla Public Licence (MPL) v. 2
125
+ — GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
126
+ — Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
127
+ — European Union Public Licence (EUPL) v. 1.1, v. 1.2
128
+ — Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+).
@@ -0,0 +1,30 @@
1
+ # Third-party data in rac4os
2
+
3
+ The rac4os code is licensed under EUPL-1.2 (see LICENSE). The classification files in
4
+ `rac4os/_data/` are not covered by that licence; they remain under their publishers' terms.
5
+ None of the publishers endorses rac4os.
6
+
7
+ ## SEA 2021 — `sea2021.xml`
8
+ Systematik der Einnahmen und Ausgaben der privaten Haushalte, Ausgabe 2021
9
+ (file version of 18 September 2024).
10
+ Source: Statistisches Bundesamt (Destatis), Klassifikationsserver,
11
+ https://klassifikationsserver.de/klassService/thyme/variant/sea_2021
12
+ Licence: Datenlizenz Deutschland – Namensnennung – Version 2.0 (dl-de/by-2-0),
13
+ https://www.govdata.de/dl-de/by-2-0
14
+
15
+ ## SEA 2021, refined descriptions — `sea_2021_augmented.json`
16
+ Modified version of `sea2021.xml`: descriptions of parent categories were generated
17
+ by a language model with rac4os's ClassificationsSystemAugmenter (<model>, <date>).
18
+ This is not an official Destatis publication.
19
+ Source of the original and licence: as above (dl-de/by-2-0); changes made by Adrian Montag.
20
+
21
+ ## COICOP 2018 — `COICOP_2018_English_structure.xlsx`
22
+ Classification of Individual Consumption According to Purpose (COICOP) 2018, final structure.
23
+ Publisher: United Nations Statistics Division (UNSD),
24
+ https://unstats.un.org/unsd/classifications/coicop
25
+
26
+ ## ICATUS 2016 — `UNSD_Time_Use_Statistics.csv`
27
+ International Classification of Activities for Time-Use Statistics 2016.
28
+ Publisher: United Nations Statistics Division (UNSD),
29
+ https://unstats.un.org/unsd/demographic-social/time-use/icatus-2016/tableview
30
+ Terms: <as for COICOP>
rac4os-0.2.16/PKG-INFO ADDED
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: rac4os
3
+ Version: 0.2.16
4
+ Summary: Retrieval-augmented classification of free text into hierarchical statistical taxonomies
5
+ Author: Adrian Montag
6
+ License-Expression: EUPL-1.2
7
+ Project-URL: Documentation, https://rac4os.com/
8
+ Project-URL: Source, https://github.com/adimo20/rac4os
9
+ Project-URL: Issues, https://github.com/adimo20/rac4os/issues
10
+ Keywords: classification,icatus,coicop,sea,household-survey,official-statistics
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Natural Language :: German
14
+ Classifier: Natural Language :: English
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: >=3.12
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ License-File: NOTICE.md
24
+ Requires-Dist: pandas>=2.2.0
25
+ Requires-Dist: openpyxl>=3.1
26
+ Requires-Dist: dspy<3.5,>=3.0
27
+ Provides-Extra: local
28
+ Requires-Dist: chromadb>=1.0; extra == "local"
29
+ Requires-Dist: sentence-transformers>=3.0; extra == "local"
30
+ Provides-Extra: ollama
31
+ Requires-Dist: chromadb>=1.0; extra == "ollama"
32
+ Requires-Dist: ollama>=0.3; extra == "ollama"
33
+ Provides-Extra: openai
34
+ Requires-Dist: chromadb>=1.0; extra == "openai"
35
+ Requires-Dist: openai>=1.0; extra == "openai"
36
+ Provides-Extra: test
37
+ Requires-Dist: chromadb>=1.0; extra == "test"
38
+ Requires-Dist: pytest>=8.0; extra == "test"
39
+ Requires-Dist: pytest-socket>=0.7; extra == "test"
40
+ Dynamic: license-file
41
+
42
+ # rac4os — Retrieval Augmented Classification for Official Statistics
43
+
44
+ **📖 Documentation: <https://rac4os.com/>**
45
+
46
+ `rac4os` is an experimental package for applying Retrieval-Augmented Generation (RAG)
47
+ to classification tasks based on hierarchical statistical taxonomies. It is aimed at
48
+ practitioners in official statistics, the social sciences and economics who want to
49
+ classify free-text data against statistical taxonomies with RAG-based and agentic
50
+ approaches. The package provides modular, adaptable components for modelling each stage
51
+ of a RAG classification pipeline — you can use every component as it is, or adapt and
52
+ extend it for new use cases.
53
+
54
+ Three approaches to classification are available:
55
+
56
+ - **agentic hierarchy traversal** — walks your taxonomy top-down through four navigation
57
+ tools; no retriever and no embeddings required.
58
+ - **linear RAG** — one retrieval call and one chain-of-thought generation per item. Comes
59
+ in two variants: a naïve RAG implementation and a more advanced
60
+ Rephrase-Retrieve-Respond RAG, which rewrites the query in the vocabulary of your
61
+ labels before retrieving.
62
+ - **agentic RAG** — exposes the retriever to the model as a tool, so it can reformulate
63
+ its query and search again when the candidates do not fit.
64
+
65
+ All three are built on two shared components you can adapt: a **classification system**
66
+ (the uniform interface to your taxonomy) and a **retriever** (semantic search over your
67
+ categories). Both are built around _your_ classification — you describe it once, and
68
+ every approach works on it. Worked entries for three official classifications (COICOP
69
+ 2018, SEA 2021, ICATUS 2016) ship with the package as examples.
70
+
71
+ ## Install
72
+
73
+ ```bash
74
+ pip install "rac4os[local]"
75
+ ```
76
+
77
+ Python ≥ 3.12. The core install covers parsing and navigating taxonomies only; the
78
+ retrieval-based approaches need one embedding backend — `[local]`
79
+ (sentence-transformers, in-process), `[ollama]` or `[openai]`.
80
+
81
+ To install the current state of `master` instead of the latest release:
82
+
83
+ ```bash
84
+ pip install "rac4os[local] @ git+https://github.com/adimo20/rac4os.git"
85
+ ```
86
+
87
+ ## A first look
88
+
89
+ ```python
90
+ from rac4os.classification_system import get_classification_system
91
+
92
+ cs = get_classification_system("COICOP_2018") # a taxonomy you registered
93
+ cs.get_children("1010")
94
+ # [Code(code='101010', description='Printing and copying paper', level=3, ...), ...]
95
+ cs.get_code_trace("101010")
96
+ # [('10', 'Office supplies and consumables'), ('1010', 'Paper and paper products'), ...]
97
+ ```
98
+
99
+ ## Benchmark results
100
+
101
+ Measured on COICOP 2018 against a 1,000-example subsample (20%) of the public
102
+ [Palumbo et al. (2026) dataset](https://doi.org/10.5281/zenodo.18459651); for the work
103
+ behind it, see
104
+ [Palumbo & Nunes at UNECE (2025)](https://unece.org/sites/default/files/2025-05/GenAI2025_S3_Italy_Palumbo_P.pdf).
105
+ Candidates were retrieved with `qwen3-embedding:0.6b`; the models named in the figures
106
+ are the generators that chose among them. Predictions were made on COICOP level 4.
107
+
108
+ ![F1 score by COICOP level](https://raw.githubusercontent.com/adimo20/rac4os/master/img/1_f1_by_level.png)
109
+
110
+
111
+ Accuracy is governed by how fine the target level is. Every model stays above 0.96 at
112
+ the two-digit division, where they are within 0.016 of each other, and the spread only
113
+ opens up further down: at the four-digit subclass it reaches 0.145, between 0.852 for
114
+ DeepSeek V4.1 Flash and 0.707 for Solar Mini 4.5.
115
+
116
+ ![Subclass-level F1: RAG agent vs. Rephrase-Retrieve-Respond pipeline](https://raw.githubusercontent.com/adimo20/rac4os/master/img/2_f1_agent_vs_pipeline_subclass.png)
117
+
118
+ At the most detailed level the agentic approach beats the linear
119
+ Rephrase-Retrieve-Respond pipeline for every model tested, by between 0.036 and 0.069
120
+ F1. Letting the model judge its candidates and search again recovers cases that a single
121
+ retrieval on the raw item misses — which is the bottleneck the linear pipeline cannot
122
+ work around, at the cost of more model calls per item.
123
+
124
+ One classification, one dataset, one subsample: read these as how the approaches compare
125
+ to each other here, not as a leaderboard. Also note the distribution of the coicop dataset;
126
+ The dataset only consists out of products in the division `01` and `02`.
127
+
128
+ The experiments behind both figures are in [`examples/coicop`](https://github.com/adimo20/rac4os/tree/master/examples/coicop):
129
+ `sample.py` draws the subsample from the published dataset, `main.py` runs the RAG agent
130
+ and the Rephrase-Retrieve-Respond pipeline over it, and the per-model predictions and
131
+ scores are kept under `data/eval_results/`.
132
+
133
+ ## Where to go next
134
+
135
+ | | |
136
+ | ---------------------------------------------------------------------------- | ------------------------------------------- |
137
+ | [Quickstart](https://rac4os.com/getting-started/quickstart/) | each approach run once, end to end |
138
+ | [Your Own Taxonomy](https://rac4os.com/taxonomy/overview/) | describe your classification in three steps |
139
+ | [Linear RAG](https://rac4os.com/linear-rag/usage/) | retrieve once, reason once |
140
+ | [Agentic RAG](https://rac4os.com/agentic-rag/usage/) | the retriever as a tool |
141
+ | [Hierarchy Traversal](https://rac4os.com/traversal/usage/) | classify by descending the hierarchy |
142
+ | [Package Reference](https://rac4os.com/reference/classifiers/) | generated from the source |
143
+
144
+ ## Disclaimer
145
+
146
+ `rac4os` is an independent research package. It is not affiliated with or endorsed by
147
+ any statistical office or other organisation whose classifications it works with.
148
+
149
+ ## License
150
+
151
+ Copyright (c) 2026 Adrian Montag
152
+ Licensed under the EUPL v. 1.2
153
+
154
+ ## Citation
155
+
156
+ ```bibtex
157
+ @software{montag_rac4os,
158
+ author = {Montag, Adrian},
159
+ title = {{rac4os}: Retrieval Augmented Classification for Official Statistics},
160
+ version = {0.2.16},
161
+ year = {2026},
162
+ url = {https://github.com/adimo20/rac4os},
163
+ license = {EUPL-1.2}
164
+ }
165
+ ```
@@ -0,0 +1,124 @@
1
+ # rac4os — Retrieval Augmented Classification for Official Statistics
2
+
3
+ **📖 Documentation: <https://rac4os.com/>**
4
+
5
+ `rac4os` is an experimental package for applying Retrieval-Augmented Generation (RAG)
6
+ to classification tasks based on hierarchical statistical taxonomies. It is aimed at
7
+ practitioners in official statistics, the social sciences and economics who want to
8
+ classify free-text data against statistical taxonomies with RAG-based and agentic
9
+ approaches. The package provides modular, adaptable components for modelling each stage
10
+ of a RAG classification pipeline — you can use every component as it is, or adapt and
11
+ extend it for new use cases.
12
+
13
+ Three approaches to classification are available:
14
+
15
+ - **agentic hierarchy traversal** — walks your taxonomy top-down through four navigation
16
+ tools; no retriever and no embeddings required.
17
+ - **linear RAG** — one retrieval call and one chain-of-thought generation per item. Comes
18
+ in two variants: a naïve RAG implementation and a more advanced
19
+ Rephrase-Retrieve-Respond RAG, which rewrites the query in the vocabulary of your
20
+ labels before retrieving.
21
+ - **agentic RAG** — exposes the retriever to the model as a tool, so it can reformulate
22
+ its query and search again when the candidates do not fit.
23
+
24
+ All three are built on two shared components you can adapt: a **classification system**
25
+ (the uniform interface to your taxonomy) and a **retriever** (semantic search over your
26
+ categories). Both are built around _your_ classification — you describe it once, and
27
+ every approach works on it. Worked entries for three official classifications (COICOP
28
+ 2018, SEA 2021, ICATUS 2016) ship with the package as examples.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install "rac4os[local]"
34
+ ```
35
+
36
+ Python ≥ 3.12. The core install covers parsing and navigating taxonomies only; the
37
+ retrieval-based approaches need one embedding backend — `[local]`
38
+ (sentence-transformers, in-process), `[ollama]` or `[openai]`.
39
+
40
+ To install the current state of `master` instead of the latest release:
41
+
42
+ ```bash
43
+ pip install "rac4os[local] @ git+https://github.com/adimo20/rac4os.git"
44
+ ```
45
+
46
+ ## A first look
47
+
48
+ ```python
49
+ from rac4os.classification_system import get_classification_system
50
+
51
+ cs = get_classification_system("COICOP_2018") # a taxonomy you registered
52
+ cs.get_children("1010")
53
+ # [Code(code='101010', description='Printing and copying paper', level=3, ...), ...]
54
+ cs.get_code_trace("101010")
55
+ # [('10', 'Office supplies and consumables'), ('1010', 'Paper and paper products'), ...]
56
+ ```
57
+
58
+ ## Benchmark results
59
+
60
+ Measured on COICOP 2018 against a 1,000-example subsample (20%) of the public
61
+ [Palumbo et al. (2026) dataset](https://doi.org/10.5281/zenodo.18459651); for the work
62
+ behind it, see
63
+ [Palumbo & Nunes at UNECE (2025)](https://unece.org/sites/default/files/2025-05/GenAI2025_S3_Italy_Palumbo_P.pdf).
64
+ Candidates were retrieved with `qwen3-embedding:0.6b`; the models named in the figures
65
+ are the generators that chose among them. Predictions were made on COICOP level 4.
66
+
67
+ ![F1 score by COICOP level](https://raw.githubusercontent.com/adimo20/rac4os/master/img/1_f1_by_level.png)
68
+
69
+
70
+ Accuracy is governed by how fine the target level is. Every model stays above 0.96 at
71
+ the two-digit division, where they are within 0.016 of each other, and the spread only
72
+ opens up further down: at the four-digit subclass it reaches 0.145, between 0.852 for
73
+ DeepSeek V4.1 Flash and 0.707 for Solar Mini 4.5.
74
+
75
+ ![Subclass-level F1: RAG agent vs. Rephrase-Retrieve-Respond pipeline](https://raw.githubusercontent.com/adimo20/rac4os/master/img/2_f1_agent_vs_pipeline_subclass.png)
76
+
77
+ At the most detailed level the agentic approach beats the linear
78
+ Rephrase-Retrieve-Respond pipeline for every model tested, by between 0.036 and 0.069
79
+ F1. Letting the model judge its candidates and search again recovers cases that a single
80
+ retrieval on the raw item misses — which is the bottleneck the linear pipeline cannot
81
+ work around, at the cost of more model calls per item.
82
+
83
+ One classification, one dataset, one subsample: read these as how the approaches compare
84
+ to each other here, not as a leaderboard. Also note the distribution of the coicop dataset;
85
+ The dataset only consists out of products in the division `01` and `02`.
86
+
87
+ The experiments behind both figures are in [`examples/coicop`](https://github.com/adimo20/rac4os/tree/master/examples/coicop):
88
+ `sample.py` draws the subsample from the published dataset, `main.py` runs the RAG agent
89
+ and the Rephrase-Retrieve-Respond pipeline over it, and the per-model predictions and
90
+ scores are kept under `data/eval_results/`.
91
+
92
+ ## Where to go next
93
+
94
+ | | |
95
+ | ---------------------------------------------------------------------------- | ------------------------------------------- |
96
+ | [Quickstart](https://rac4os.com/getting-started/quickstart/) | each approach run once, end to end |
97
+ | [Your Own Taxonomy](https://rac4os.com/taxonomy/overview/) | describe your classification in three steps |
98
+ | [Linear RAG](https://rac4os.com/linear-rag/usage/) | retrieve once, reason once |
99
+ | [Agentic RAG](https://rac4os.com/agentic-rag/usage/) | the retriever as a tool |
100
+ | [Hierarchy Traversal](https://rac4os.com/traversal/usage/) | classify by descending the hierarchy |
101
+ | [Package Reference](https://rac4os.com/reference/classifiers/) | generated from the source |
102
+
103
+ ## Disclaimer
104
+
105
+ `rac4os` is an independent research package. It is not affiliated with or endorsed by
106
+ any statistical office or other organisation whose classifications it works with.
107
+
108
+ ## License
109
+
110
+ Copyright (c) 2026 Adrian Montag
111
+ Licensed under the EUPL v. 1.2
112
+
113
+ ## Citation
114
+
115
+ ```bibtex
116
+ @software{montag_rac4os,
117
+ author = {Montag, Adrian},
118
+ title = {{rac4os}: Retrieval Augmented Classification for Official Statistics},
119
+ version = {0.2.16},
120
+ year = {2026},
121
+ url = {https://github.com/adimo20/rac4os},
122
+ license = {EUPL-1.2}
123
+ }
124
+ ```
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rac4os"
7
+ version = "0.2.16"
8
+ description = "Retrieval-augmented classification of free text into hierarchical statistical taxonomies"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "EUPL-1.2"
12
+ license-files = ["LICENSE", "NOTICE.md"]
13
+ authors = [{ name = "Adrian Montag"}]
14
+ keywords = [
15
+ "classification",
16
+ "icatus",
17
+ "coicop",
18
+ "sea",
19
+ "household-survey",
20
+ "official-statistics",
21
+ ]
22
+ classifiers = [
23
+ "Development Status :: 3 - Alpha",
24
+ "Intended Audience :: Science/Research",
25
+ "Natural Language :: German",
26
+ "Natural Language :: English",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Programming Language :: Python :: 3.14",
31
+ "Operating System :: OS Independent"
32
+ ]
33
+ dependencies = ["pandas>=2.2.0", "openpyxl>=3.1", "dspy>=3.0,<3.5"]
34
+
35
+ [project.optional-dependencies]
36
+ local = ["chromadb>=1.0", "sentence-transformers>=3.0"]
37
+ ollama = ["chromadb>=1.0", "ollama>=0.3"]
38
+ openai = ["chromadb>=1.0", "openai>=1.0"]
39
+ test = ["chromadb>=1.0", "pytest>=8.0", "pytest-socket>=0.7"]
40
+
41
+ [project.urls]
42
+ Documentation = "https://rac4os.com/"
43
+ Source = "https://github.com/adimo20/rac4os"
44
+ Issues = "https://github.com/adimo20/rac4os/issues"
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["."]
48
+ include = ["rac4os*"]
49
+
50
+ [tool.setuptools.package-data]
51
+ "*" = ["*.json", "*.csv", "*.xml", "*.xlsx"]
52
+
53
+ [tool.pytest.ini_options]
54
+ testpaths = ["tests"]
55
+ pythonpath = ["."]
@@ -0,0 +1,23 @@
1
+ from . import (
2
+ _data,
3
+ _shared,
4
+ agents,
5
+ classification_system,
6
+ dataloaders,
7
+ inference,
8
+ rag,
9
+ taxonomy_refinement,
10
+ )
11
+ from .__version__ import __version__
12
+
13
+ __all__ = [
14
+ "__version__",
15
+ "_data",
16
+ "_shared",
17
+ "agents",
18
+ "classification_system",
19
+ "dataloaders",
20
+ "inference",
21
+ "rag",
22
+ "taxonomy_refinement",
23
+ ]
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("rac4os")
5
+ except PackageNotFoundError:
6
+ __version__ = "0+unknown"