ragtrace 0.2.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.
ragtrace-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RAG Debugger Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,403 @@
1
+ Metadata-Version: 2.4
2
+ Name: ragtrace
3
+ Version: 0.2.0
4
+ Summary: Observability and tracing for Retrieval-Augmented Generation pipelines
5
+ License-File: LICENSE
6
+ Author: Sabyasachi Ghosh
7
+ Requires-Python: >=3.9,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Requires-Dist: click (>=8.1.0,<9.0.0)
16
+ Requires-Dist: fastapi (>=0.109.0,<0.110.0)
17
+ Requires-Dist: langchain (>=0.1.0,<0.2.0)
18
+ Requires-Dist: langchain-community (>=0.0.20,<0.0.21)
19
+ Requires-Dist: langchain-openai (>=0.0.5,<0.0.6)
20
+ Requires-Dist: openai (>=1.0.0,<2.0.0)
21
+ Requires-Dist: pydantic (>=2.5.0,<3.0.0)
22
+ Requires-Dist: rich (>=13.7.0,<14.0.0)
23
+ Requires-Dist: sqlalchemy (>=2.0.0,<3.0.0)
24
+ Requires-Dist: tiktoken (>=0.5.0,<0.6.0)
25
+ Requires-Dist: uvicorn[standard] (>=0.27.0,<0.28.0)
26
+ Description-Content-Type: text/markdown
27
+
28
+ # RAGTrace 📊
29
+
30
+ > **Observability for RAG pipelines** - Trace, inspect, and optimize Retrieval-Augmented Generation systems with ease.
31
+
32
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
33
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
34
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
35
+
36
+ ## ✨ What is RAGTrace?
37
+
38
+ RAGTrace is a lightweight observability layer for RAG (Retrieval-Augmented Generation) systems that captures and visualizes every step of your pipeline:
39
+
40
+ - 🔍 **Event Capture** - Automatically intercepts retrieval, prompt, and generation events
41
+ - 💰 **Cost Tracking** - Accurate token counting and cost estimation per query
42
+ - 📊 **Interactive Web UI** - Modern timeline view with charts, filters, and event inspection
43
+ - 🔧 **CLI Tool** - Developer-friendly command-line interface
44
+ - 🌐 **REST API** - Query and analyze sessions programmatically
45
+ - 🧪 **Regression Testing** - Snapshot and compare RAG outputs
46
+
47
+ **Think of it as OpenTelemetry, but specifically for RAG pipelines.**
48
+
49
+ ## 🚀 Quick Start
50
+
51
+ ### Installation
52
+
53
+ ```bash
54
+ # Clone the repository
55
+ git clone https://github.com/yourusername/ragtrace.git
56
+ cd ragtrace
57
+
58
+ # Install dependencies (using pip)
59
+ pip install -e .
60
+
61
+ # Or using Poetry
62
+ poetry install
63
+ poetry shell
64
+
65
+ # Initialize database
66
+ ragtrace init
67
+ ```
68
+
69
+ ### Basic Usage
70
+
71
+ ```python
72
+ from langchain.vectorstores import FAISS
73
+ from langchain.embeddings import OpenAIEmbeddings
74
+ from langchain.chat_models import ChatOpenAI
75
+ from langchain.chains import RetrievalQA
76
+ from ragtrace import RagTracer
77
+
78
+ # Your existing RAG setup
79
+ embeddings = OpenAIEmbeddings()
80
+ vectorstore = FAISS.from_texts(["Your documents here..."], embeddings)
81
+ llm = ChatOpenAI(model="gpt-3.5-turbo")
82
+
83
+ # Add RAGTrace - just one line!
84
+ tracer = RagTracer(auto_save=True)
85
+
86
+ # Create chain with tracer
87
+ chain = RetrievalQA.from_chain_type(
88
+ llm=llm,
89
+ retriever=vectorstore.as_retriever(),
90
+ callbacks=[tracer] # ← Automatic capture!
91
+ )
92
+
93
+ # Run your query (automatically captured)
94
+ result = chain.run("What is RAG?")
95
+ ```
96
+
97
+ ### View Results
98
+
99
+ ```bash
100
+ # View latest session in CLI
101
+ ragtrace show last
102
+
103
+ # List all sessions
104
+ ragtrace list
105
+
106
+ # Export to JSON
107
+ ragtrace export <session-id> > session.json
108
+
109
+ # Start API server (for Web UI)
110
+ ragtrace run
111
+
112
+ # Or start both servers for full Web UI experience
113
+ uvicorn api.main:app --port 8000 & # API server
114
+ python ui/serve.py # UI server → http://localhost:3000
115
+ ```
116
+
117
+ ## 🌐 Web UI
118
+
119
+ RAGTrace includes a modern web interface for visualizing and analyzing your RAG pipelines:
120
+
121
+ ### Start the Servers
122
+
123
+ ```bash
124
+ # Terminal 1: Start API server
125
+ cd ragtrace
126
+ source venv/bin/activate
127
+ uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload
128
+
129
+ # Terminal 2: Start UI server
130
+ cd ragtrace
131
+ python ui/serve.py
132
+ ```
133
+
134
+ Then open **http://localhost:3000** in your browser.
135
+
136
+ ### Web UI Features
137
+
138
+ - **📋 Sessions View** - Browse all captured RAG sessions with search and filtering
139
+ - **📊 Timeline View** - Interactive timeline showing retrieval → prompt → generation flow
140
+ - **📈 Performance Charts** - Waterfall chart for event durations, cost breakdown by component
141
+ - **🔍 Event Inspector** - Click any event to see full details including tokens, costs, and data
142
+ - **🎯 Smart Filters** - Filter events by type, duration, and cost
143
+ - **📤 Export Tools** - Export session data as JSON or CSV, copy to clipboard
144
+
145
+ ### Quick UI Guide
146
+
147
+ 1. **Sessions Tab**: View all RAG sessions, sorted by recent activity
148
+ 2. **Timeline Tab**: Click on any session to see detailed event timeline
149
+ 3. **Click Events**: Click timeline events to inspect full details
150
+ 4. **Apply Filters**: Use dropdowns to filter by event type or performance metrics
151
+ 5. **Export Data**: Use export buttons to download session data
152
+
153
+
154
+ ## 📊 Example Output
155
+
156
+ ```
157
+ ╭─ Session: d4f3a8b2-... ─────────────────────────────────╮
158
+ │ Query: What is RAG? │
159
+ │ Model: gpt-3.5-turbo │
160
+ │ Cost: $0.00360 │
161
+ │ Duration: 1,850ms │
162
+ ╰──────────────────────────────────────────────────────────╯
163
+
164
+ ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
165
+ ┃ Event ┃ Duration ┃ Cost ┃
166
+ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
167
+ │ Retrieval │ 150ms │ $0.00001 │
168
+ │ Prompt │ 0ms │ $0.00000 │
169
+ │ Generation │ 1,700ms │ $0.00359 │
170
+ └─────────────┴────────────┴────────────┘
171
+ ```
172
+
173
+ ## 🎯 Features
174
+
175
+ ### ✅ Core Features
176
+
177
+ - **Automatic Event Capture** - Works with LangChain callbacks
178
+ - **Cost Tracking** - Uses tiktoken for accurate token counting
179
+ - **Timeline Visualization** - See your RAG pipeline in action
180
+ - **Session Management** - Store and retrieve debugging sessions
181
+ - **CLI Tool** - Rich formatted terminal output
182
+ - **REST API** - FastAPI server with OpenAPI docs
183
+ - **Web UI** - Interactive timeline with charts and event inspection
184
+ - **JSON/CSV Export** - Export sessions for analysis
185
+ - **Snapshot Testing** - Save and compare pipeline outputs
186
+
187
+ ### 🎨 Web UI Features
188
+
189
+ - **Sessions Dashboard** - View all sessions with search and sort
190
+ - **Interactive Timeline** - Click events to inspect details
191
+ - **Performance Waterfall** - Visualize event durations side-by-side
192
+ - **Cost Breakdown Chart** - See spending by component (embeddings, prompts, generation)
193
+ - **Smart Filters** - Filter by event type, duration, or cost
194
+ - **Real-time Updates** - WebSocket support for live session monitoring
195
+ - **Export Tools** - Download as JSON, CSV, or copy to clipboard
196
+
197
+ ### 🎨 CLI Commands
198
+
199
+ ```bash
200
+ ragtrace init # Initialize database
201
+ ragtrace list # List recent sessions
202
+ ragtrace show [id] # View session details
203
+ ragtrace show last # View latest session
204
+ ragtrace export <id> # Export to JSON
205
+ ragtrace clear # Clear all data
206
+ ragtrace snapshot save # Save snapshot
207
+ ragtrace snapshot list # List snapshots
208
+ ragtrace run # Start API server
209
+ ```
210
+
211
+ ### 🌐 API Endpoints
212
+
213
+ ```
214
+ POST /api/sessions # Create session
215
+ GET /api/sessions # List sessions
216
+ GET /api/sessions/{id} # Get session
217
+ PATCH /api/sessions/{id} # Update session
218
+ DELETE /api/sessions/{id} # Delete session
219
+ POST /api/sessions/{id}/events # Add event
220
+ GET /api/sessions/{id}/costs # Get costs
221
+ POST /api/snapshots # Create snapshot
222
+ GET /api/snapshots # List snapshots
223
+ GET /api/snapshots/{id1}/compare/{id2} # Compare snapshots
224
+ ```
225
+
226
+ Visit `http://localhost:8000/docs` after running `ragtrace run` for interactive API documentation.
227
+
228
+ ## 🏗️ Architecture
229
+
230
+ ```
231
+ ragtrace/
232
+ ├── core/ # Core business logic
233
+ │ ├── models.py # Pydantic data models
234
+ │ ├── storage.py # SQLite database layer
235
+ │ ├── cost.py # Token counting & cost calculation
236
+ │ └── capture.py # Event aggregation
237
+ ├── langchain/ # LangChain integration
238
+ │ └── middleware.py # Callback handler
239
+ ├── api/ # REST API (FastAPI)
240
+ │ ├── main.py # FastAPI application
241
+ │ └── routes.py # API endpoints
242
+ ├── ui/ # Web UI (HTML/CSS/JS)
243
+ │ ├── index.html # Main UI page
244
+ │ ├── app.js # Frontend application logic
245
+ │ ├── styles.css # UI styling
246
+ │ └── serve.py # Development server
247
+ ├── cli/ # Command-line interface
248
+ │ └── main.py # Click CLI commands
249
+ ├── examples/ # Usage examples
250
+ │ └── simple_rag.py # Complete working example
251
+ └── tests/ # Test suite
252
+ ├── test_cost.py # Cost calculation tests
253
+ ├── test_storage.py # Database tests
254
+ └── test_capture.py # Capture logic tests
255
+ ```
256
+
257
+ ## 📋 Requirements
258
+
259
+ - **Python**: 3.11+ (3.12 recommended)
260
+ - **Dependencies**: FastAPI, LangChain, tiktoken, Rich, Click
261
+ - **OpenAI API Key**: Required for examples (not for core functionality)
262
+
263
+ ## 🛠️ Development
264
+
265
+ ### Setup Development Environment
266
+
267
+ ```bash
268
+ # Clone repository
269
+ git clone https://github.com/yourusername/ragtrace.git
270
+ cd ragtrace
271
+
272
+ # Install with development dependencies
273
+ poetry install
274
+ poetry shell
275
+
276
+ # Run tests
277
+ pytest
278
+
279
+ # Run with coverage
280
+ pytest --cov=core --cov=langchain --cov=api --cov=cli
281
+ ```
282
+
283
+ ### Running Tests
284
+
285
+ ```bash
286
+ # All tests
287
+ pytest
288
+
289
+ # Specific test file
290
+ pytest tests/test_cost.py -v
291
+
292
+ # With coverage report
293
+ pytest --cov=core tests/
294
+ ```
295
+
296
+ ### Code Quality
297
+
298
+ ```bash
299
+ # Format code
300
+ black .
301
+
302
+ # Lint
303
+ ruff check .
304
+
305
+ # Type checking
306
+ mypy .
307
+ ```
308
+
309
+ ## 📖 Examples
310
+
311
+ Check out the `examples/` directory for complete working examples:
312
+
313
+ - **`simple_rag.py`** - Basic RAG pipeline with debugger
314
+ - **`with_sources.py`** - RAG with source tracking (coming soon)
315
+
316
+ ## 🔬 Use Cases
317
+
318
+ ### 1. Debug Failed Queries
319
+ ```bash
320
+ # See exactly why your RAG pipeline failed
321
+ ragtrace show last
322
+ ```
323
+
324
+ ### 2. Track Costs
325
+ ```bash
326
+ # Monitor spending per query
327
+ ragtrace list --sort-by cost
328
+ ```
329
+
330
+ ### 3. Identify Retrieval Issues
331
+ ```python
332
+ # Check which documents were retrieved
333
+ session = tracer.get_latest_session()
334
+ print(session.retrieval_event.chunks)
335
+ ```
336
+
337
+ ### 4. Regression Testing
338
+ ```bash
339
+ # Save baseline
340
+ ragtrace snapshot save "v1-baseline"
341
+
342
+ # Compare after changes
343
+ ragtrace snapshot compare <snapshot-id-1> <snapshot-id-2>
344
+ ```
345
+
346
+ ## 🤝 Contributing
347
+
348
+ Contributions are welcome! Please feel free to submit a Pull Request.
349
+
350
+ 1. Fork the repository
351
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
352
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
353
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
354
+ 5. Open a Pull Request
355
+
356
+ ## 📝 License
357
+
358
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
359
+
360
+ ## 🙏 Acknowledgments
361
+
362
+ - Built with [FastAPI](https://fastapi.tiangolo.com/)
363
+ - Integrated with [LangChain](https://python.langchain.com/)
364
+ - Token counting via [tiktoken](https://github.com/openai/tiktoken)
365
+ - Beautiful CLI with [Rich](https://rich.readthedocs.io/)
366
+
367
+ ## 📞 Support
368
+
369
+ - **Issues**: [GitHub Issues](https://github.com/yourusername/ragtrace/issues)
370
+ - **Documentation**: See [examples/](examples/) directory
371
+ - **API Docs**: Run `ragtrace run` and visit `http://localhost:8000/docs`
372
+
373
+ ## 🗺️ Roadmap
374
+
375
+ ### v0.2.0 (Current)
376
+ - [x] Web UI for timeline visualization
377
+ - [x] Interactive event inspection
378
+ - [x] Performance charts (waterfall, cost breakdown)
379
+ - [x] Export tools (JSON, CSV)
380
+ - [ ] Advanced regression testing
381
+ - [ ] LlamaIndex integration
382
+ - [ ] Prompt versioning
383
+
384
+ ### v0.3.0 (Planned)
385
+ - [ ] Agent tracing support
386
+ - [ ] Cost optimization suggestions
387
+ - [ ] Quality scoring
388
+ - [ ] Team collaboration features
389
+
390
+ ### v1.0.0
391
+ - [ ] Cloud mode
392
+ - [ ] Advanced analytics
393
+ - [ ] Alert system
394
+ - [ ] Multi-framework support
395
+
396
+ ## ⭐ Star History
397
+
398
+ If you find RAGTrace useful, please consider giving it a star! ⭐
399
+
400
+ ---
401
+
402
+ **Built with ❤️ for RAG developers**
403
+