rag-python 0.3.0__tar.gz → 0.3.1__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.
- rag_python-0.3.1/PKG-INFO +205 -0
- rag_python-0.3.1/README.md +152 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/pyproject.toml +4 -3
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/__init__.py +19 -4
- rag_python-0.3.1/src/rag_python/cli.py +266 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/client.py +19 -1
- rag_python-0.3.1/src/rag_python/generation.py +65 -0
- rag_python-0.3.1/src/rag_python/help_text.py +229 -0
- rag_python-0.3.1/src/rag_python/log.py +21 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/anthropic_provider.py +23 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/azure_openai_provider.py +26 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/base.py +11 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/ollama_provider.py +37 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/openai_provider.py +26 -0
- rag_python-0.3.1/src/rag_python/providers/streaming.py +35 -0
- rag_python-0.3.1/src/rag_python/rag_pipeline.py +460 -0
- rag_python-0.3.1/src/rag_python.egg-info/PKG-INFO +205 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python.egg-info/SOURCES.txt +6 -1
- rag_python-0.3.1/tests/test_cli.py +52 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_import.py +1 -1
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_package.py +1 -1
- rag_python-0.3.1/tests/test_streaming.py +38 -0
- rag_python-0.3.0/PKG-INFO +0 -180
- rag_python-0.3.0/README.md +0 -128
- rag_python-0.3.0/src/rag_python/cli.py +0 -127
- rag_python-0.3.0/src/rag_python/generation.py +0 -35
- rag_python-0.3.0/src/rag_python/rag_pipeline.py +0 -247
- rag_python-0.3.0/src/rag_python.egg-info/PKG-INFO +0 -180
- {rag_python-0.3.0 → rag_python-0.3.1}/LICENSE +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/setup.cfg +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/chunking.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/cleaning.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/config.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/document_loaders.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/evaluation.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/guardrails.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/hybrid_search.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/options.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/__init__.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/factory.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/gemini_provider.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/providers/local_provider.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/py.typed +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/query_rewriting.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/reranker.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/retrieval.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python/vector_store.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python.egg-info/dependency_links.txt +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python.egg-info/entry_points.txt +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python.egg-info/requires.txt +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/src/rag_python.egg-info/top_level.txt +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_chunking.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_config.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_hybrid_search.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_loaders.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_pipeline.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_providers.py +0 -0
- {rag_python-0.3.0 → rag_python-0.3.1}/tests/test_retrieval.py +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: rag-python
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Production-grade RAG for Python: ingest documents, hybrid search, streaming, multi-LLM, guardrails. CLI + Python API.
|
|
5
|
+
Author-email: Raghav Singla <04raghavsingla28@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/RaghavOG/rag-python
|
|
8
|
+
Project-URL: Repository, https://github.com/RaghavOG/rag-python
|
|
9
|
+
Project-URL: Documentation, https://github.com/RaghavOG/rag-python/tree/main/docs
|
|
10
|
+
Project-URL: Changelog, https://github.com/RaghavOG/rag-python/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Issues, https://github.com/RaghavOG/rag-python/issues
|
|
12
|
+
Keywords: rag,llm,embeddings,chromadb,openai,rag-python,retrieval-augmented-generation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: openai>=1.12.0
|
|
26
|
+
Requires-Dist: tiktoken>=0.5.0
|
|
27
|
+
Requires-Dist: chromadb>=0.4.22
|
|
28
|
+
Requires-Dist: pypdf>=3.17.0
|
|
29
|
+
Requires-Dist: python-docx>=1.1.0
|
|
30
|
+
Requires-Dist: langdetect>=1.0.9
|
|
31
|
+
Requires-Dist: regex>=2023.0.0
|
|
32
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
33
|
+
Requires-Dist: requests>=2.31.0
|
|
34
|
+
Provides-Extra: rerank
|
|
35
|
+
Requires-Dist: sentence-transformers>=2.2.0; extra == "rerank"
|
|
36
|
+
Requires-Dist: torch>=2.0.0; extra == "rerank"
|
|
37
|
+
Provides-Extra: local
|
|
38
|
+
Requires-Dist: sentence-transformers>=2.2.0; extra == "local"
|
|
39
|
+
Provides-Extra: hybrid
|
|
40
|
+
Requires-Dist: rank-bm25>=0.2.2; extra == "hybrid"
|
|
41
|
+
Provides-Extra: anthropic
|
|
42
|
+
Requires-Dist: anthropic>=0.20.0; extra == "anthropic"
|
|
43
|
+
Provides-Extra: gemini
|
|
44
|
+
Requires-Dist: google-genai>=0.3.0; extra == "gemini"
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
47
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
48
|
+
Requires-Dist: build; extra == "dev"
|
|
49
|
+
Requires-Dist: twine; extra == "dev"
|
|
50
|
+
Requires-Dist: rank-bm25>=0.2.2; extra == "dev"
|
|
51
|
+
Provides-Extra: all
|
|
52
|
+
Requires-Dist: rag-python[anthropic,gemini,hybrid,local,rerank]; extra == "all"
|
|
53
|
+
|
|
54
|
+
# rag-python
|
|
55
|
+
|
|
56
|
+
[](https://pypi.org/project/rag-python/)
|
|
57
|
+
[](https://pypi.org/project/rag-python/)
|
|
58
|
+
[](https://www.python.org/downloads/)
|
|
59
|
+
[](LICENSE)
|
|
60
|
+
[](https://github.com/RaghavOG/rag-python/tree/main/docs)
|
|
61
|
+
|
|
62
|
+
**Production-grade Retrieval-Augmented Generation (RAG) for Python** — ingest documents, ask questions, get grounded answers with multi-LLM support, hybrid search, streaming, and guardrails.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install rag-python
|
|
66
|
+
export OPENAI_API_KEY=sk-...
|
|
67
|
+
rag-python ingest ./docs --reindex
|
|
68
|
+
rag-python query "What is our leave policy?"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Author:** [Raghav Singla](https://github.com/RaghavOG) · **Repo:** [github.com/RaghavOG/rag-python](https://github.com/RaghavOG/rag-python)
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Why rag-python?
|
|
76
|
+
|
|
77
|
+
| Capability | What you get |
|
|
78
|
+
|------------|--------------|
|
|
79
|
+
| **Ingest** | TXT, MD, PDF, DOCX, CSV, JSON, HTML → chunk → embed → ChromaDB |
|
|
80
|
+
| **Retrieve** | Multi-query rewriting, **hybrid BM25+vector**, reranking, metadata filters |
|
|
81
|
+
| **Generate** | Multi-LLM answers with guardrails, evaluation, and retry loop |
|
|
82
|
+
| **Stream** | `rag.query_stream()` and `--stream` CLI for responsive UX |
|
|
83
|
+
| **Offline** | Local embeddings via sentence-transformers |
|
|
84
|
+
| **CLI** | `rag-python ingest`, `query`, `docs` — no code required |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Install
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install rag-python
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
| Extra | Install | Enables |
|
|
95
|
+
|-------|---------|---------|
|
|
96
|
+
| `local` | `pip install rag-python[local]` | Offline embeddings (sentence-transformers) |
|
|
97
|
+
| `hybrid` | `pip install rag-python[hybrid]` | BM25 + vector hybrid retrieval |
|
|
98
|
+
| `rerank` | `pip install rag-python[rerank]` | Cross-encoder reranking |
|
|
99
|
+
| `anthropic` | `pip install rag-python[anthropic]` | Claude LLM |
|
|
100
|
+
| `gemini` | `pip install rag-python[gemini]` | Gemini LLM |
|
|
101
|
+
| `all` | `pip install rag-python[all]` | All optional features |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Quickstart (Python)
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from rag_python import RAG
|
|
109
|
+
|
|
110
|
+
rag = RAG(llm_model="gpt-4o-mini")
|
|
111
|
+
rag.ingest(["./data"], reindex=True)
|
|
112
|
+
|
|
113
|
+
answer = rag.query("How many days of annual leave?")
|
|
114
|
+
print(answer.text)
|
|
115
|
+
print(answer.sources)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Streaming
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
stream = rag.query_stream("How many days of annual leave?")
|
|
122
|
+
for token in stream:
|
|
123
|
+
print(token, end="", flush=True)
|
|
124
|
+
print(stream.result.evaluation)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Hybrid search + metadata filter
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
rag = RAG(
|
|
131
|
+
retriever="hybrid", # pip install rag-python[hybrid]
|
|
132
|
+
metadata_filter={"filename": "leave-policy.pdf"},
|
|
133
|
+
)
|
|
134
|
+
rag.ingest(["./policies/"])
|
|
135
|
+
print(rag.query("annual leave policy").text)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Quickstart (CLI)
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
export OPENAI_API_KEY=sk-...
|
|
144
|
+
|
|
145
|
+
rag-python ingest ./data --reindex
|
|
146
|
+
rag-python query "How many days of annual leave?"
|
|
147
|
+
rag-python query "PTO policy" --stream -v
|
|
148
|
+
rag-python query "benefits" --retriever hybrid
|
|
149
|
+
|
|
150
|
+
# Built-in terminal docs
|
|
151
|
+
rag-python docs quickstart
|
|
152
|
+
rag-python docs --list
|
|
153
|
+
rag-python --help
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Documentation
|
|
159
|
+
|
|
160
|
+
| Guide | Description |
|
|
161
|
+
|-------|-------------|
|
|
162
|
+
| [**Docs index**](docs/README.md) | Start here |
|
|
163
|
+
| [Usage](docs/USAGE.md) | Python API, streaming, retrieval |
|
|
164
|
+
| [CLI reference](docs/CLI.md) | All `rag-python` commands and flags |
|
|
165
|
+
| [Configuration](docs/CONFIGURATION.md) | Env vars and `RAGConfig` |
|
|
166
|
+
| [Providers](docs/PROVIDERS.md) | OpenAI, Azure, Anthropic, Gemini, Ollama, local |
|
|
167
|
+
| [Changelog](CHANGELOG.md) | Release notes |
|
|
168
|
+
|
|
169
|
+
**In the terminal:** `rag-python docs [topic]` — topics: `quickstart`, `install`, `cli`, `config`, `providers`, `features`
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Environment variables
|
|
174
|
+
|
|
175
|
+
| Variable | Description |
|
|
176
|
+
|----------|-------------|
|
|
177
|
+
| `OPENAI_API_KEY` | Default LLM + embeddings |
|
|
178
|
+
| `ANTHROPIC_API_KEY` | Claude |
|
|
179
|
+
| `GEMINI_API_KEY` | Gemini |
|
|
180
|
+
| `AZURE_OPENAI_ENDPOINT` / `AZURE_OPENAI_API_KEY` | Azure OpenAI |
|
|
181
|
+
| `OLLAMA_BASE_URL` | Local Ollama (default `http://localhost:11434`) |
|
|
182
|
+
| `RAG_PYTHON_DATA_DIR` | Document dir (default `./data`) |
|
|
183
|
+
| `RAG_PYTHON_CHROMA_DIR` | Vector store (default `./chroma_db`) |
|
|
184
|
+
|
|
185
|
+
See [Configuration](docs/CONFIGURATION.md) and [`.env.example`](.env.example).
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Project layout
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
src/rag_python/ # pip install rag-python → import rag_python
|
|
193
|
+
client.py # RAG, RAGAnswer, query_stream
|
|
194
|
+
rag_pipeline.py # ingest / query pipeline
|
|
195
|
+
providers/ # OpenAI, Azure, Anthropic, Gemini, Ollama, local
|
|
196
|
+
docs/ # User documentation (linked from PyPI README)
|
|
197
|
+
tests/
|
|
198
|
+
examples/
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT © [Raghav Singla](https://github.com/RaghavOG)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# rag-python
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/rag-python/)
|
|
4
|
+
[](https://pypi.org/project/rag-python/)
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://github.com/RaghavOG/rag-python/tree/main/docs)
|
|
8
|
+
|
|
9
|
+
**Production-grade Retrieval-Augmented Generation (RAG) for Python** — ingest documents, ask questions, get grounded answers with multi-LLM support, hybrid search, streaming, and guardrails.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install rag-python
|
|
13
|
+
export OPENAI_API_KEY=sk-...
|
|
14
|
+
rag-python ingest ./docs --reindex
|
|
15
|
+
rag-python query "What is our leave policy?"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Author:** [Raghav Singla](https://github.com/RaghavOG) · **Repo:** [github.com/RaghavOG/rag-python](https://github.com/RaghavOG/rag-python)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Why rag-python?
|
|
23
|
+
|
|
24
|
+
| Capability | What you get |
|
|
25
|
+
|------------|--------------|
|
|
26
|
+
| **Ingest** | TXT, MD, PDF, DOCX, CSV, JSON, HTML → chunk → embed → ChromaDB |
|
|
27
|
+
| **Retrieve** | Multi-query rewriting, **hybrid BM25+vector**, reranking, metadata filters |
|
|
28
|
+
| **Generate** | Multi-LLM answers with guardrails, evaluation, and retry loop |
|
|
29
|
+
| **Stream** | `rag.query_stream()` and `--stream` CLI for responsive UX |
|
|
30
|
+
| **Offline** | Local embeddings via sentence-transformers |
|
|
31
|
+
| **CLI** | `rag-python ingest`, `query`, `docs` — no code required |
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install rag-python
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Extra | Install | Enables |
|
|
42
|
+
|-------|---------|---------|
|
|
43
|
+
| `local` | `pip install rag-python[local]` | Offline embeddings (sentence-transformers) |
|
|
44
|
+
| `hybrid` | `pip install rag-python[hybrid]` | BM25 + vector hybrid retrieval |
|
|
45
|
+
| `rerank` | `pip install rag-python[rerank]` | Cross-encoder reranking |
|
|
46
|
+
| `anthropic` | `pip install rag-python[anthropic]` | Claude LLM |
|
|
47
|
+
| `gemini` | `pip install rag-python[gemini]` | Gemini LLM |
|
|
48
|
+
| `all` | `pip install rag-python[all]` | All optional features |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Quickstart (Python)
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from rag_python import RAG
|
|
56
|
+
|
|
57
|
+
rag = RAG(llm_model="gpt-4o-mini")
|
|
58
|
+
rag.ingest(["./data"], reindex=True)
|
|
59
|
+
|
|
60
|
+
answer = rag.query("How many days of annual leave?")
|
|
61
|
+
print(answer.text)
|
|
62
|
+
print(answer.sources)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Streaming
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
stream = rag.query_stream("How many days of annual leave?")
|
|
69
|
+
for token in stream:
|
|
70
|
+
print(token, end="", flush=True)
|
|
71
|
+
print(stream.result.evaluation)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Hybrid search + metadata filter
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
rag = RAG(
|
|
78
|
+
retriever="hybrid", # pip install rag-python[hybrid]
|
|
79
|
+
metadata_filter={"filename": "leave-policy.pdf"},
|
|
80
|
+
)
|
|
81
|
+
rag.ingest(["./policies/"])
|
|
82
|
+
print(rag.query("annual leave policy").text)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Quickstart (CLI)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
export OPENAI_API_KEY=sk-...
|
|
91
|
+
|
|
92
|
+
rag-python ingest ./data --reindex
|
|
93
|
+
rag-python query "How many days of annual leave?"
|
|
94
|
+
rag-python query "PTO policy" --stream -v
|
|
95
|
+
rag-python query "benefits" --retriever hybrid
|
|
96
|
+
|
|
97
|
+
# Built-in terminal docs
|
|
98
|
+
rag-python docs quickstart
|
|
99
|
+
rag-python docs --list
|
|
100
|
+
rag-python --help
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Documentation
|
|
106
|
+
|
|
107
|
+
| Guide | Description |
|
|
108
|
+
|-------|-------------|
|
|
109
|
+
| [**Docs index**](docs/README.md) | Start here |
|
|
110
|
+
| [Usage](docs/USAGE.md) | Python API, streaming, retrieval |
|
|
111
|
+
| [CLI reference](docs/CLI.md) | All `rag-python` commands and flags |
|
|
112
|
+
| [Configuration](docs/CONFIGURATION.md) | Env vars and `RAGConfig` |
|
|
113
|
+
| [Providers](docs/PROVIDERS.md) | OpenAI, Azure, Anthropic, Gemini, Ollama, local |
|
|
114
|
+
| [Changelog](CHANGELOG.md) | Release notes |
|
|
115
|
+
|
|
116
|
+
**In the terminal:** `rag-python docs [topic]` — topics: `quickstart`, `install`, `cli`, `config`, `providers`, `features`
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Environment variables
|
|
121
|
+
|
|
122
|
+
| Variable | Description |
|
|
123
|
+
|----------|-------------|
|
|
124
|
+
| `OPENAI_API_KEY` | Default LLM + embeddings |
|
|
125
|
+
| `ANTHROPIC_API_KEY` | Claude |
|
|
126
|
+
| `GEMINI_API_KEY` | Gemini |
|
|
127
|
+
| `AZURE_OPENAI_ENDPOINT` / `AZURE_OPENAI_API_KEY` | Azure OpenAI |
|
|
128
|
+
| `OLLAMA_BASE_URL` | Local Ollama (default `http://localhost:11434`) |
|
|
129
|
+
| `RAG_PYTHON_DATA_DIR` | Document dir (default `./data`) |
|
|
130
|
+
| `RAG_PYTHON_CHROMA_DIR` | Vector store (default `./chroma_db`) |
|
|
131
|
+
|
|
132
|
+
See [Configuration](docs/CONFIGURATION.md) and [`.env.example`](.env.example).
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Project layout
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
src/rag_python/ # pip install rag-python → import rag_python
|
|
140
|
+
client.py # RAG, RAGAnswer, query_stream
|
|
141
|
+
rag_pipeline.py # ingest / query pipeline
|
|
142
|
+
providers/ # OpenAI, Azure, Anthropic, Gemini, Ollama, local
|
|
143
|
+
docs/ # User documentation (linked from PyPI README)
|
|
144
|
+
tests/
|
|
145
|
+
examples/
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT © [Raghav Singla](https://github.com/RaghavOG)
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rag-python"
|
|
7
|
-
version = "0.3.
|
|
8
|
-
description = "Production-grade RAG for Python:
|
|
7
|
+
version = "0.3.1"
|
|
8
|
+
description = "Production-grade RAG for Python: ingest documents, hybrid search, streaming, multi-LLM, guardrails. CLI + Python API."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
11
11
|
requires-python = ">=3.10"
|
|
@@ -51,7 +51,8 @@ rag-python = "rag_python.cli:main"
|
|
|
51
51
|
[project.urls]
|
|
52
52
|
Homepage = "https://github.com/RaghavOG/rag-python"
|
|
53
53
|
Repository = "https://github.com/RaghavOG/rag-python"
|
|
54
|
-
Documentation = "https://github.com/RaghavOG/rag-python
|
|
54
|
+
Documentation = "https://github.com/RaghavOG/rag-python/tree/main/docs"
|
|
55
|
+
Changelog = "https://github.com/RaghavOG/rag-python/blob/main/CHANGELOG.md"
|
|
55
56
|
Issues = "https://github.com/RaghavOG/rag-python/issues"
|
|
56
57
|
|
|
57
58
|
[tool.setuptools.packages.find]
|
|
@@ -2,18 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
Quick start::
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
pip install rag-python
|
|
6
|
+
export OPENAI_API_KEY=sk-...
|
|
7
|
+
|
|
8
|
+
# CLI
|
|
9
|
+
rag-python ingest ./docs --reindex
|
|
10
|
+
rag-python query "What is our leave policy?"
|
|
11
|
+
rag-python docs quickstart
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
# Python
|
|
14
|
+
from rag_python import RAG
|
|
15
|
+
rag = RAG()
|
|
8
16
|
rag.ingest(["./docs"], reindex=True)
|
|
9
17
|
print(rag.query("What is our leave policy?").text)
|
|
18
|
+
|
|
19
|
+
Documentation: https://github.com/RaghavOG/rag-python/tree/main/docs
|
|
10
20
|
"""
|
|
11
21
|
|
|
12
|
-
__version__ = "0.3.
|
|
22
|
+
__version__ = "0.3.1"
|
|
13
23
|
|
|
14
24
|
from .client import RAG, RAGAnswer
|
|
15
|
-
from .rag_pipeline import ingest, query, RAGResponse
|
|
25
|
+
from .rag_pipeline import ingest, query, query_stream, RAGResponse, RAGStream
|
|
16
26
|
from .providers import make_llm_provider, make_embedding_provider
|
|
27
|
+
from .log import configure_logging, get_logger
|
|
17
28
|
from .options import (
|
|
18
29
|
ChunkingConfig,
|
|
19
30
|
DocumentConfig,
|
|
@@ -33,7 +44,11 @@ __all__ = [
|
|
|
33
44
|
"QueryConfig",
|
|
34
45
|
"ingest",
|
|
35
46
|
"query",
|
|
47
|
+
"query_stream",
|
|
48
|
+
"RAGStream",
|
|
36
49
|
"RAGResponse",
|
|
50
|
+
"configure_logging",
|
|
51
|
+
"get_logger",
|
|
37
52
|
"make_llm_provider",
|
|
38
53
|
"make_embedding_provider",
|
|
39
54
|
]
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""rag-python command-line interface."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import replace
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .client import RAG
|
|
11
|
+
from .help_text import CLI_EPILOG, list_topics, print_topic, print_topic_list
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _build_rag(args: argparse.Namespace) -> RAG:
|
|
15
|
+
kwargs: dict = dict(
|
|
16
|
+
llm_provider=args.llm_provider,
|
|
17
|
+
llm_model=args.llm_model,
|
|
18
|
+
embedding_provider=args.embedding_provider,
|
|
19
|
+
embedding_model=args.embedding_model,
|
|
20
|
+
openai_api_key=args.openai_api_key,
|
|
21
|
+
azure_endpoint=args.azure_endpoint,
|
|
22
|
+
azure_api_key=args.azure_api_key,
|
|
23
|
+
azure_api_version=args.azure_api_version,
|
|
24
|
+
anthropic_api_key=args.anthropic_api_key,
|
|
25
|
+
gemini_api_key=args.gemini_api_key,
|
|
26
|
+
ollama_base_url=args.ollama_base_url,
|
|
27
|
+
)
|
|
28
|
+
if getattr(args, "retriever", None):
|
|
29
|
+
kwargs["retriever"] = args.retriever
|
|
30
|
+
if getattr(args, "metadata_filter", None):
|
|
31
|
+
kwargs["metadata_filter"] = args.metadata_filter
|
|
32
|
+
return RAG(**kwargs)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _parse_metadata_filter(raw: str | None) -> dict | None:
|
|
36
|
+
if not raw:
|
|
37
|
+
return None
|
|
38
|
+
try:
|
|
39
|
+
return json.loads(raw)
|
|
40
|
+
except json.JSONDecodeError as e:
|
|
41
|
+
raise argparse.ArgumentTypeError(f"Invalid JSON for metadata filter: {e}") from e
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _add_provider_args(parser: argparse.ArgumentParser) -> None:
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--llm-provider",
|
|
47
|
+
default="openai",
|
|
48
|
+
choices=["openai", "azure_openai", "anthropic", "gemini", "ollama"],
|
|
49
|
+
metavar="PROVIDER",
|
|
50
|
+
help="LLM backend (default: openai). See: rag-python docs providers",
|
|
51
|
+
)
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"--llm-model",
|
|
54
|
+
default=None,
|
|
55
|
+
metavar="MODEL",
|
|
56
|
+
help="LLM model or Azure deployment name (default: from env LLM_MODEL)",
|
|
57
|
+
)
|
|
58
|
+
parser.add_argument(
|
|
59
|
+
"--embedding-provider",
|
|
60
|
+
default="openai",
|
|
61
|
+
choices=["openai", "azure_openai", "ollama", "local"],
|
|
62
|
+
metavar="PROVIDER",
|
|
63
|
+
help="Embedding backend (default: openai). Use local for offline embeddings",
|
|
64
|
+
)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"--embedding-model",
|
|
67
|
+
default=None,
|
|
68
|
+
metavar="MODEL",
|
|
69
|
+
help="Embedding model name (default: from env EMBEDDING_MODEL)",
|
|
70
|
+
)
|
|
71
|
+
parser.add_argument(
|
|
72
|
+
"--ollama-base-url",
|
|
73
|
+
default=None,
|
|
74
|
+
metavar="URL",
|
|
75
|
+
help="Ollama server URL (default: http://localhost:11434 or OLLAMA_BASE_URL)",
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument("--azure-endpoint", default=None, help="Azure OpenAI endpoint URL")
|
|
78
|
+
parser.add_argument("--azure-api-key", default=None, help="Azure OpenAI API key")
|
|
79
|
+
parser.add_argument(
|
|
80
|
+
"--azure-api-version",
|
|
81
|
+
default=None,
|
|
82
|
+
help="Azure API version (default: 2023-09-01-preview)",
|
|
83
|
+
)
|
|
84
|
+
parser.add_argument("--openai-api-key", default=None, help="OpenAI API key (overrides env)")
|
|
85
|
+
parser.add_argument("--anthropic-api-key", default=None, help="Anthropic API key")
|
|
86
|
+
parser.add_argument("--gemini-api-key", default=None, help="Gemini API key")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _add_search_args(parser: argparse.ArgumentParser) -> None:
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"--retriever",
|
|
92
|
+
choices=["vector", "multi_query", "hybrid"],
|
|
93
|
+
default=None,
|
|
94
|
+
metavar="MODE",
|
|
95
|
+
help=(
|
|
96
|
+
"Retrieval mode: vector (single query), multi_query (default, with rewriting), "
|
|
97
|
+
"or hybrid (BM25+vector; requires pip install rag-python[hybrid])"
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
parser.add_argument(
|
|
101
|
+
"--metadata-filter",
|
|
102
|
+
type=_parse_metadata_filter,
|
|
103
|
+
default=None,
|
|
104
|
+
metavar="JSON",
|
|
105
|
+
help='Filter chunks by metadata, e.g. \'{"filename": "policy.pdf"}\'',
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _make_parser() -> argparse.ArgumentParser:
|
|
110
|
+
parser = argparse.ArgumentParser(
|
|
111
|
+
prog="rag-python",
|
|
112
|
+
description=(
|
|
113
|
+
"Production-grade RAG for Python — ingest documents, ask questions, "
|
|
114
|
+
"get grounded answers with multi-LLM support."
|
|
115
|
+
),
|
|
116
|
+
epilog=CLI_EPILOG,
|
|
117
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
118
|
+
)
|
|
119
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
120
|
+
sub = parser.add_subparsers(dest="command", required=True, metavar="COMMAND")
|
|
121
|
+
|
|
122
|
+
ing = sub.add_parser(
|
|
123
|
+
"ingest",
|
|
124
|
+
help="Load files into the vector store (chunk + embed)",
|
|
125
|
+
description=(
|
|
126
|
+
"Ingest one or more files or directories into the ChromaDB vector store.\n"
|
|
127
|
+
"Supported formats: .txt .md .pdf .docx .csv .json .html"
|
|
128
|
+
),
|
|
129
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
130
|
+
epilog=(
|
|
131
|
+
"examples:\n"
|
|
132
|
+
" rag-python ingest ./data --reindex\n"
|
|
133
|
+
" rag-python ingest policy.pdf handbook/ --embedding-provider local"
|
|
134
|
+
),
|
|
135
|
+
)
|
|
136
|
+
ing.add_argument(
|
|
137
|
+
"paths",
|
|
138
|
+
nargs="+",
|
|
139
|
+
metavar="PATH",
|
|
140
|
+
help="File or directory paths to ingest",
|
|
141
|
+
)
|
|
142
|
+
ing.add_argument(
|
|
143
|
+
"--reindex",
|
|
144
|
+
action="store_true",
|
|
145
|
+
help="Delete existing vectors before ingesting (fresh index)",
|
|
146
|
+
)
|
|
147
|
+
_add_provider_args(ing)
|
|
148
|
+
|
|
149
|
+
q = sub.add_parser(
|
|
150
|
+
"query",
|
|
151
|
+
help="Ask a question against ingested documents",
|
|
152
|
+
description=(
|
|
153
|
+
"Run the full RAG pipeline: retrieve relevant chunks, generate an answer, "
|
|
154
|
+
"optionally stream tokens and show sources."
|
|
155
|
+
),
|
|
156
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
157
|
+
epilog=(
|
|
158
|
+
"examples:\n"
|
|
159
|
+
' rag-python query "How many days of annual leave?"\n'
|
|
160
|
+
" rag-python query \"PTO policy\" --stream -v\n"
|
|
161
|
+
' rag-python query "benefits" --retriever hybrid --metadata-filter \'{"filename": "hr.pdf"}\''
|
|
162
|
+
),
|
|
163
|
+
)
|
|
164
|
+
q.add_argument(
|
|
165
|
+
"question",
|
|
166
|
+
nargs="+",
|
|
167
|
+
metavar="QUESTION",
|
|
168
|
+
help="Question text (multiple words are joined)",
|
|
169
|
+
)
|
|
170
|
+
q.add_argument(
|
|
171
|
+
"--no-multi-query",
|
|
172
|
+
action="store_true",
|
|
173
|
+
help="Use single-query vector retrieval (same as --retriever vector)",
|
|
174
|
+
)
|
|
175
|
+
q.add_argument(
|
|
176
|
+
"--stream",
|
|
177
|
+
action="store_true",
|
|
178
|
+
help="Stream answer tokens to stdout as they are generated",
|
|
179
|
+
)
|
|
180
|
+
q.add_argument(
|
|
181
|
+
"-v",
|
|
182
|
+
"--verbose",
|
|
183
|
+
action="store_true",
|
|
184
|
+
help="After the answer, print evaluation scores and top source paths",
|
|
185
|
+
)
|
|
186
|
+
_add_provider_args(q)
|
|
187
|
+
_add_search_args(q)
|
|
188
|
+
|
|
189
|
+
docs = sub.add_parser(
|
|
190
|
+
"docs",
|
|
191
|
+
help="Show user documentation in the terminal",
|
|
192
|
+
description="Print built-in help topics. Full docs: https://github.com/RaghavOG/rag-python/tree/main/docs",
|
|
193
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
194
|
+
epilog="topics: " + ", ".join(list_topics()),
|
|
195
|
+
)
|
|
196
|
+
docs.add_argument(
|
|
197
|
+
"topic",
|
|
198
|
+
nargs="?",
|
|
199
|
+
default="quickstart",
|
|
200
|
+
choices=list_topics(),
|
|
201
|
+
metavar="TOPIC",
|
|
202
|
+
help="Documentation topic (default: quickstart)",
|
|
203
|
+
)
|
|
204
|
+
docs.add_argument(
|
|
205
|
+
"--list",
|
|
206
|
+
action="store_true",
|
|
207
|
+
help="List all available documentation topics",
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
return parser
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def main(argv: list[str] | None = None) -> None:
|
|
214
|
+
parser = _make_parser()
|
|
215
|
+
args = parser.parse_args(argv)
|
|
216
|
+
|
|
217
|
+
if args.command == "docs":
|
|
218
|
+
if args.list:
|
|
219
|
+
print_topic_list()
|
|
220
|
+
else:
|
|
221
|
+
print_topic(args.topic)
|
|
222
|
+
return
|
|
223
|
+
|
|
224
|
+
if args.command == "ingest":
|
|
225
|
+
rag = _build_rag(args)
|
|
226
|
+
n = rag.ingest(args.paths, reindex=args.reindex)
|
|
227
|
+
print(f"Ingested {n} chunks.")
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
if args.command == "query":
|
|
231
|
+
rag = _build_rag(args)
|
|
232
|
+
question = " ".join(args.question)
|
|
233
|
+
retriever = args.retriever
|
|
234
|
+
if retriever is None and args.no_multi_query:
|
|
235
|
+
retriever = "vector"
|
|
236
|
+
search = replace(
|
|
237
|
+
rag.config.search,
|
|
238
|
+
retriever=retriever or rag.config.search.retriever,
|
|
239
|
+
metadata_filter=args.metadata_filter or rag.config.search.metadata_filter,
|
|
240
|
+
)
|
|
241
|
+
if args.stream:
|
|
242
|
+
stream = rag.query_stream(question, search=search)
|
|
243
|
+
for token in stream:
|
|
244
|
+
print(token, end="", flush=True)
|
|
245
|
+
print()
|
|
246
|
+
result = stream.result
|
|
247
|
+
if args.verbose:
|
|
248
|
+
print("\n--- evaluation ---")
|
|
249
|
+
print(result.evaluation)
|
|
250
|
+
print("\n--- sources ---")
|
|
251
|
+
for s in result.sources[:5]:
|
|
252
|
+
print(s.get("metadata", {}).get("source", ""), "score:", s.get("score"))
|
|
253
|
+
return
|
|
254
|
+
|
|
255
|
+
ans = rag.query(question, search=search)
|
|
256
|
+
print(ans.text)
|
|
257
|
+
if args.verbose:
|
|
258
|
+
print("\n--- evaluation ---")
|
|
259
|
+
print(ans.evaluation)
|
|
260
|
+
print("\n--- sources ---")
|
|
261
|
+
for s in ans.sources[:5]:
|
|
262
|
+
print(s.get("metadata", {}).get("source", ""), "score:", s.get("score"))
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
if __name__ == "__main__":
|
|
266
|
+
main(sys.argv[1:])
|