rag-audit 0.1.0__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 (49) hide show
  1. rag_audit-0.1.0/.github/workflows/ci.yml +270 -0
  2. rag_audit-0.1.0/.github/workflows/docs.yml +35 -0
  3. rag_audit-0.1.0/.github/workflows/publish.yml +36 -0
  4. rag_audit-0.1.0/.gitignore +218 -0
  5. rag_audit-0.1.0/.pre-commit-config.yaml +158 -0
  6. rag_audit-0.1.0/LICENSE +21 -0
  7. rag_audit-0.1.0/PKG-INFO +225 -0
  8. rag_audit-0.1.0/README.md +176 -0
  9. rag_audit-0.1.0/docs/api/adapters.md +66 -0
  10. rag_audit-0.1.0/docs/api/chunker.md +93 -0
  11. rag_audit-0.1.0/docs/api/metrics.md +58 -0
  12. rag_audit-0.1.0/docs/api/report.md +30 -0
  13. rag_audit-0.1.0/docs/index.md +23 -0
  14. rag_audit-0.1.0/docs/quickstart.md +133 -0
  15. rag_audit-0.1.0/docs/stylesheets/extra.css +104 -0
  16. rag_audit-0.1.0/mkdocs.yml +58 -0
  17. rag_audit-0.1.0/pyproject.toml +192 -0
  18. rag_audit-0.1.0/src/rag_audit/__init__.py +3 -0
  19. rag_audit-0.1.0/src/rag_audit/adapters/__init__.py +12 -0
  20. rag_audit-0.1.0/src/rag_audit/adapters/base.py +11 -0
  21. rag_audit-0.1.0/src/rag_audit/adapters/chroma.py +42 -0
  22. rag_audit-0.1.0/src/rag_audit/adapters/stubs.py +30 -0
  23. rag_audit-0.1.0/src/rag_audit/chunker/__init__.py +20 -0
  24. rag_audit-0.1.0/src/rag_audit/chunker/base.py +16 -0
  25. rag_audit-0.1.0/src/rag_audit/chunker/evaluator.py +51 -0
  26. rag_audit-0.1.0/src/rag_audit/chunker/models.py +15 -0
  27. rag_audit-0.1.0/src/rag_audit/chunker/strategies.py +96 -0
  28. rag_audit-0.1.0/src/rag_audit/cli/__init__.py +0 -0
  29. rag_audit-0.1.0/src/rag_audit/cli/main.py +68 -0
  30. rag_audit-0.1.0/src/rag_audit/core/__init__.py +1 -0
  31. rag_audit-0.1.0/src/rag_audit/core/config.py +25 -0
  32. rag_audit-0.1.0/src/rag_audit/core/runner.py +41 -0
  33. rag_audit-0.1.0/src/rag_audit/metrics/__init__.py +11 -0
  34. rag_audit-0.1.0/src/rag_audit/metrics/hallucination.py +60 -0
  35. rag_audit-0.1.0/src/rag_audit/metrics/retrieval.py +42 -0
  36. rag_audit-0.1.0/src/rag_audit/report/__init__.py +6 -0
  37. rag_audit-0.1.0/src/rag_audit/report/models.py +18 -0
  38. rag_audit-0.1.0/src/rag_audit/report/renderer.py +58 -0
  39. rag_audit-0.1.0/tests/__init__.py +0 -0
  40. rag_audit-0.1.0/tests/test_placeholder.py +4 -0
  41. rag_audit-0.1.0/tests/unit/__init__.py +0 -0
  42. rag_audit-0.1.0/tests/unit/test_adapters.py +70 -0
  43. rag_audit-0.1.0/tests/unit/test_chunker.py +167 -0
  44. rag_audit-0.1.0/tests/unit/test_cli.py +119 -0
  45. rag_audit-0.1.0/tests/unit/test_hallucination.py +68 -0
  46. rag_audit-0.1.0/tests/unit/test_report.py +74 -0
  47. rag_audit-0.1.0/tests/unit/test_retrieval.py +60 -0
  48. rag_audit-0.1.0/tests/unit/test_runner.py +58 -0
  49. rag_audit-0.1.0/uv.lock +3744 -0
@@ -0,0 +1,270 @@
1
+ # =============================================================================
2
+ # .github/workflows/ci.yml — Pipeline de Integração Contínua (CI)
3
+ #
4
+ # O que é GitHub Actions?
5
+ # É o sistema de automação do GitHub. Você define "workflows" em arquivos YAML
6
+ # dentro de .github/workflows/. Esses workflows rodam em servidores do GitHub
7
+ # (chamados "runners") automaticamente quando certas coisas acontecem no repo.
8
+ #
9
+ # O que este workflow faz?
10
+ # Toda vez que alguém abre um Pull Request ou faz push para main/develop,
11
+ # este workflow roda automaticamente e verifica:
12
+ # 1. Se o código está formatado corretamente (ruff)
13
+ # 2. Se os tipos estão corretos (mypy)
14
+ # 3. Se todos os testes passam (pytest) — em Python 3.11 e 3.12
15
+ # 4. Se a cobertura de código está acima do mínimo
16
+ #
17
+ # Se qualquer passo falhar, o PR fica bloqueado (vermelho) até ser corrigido.
18
+ # =============================================================================
19
+
20
+ name: CI # Nome que aparece na aba "Actions" do GitHub
21
+
22
+ # ===========================================================================
23
+ # `on` — Define QUANDO este workflow é disparado
24
+ # ===========================================================================
25
+ on:
26
+ push:
27
+ branches:
28
+ - main # Roda quando há push direto para main
29
+ - develop # Roda quando há push para develop
30
+
31
+ pull_request:
32
+ branches:
33
+ - main # Roda em PRs que querem entrar em main
34
+ - develop # Roda em PRs que querem entrar em develop
35
+
36
+ # Permite rodar o workflow manualmente pela UI do GitHub (botão "Run workflow")
37
+ workflow_dispatch:
38
+
39
+
40
+ # ===========================================================================
41
+ # `env` — Variáveis de ambiente disponíveis em TODOS os jobs
42
+ # ===========================================================================
43
+ env:
44
+ # Evita que o Python crie arquivos .pyc durante a CI (não precisamos deles)
45
+ PYTHONDONTWRITEBYTECODE: "1"
46
+
47
+ # Força o Python a não usar buffer no stdout/stderr (logs aparecem em tempo real)
48
+ PYTHONUNBUFFERED: "1"
49
+
50
+ # Versão padrão do uv (gerenciador de pacotes)
51
+ UV_VERSION: "latest"
52
+
53
+
54
+ # ===========================================================================
55
+ # `jobs` — Os trabalhos que vão rodar (cada job é independente)
56
+ # ===========================================================================
57
+ jobs:
58
+
59
+ # =========================================================================
60
+ # JOB 1: lint — Verifica formatação e estilo
61
+ #
62
+ # Roda ruff para checar se o código está formatado corretamente.
63
+ # É o job mais rápido (~10 segundos) e roda antes dos testes.
64
+ # Se o código estiver mal formatado, não faz sentido rodar os testes.
65
+ # =========================================================================
66
+ lint:
67
+ name: Lint & Format check
68
+ runs-on: ubuntu-latest # Roda em uma VM Ubuntu gerenciada pelo GitHub (gratuito)
69
+
70
+ steps:
71
+ # Passo 1: Baixa o código do repositório para a VM
72
+ # `actions/checkout` é uma action oficial do GitHub
73
+ - name: Checkout code
74
+ uses: actions/checkout@v4
75
+
76
+ # Passo 2: Instala o Python
77
+ - name: Set up Python
78
+ uses: actions/setup-python@v5
79
+ with:
80
+ python-version: "3.11"
81
+
82
+ # Passo 3: Instala o uv (gerenciador de pacotes moderno e ultrarrápido)
83
+ - name: Install uv
84
+ uses: astral-sh/setup-uv@v3
85
+ with:
86
+ version: ${{ env.UV_VERSION }}
87
+
88
+ # Passo 4: Instala as dependências de desenvolvimento (grupo [dev] do pyproject.toml)
89
+ - name: Install dev dependencies
90
+ run: uv sync --group dev
91
+
92
+ # Passo 5: Roda o ruff como linter (verifica problemas de código)
93
+ - name: Run ruff linter
94
+ run: uv run ruff check src/ tests/
95
+
96
+ # Passo 6: Roda o ruff como formatter (verifica se o código está formatado)
97
+ # --check não modifica arquivos, só verifica e retorna erro se precisar de formatação
98
+ - name: Run ruff format check
99
+ run: uv run ruff format --check src/ tests/
100
+
101
+
102
+ # =========================================================================
103
+ # JOB 2: typecheck — Verificação de tipos com mypy
104
+ #
105
+ # Analisa os type hints do código sem executá-lo.
106
+ # Roda em paralelo com o job de lint (jobs independentes rodam ao mesmo tempo).
107
+ # =========================================================================
108
+ typecheck:
109
+ name: Type check (mypy)
110
+ runs-on: ubuntu-latest
111
+
112
+ steps:
113
+ - name: Checkout code
114
+ uses: actions/checkout@v4
115
+
116
+ - name: Set up Python
117
+ uses: actions/setup-python@v5
118
+ with:
119
+ python-version: "3.11"
120
+
121
+ - name: Install uv
122
+ uses: astral-sh/setup-uv@v3
123
+ with:
124
+ version: ${{ env.UV_VERSION }}
125
+
126
+ - name: Install dependencies
127
+ run: uv sync --group dev
128
+
129
+ - name: Run mypy
130
+ run: uv run mypy src/rag_audit
131
+
132
+
133
+ # =========================================================================
134
+ # JOB 3: test — Roda a suíte de testes
135
+ #
136
+ # Este é o job mais importante. Usa uma "matrix strategy" para rodar
137
+ # os testes em múltiplas versões do Python ao mesmo tempo.
138
+ #
139
+ # Matrix strategy: em vez de criar um job por versão, você define uma matriz
140
+ # e o GitHub cria automaticamente um job para cada combinação.
141
+ # =========================================================================
142
+ test:
143
+ name: Tests (Python ${{ matrix.python-version }})
144
+ runs-on: ubuntu-latest
145
+
146
+ # Depende dos jobs de lint e typecheck — só roda se ambos passarem
147
+ needs: [lint, typecheck]
148
+
149
+ # Define a matriz de versões — cria um job para cada versão listada
150
+ strategy:
151
+ matrix:
152
+ python-version: ["3.11", "3.12"]
153
+
154
+ # fail-fast: false = se o teste falhar em 3.11, continua rodando em 3.12
155
+ # Útil para identificar se o problema é específico de uma versão
156
+ fail-fast: false
157
+
158
+ steps:
159
+ - name: Checkout code
160
+ uses: actions/checkout@v4
161
+
162
+ # Aqui usamos `matrix.python-version` para instalar a versão correta
163
+ - name: Set up Python ${{ matrix.python-version }}
164
+ uses: actions/setup-python@v5
165
+ with:
166
+ python-version: ${{ matrix.python-version }}
167
+
168
+ - name: Install uv
169
+ uses: astral-sh/setup-uv@v3
170
+ with:
171
+ version: ${{ env.UV_VERSION }}
172
+
173
+ # Cache das dependências do uv — evita baixar tudo do zero em cada run
174
+ # O cache é invalidado quando o pyproject.toml muda (hash do arquivo)
175
+ - name: Cache uv dependencies
176
+ uses: actions/cache@v4
177
+ with:
178
+ path: ~/.cache/uv
179
+ key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
180
+ restore-keys: |
181
+ uv-${{ runner.os }}-${{ matrix.python-version }}-
182
+
183
+ - name: Install dependencies
184
+ run: uv sync --group dev
185
+
186
+ # Roda os testes com cobertura de código
187
+ # --cov=src/rag_audit = mede cobertura do código em src/rag_audit
188
+ # --cov-report=term-missing = mostra no terminal quais linhas não foram testadas
189
+ # --cov-report=xml = gera coverage.xml (para upload no próximo passo)
190
+ # --cov-fail-under=80 = FALHA se a cobertura for menor que 80%
191
+ - name: Run tests with coverage
192
+ run: |
193
+ uv run pytest \
194
+ --cov=src/rag_audit \
195
+ --cov-report=term-missing \
196
+ --cov-report=xml \
197
+ --cov-fail-under=80 \
198
+ -m "not integration"
199
+
200
+ # Faz upload do relatório de cobertura para o Codecov
201
+ # Codecov é um serviço gratuito para OSS que mostra a cobertura em PRs
202
+ # (opcional — remova se não quiser usar)
203
+ - name: Upload coverage to Codecov
204
+ uses: codecov/codecov-action@v4
205
+ if: matrix.python-version == '3.11' # Sobe apenas uma vez (evita duplicata)
206
+ with:
207
+ file: ./coverage.xml
208
+ fail_ci_if_error: false # Não falha a CI se o Codecov estiver fora do ar
209
+
210
+
211
+ # =========================================================================
212
+ # JOB 4: test-integration — Testes de integração (separados)
213
+ #
214
+ # Testes que chamam LLMs reais ou vector databases.
215
+ # Rodam SEPARADOS dos testes unitários porque:
216
+ # 1. São mais lentos
217
+ # 2. Precisam de API keys (secrets)
218
+ # 3. Custam dinheiro (chamadas à API da OpenAI/Anthropic)
219
+ #
220
+ # Só rodam em push para main (não em todo PR) para economizar recursos.
221
+ # =========================================================================
222
+ test-integration:
223
+ name: Integration tests
224
+ runs-on: ubuntu-latest
225
+ needs: [test]
226
+
227
+ # Condição: só roda em push para main, não em PRs
228
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
229
+
230
+ steps:
231
+ - name: Checkout code
232
+ uses: actions/checkout@v4
233
+
234
+ - name: Set up Python
235
+ uses: actions/setup-python@v5
236
+ with:
237
+ python-version: "3.11"
238
+
239
+ - name: Install uv
240
+ uses: astral-sh/setup-uv@v3
241
+ with:
242
+ version: ${{ env.UV_VERSION }}
243
+
244
+ - name: Install dependencies
245
+ run: uv sync --group dev
246
+
247
+ - name: Run integration tests
248
+ # As API keys ficam em GitHub Secrets (Settings → Secrets → Actions)
249
+ # Nunca coloque chaves de API direto no código!
250
+ env:
251
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
252
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
253
+ run: |
254
+ uv run pytest -m "integration" --tb=short -v || ec=$?
255
+ [ "${ec:-0}" -eq 5 ] && exit 0 || exit "${ec:-0}"
256
+
257
+
258
+ # ===========================================================================
259
+ # RESUMO DO FLUXO EM UM PR:
260
+ #
261
+ # Push / PR aberto
262
+ # │
263
+ # ├─── lint (ruff) ──┐
264
+ # │ ├── ambos passam → test (pytest matrix 3.11 + 3.12)
265
+ # └─── typecheck (mypy) ──┘ │
266
+ # └── testes passam → PR pode ser mergeado ✓
267
+ #
268
+ # Em push para main (após merge):
269
+ # └── test-integration (testes com LLMs reais)
270
+ # ===========================================================================
@@ -0,0 +1,35 @@
1
+ name: Deploy docs
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: write
11
+
12
+ jobs:
13
+ deploy:
14
+ name: Deploy to GitHub Pages
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout code
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Set up Python
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: "3.11"
25
+
26
+ - name: Install uv
27
+ uses: astral-sh/setup-uv@v3
28
+ with:
29
+ version: "latest"
30
+
31
+ - name: Install docs dependencies
32
+ run: uv sync --group docs
33
+
34
+ - name: Deploy docs
35
+ run: uv run mkdocs gh-deploy --force
@@ -0,0 +1,36 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ publish:
13
+ name: Build and publish
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.11"
24
+
25
+ - name: Install uv
26
+ uses: astral-sh/setup-uv@v3
27
+ with:
28
+ version: "latest"
29
+
30
+ - name: Build package
31
+ run: uv build
32
+
33
+ - name: Publish to PyPI
34
+ run: uv publish
35
+ env:
36
+ UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml