contexttrace 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 (33) hide show
  1. contexttrace-0.1.0/MANIFEST.in +18 -0
  2. contexttrace-0.1.0/PKG-INFO +154 -0
  3. contexttrace-0.1.0/README.md +97 -0
  4. contexttrace-0.1.0/contexttrace/__init__.py +36 -0
  5. contexttrace-0.1.0/contexttrace/_version.py +1 -0
  6. contexttrace-0.1.0/contexttrace/cli.py +474 -0
  7. contexttrace-0.1.0/contexttrace/client.py +1074 -0
  8. contexttrace-0.1.0/contexttrace/config.py +246 -0
  9. contexttrace-0.1.0/contexttrace/demo.py +311 -0
  10. contexttrace-0.1.0/contexttrace/demo_data.py +257 -0
  11. contexttrace-0.1.0/contexttrace/endpoint_eval.py +314 -0
  12. contexttrace-0.1.0/contexttrace/errors.py +14 -0
  13. contexttrace-0.1.0/contexttrace/evaluator.py +448 -0
  14. contexttrace-0.1.0/contexttrace/integrations/__init__.py +14 -0
  15. contexttrace-0.1.0/contexttrace/integrations/fastapi.py +311 -0
  16. contexttrace-0.1.0/contexttrace/integrations/langchain.py +440 -0
  17. contexttrace-0.1.0/contexttrace/integrations/langgraph.py +197 -0
  18. contexttrace-0.1.0/contexttrace/integrations/llamaindex.py +422 -0
  19. contexttrace-0.1.0/contexttrace/integrations/opentelemetry.py +111 -0
  20. contexttrace-0.1.0/contexttrace/local.py +325 -0
  21. contexttrace-0.1.0/contexttrace/py.typed +1 -0
  22. contexttrace-0.1.0/contexttrace/regression.py +123 -0
  23. contexttrace-0.1.0/contexttrace/reliability.py +284 -0
  24. contexttrace-0.1.0/contexttrace/report.py +550 -0
  25. contexttrace-0.1.0/contexttrace/storage/__init__.py +3 -0
  26. contexttrace-0.1.0/contexttrace/storage/sqlite_store.py +604 -0
  27. contexttrace-0.1.0/contexttrace/thresholds.py +50 -0
  28. contexttrace-0.1.0/contexttrace/transport.py +183 -0
  29. contexttrace-0.1.0/contexttrace/viewer.py +148 -0
  30. contexttrace-0.1.0/contexttrace.egg-info/SOURCES.txt +30 -0
  31. contexttrace-0.1.0/pyproject.toml +99 -0
  32. contexttrace-0.1.0/setup.cfg +4 -0
  33. contexttrace-0.1.0/setup.py +4 -0
@@ -0,0 +1,18 @@
1
+ include README.md
2
+ include pyproject.toml
3
+ include setup.py
4
+ include contexttrace/py.typed
5
+ recursive-include contexttrace *.py
6
+ prune build
7
+ prune dist
8
+ prune tests
9
+ prune .contexttrace
10
+ prune .pytest_cache
11
+ prune contexttrace.egg-info
12
+ global-exclude __pycache__/*
13
+ global-exclude *.py[cod]
14
+ global-exclude *.db
15
+ global-exclude *.sqlite
16
+ global-exclude *.sqlite3
17
+ global-exclude *.log
18
+ global-exclude .env
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.1
2
+ Name: contexttrace
3
+ Version: 0.1.0
4
+ Summary: Local-first SDK and CLI for RAG and agent reliability tracing, citation checks, and failure diagnosis.
5
+ Author: ContextTrace contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/samarth1412/Context-Trace
8
+ Project-URL: Documentation, https://github.com/samarth1412/Context-Trace/tree/main/docs
9
+ Project-URL: Repository, https://github.com/samarth1412/Context-Trace
10
+ Project-URL: Issues, https://github.com/samarth1412/Context-Trace/issues
11
+ Project-URL: Changelog, https://github.com/samarth1412/Context-Trace/blob/main/CHANGELOG.md
12
+ Keywords: rag,llm,retrieval-augmented-generation,citations,evaluation,observability,agents,cli,sqlite
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: httpx>=0.27
29
+ Requires-Dist: typing-extensions>=4.9
30
+ Provides-Extra: langchain
31
+ Requires-Dist: langchain-core>=0.2; extra == "langchain"
32
+ Provides-Extra: llamaindex
33
+ Requires-Dist: llama-index-core>=0.10; extra == "llamaindex"
34
+ Provides-Extra: local
35
+ Provides-Extra: fastapi
36
+ Requires-Dist: fastapi>=0.110; extra == "fastapi"
37
+ Provides-Extra: langgraph
38
+ Requires-Dist: langgraph>=0.2; extra == "langgraph"
39
+ Provides-Extra: otel
40
+ Requires-Dist: opentelemetry-api>=1.24; extra == "otel"
41
+ Provides-Extra: opentelemetry
42
+ Requires-Dist: opentelemetry-api>=1.24; extra == "opentelemetry"
43
+ Provides-Extra: integrations
44
+ Requires-Dist: fastapi>=0.110; extra == "integrations"
45
+ Requires-Dist: langchain-core>=0.2; extra == "integrations"
46
+ Requires-Dist: langgraph>=0.2; extra == "integrations"
47
+ Requires-Dist: llama-index-core>=0.10; extra == "integrations"
48
+ Requires-Dist: opentelemetry-api>=1.24; extra == "integrations"
49
+ Provides-Extra: all
50
+ Requires-Dist: fastapi>=0.110; extra == "all"
51
+ Requires-Dist: langchain-core>=0.2; extra == "all"
52
+ Requires-Dist: langgraph>=0.2; extra == "all"
53
+ Requires-Dist: llama-index-core>=0.10; extra == "all"
54
+ Requires-Dist: opentelemetry-api>=1.24; extra == "all"
55
+ Provides-Extra: test
56
+ Requires-Dist: pytest>=8.0; extra == "test"
57
+
58
+ # ContextTrace
59
+
60
+ **Debug RAG failures before users find them.**
61
+
62
+ ContextTrace is a local-first Python SDK and CLI for evaluating existing RAG and AI agent systems. It records retrieved chunks, selected context, answer claims, citations, token usage, latency, and agent events, then writes local traces and HTML reports without requiring a hosted dashboard.
63
+
64
+ ## Install
65
+
66
+ ```bash
67
+ pip install contexttrace
68
+ contexttrace --version
69
+ contexttrace init
70
+ ```
71
+
72
+ Optional integrations:
73
+
74
+ ```bash
75
+ pip install "contexttrace[langchain]"
76
+ pip install "contexttrace[llamaindex]"
77
+ pip install "contexttrace[fastapi]"
78
+ pip install "contexttrace[langgraph]"
79
+ pip install "contexttrace[otel]"
80
+ pip install "contexttrace[all]"
81
+ ```
82
+
83
+ ## Quickstart
84
+
85
+ ```bash
86
+ contexttrace init
87
+ contexttrace demo --dataset refund_policy
88
+ contexttrace report --last
89
+ contexttrace doctor
90
+ ```
91
+
92
+ By default, traces are stored locally in:
93
+
94
+ ```text
95
+ .contexttrace/contexttrace.db
96
+ ```
97
+
98
+ ## SDK Example
99
+
100
+ ```python
101
+ from contexttrace import ContextTrace
102
+
103
+ ct = ContextTrace(project="support-rag")
104
+
105
+ with ct.trace(query="What is the refund policy?") as trace:
106
+ chunks = retriever.search("What is the refund policy?")
107
+ trace.log_retrieval(chunks)
108
+ trace.log_context(chunks[:5])
109
+
110
+ answer = llm.generate("What is the refund policy?", chunks[:5])
111
+ trace.log_answer(answer, usage={"total_tokens": 1200})
112
+ trace.log_citations([
113
+ {"claim": "Refunds are available within 30 days.", "source_chunk_id": "chunk_12"}
114
+ ])
115
+
116
+ result = trace.evaluate()
117
+ print(result["failure"]["failure_type"])
118
+ ```
119
+
120
+ ## BYO RAG Endpoint
121
+
122
+ Evaluate a running local or hosted RAG API without adding SDK code:
123
+
124
+ ```bash
125
+ contexttrace eval \
126
+ --dataset evals/questions.json \
127
+ --endpoint http://localhost:8000/query \
128
+ --method POST \
129
+ --input-key question \
130
+ --answer-path $.answer \
131
+ --contexts-path $.contexts \
132
+ --citations-path $.citations \
133
+ --fail-on "failure_rate>0.25"
134
+ ```
135
+
136
+ ## What It Catches
137
+
138
+ - `retrieval_miss`
139
+ - `citation_mismatch`
140
+ - `unsupported_answer`
141
+ - `contradicted_answer`
142
+ - `conflicting_sources`
143
+ - `should_have_abstained`
144
+ - agent failures such as `stale_memory_used` and `tool_error`
145
+
146
+ ## Privacy
147
+
148
+ Local mode is the default. ContextTrace makes no network calls unless you configure an LLM judge provider or evaluate a RAG endpoint you provide.
149
+
150
+ ## Links
151
+
152
+ - Repository: https://github.com/samarth1412/Context-Trace
153
+ - Documentation: https://github.com/samarth1412/Context-Trace/tree/main/docs
154
+ - Issues: https://github.com/samarth1412/Context-Trace/issues
@@ -0,0 +1,97 @@
1
+ # ContextTrace
2
+
3
+ **Debug RAG failures before users find them.**
4
+
5
+ ContextTrace is a local-first Python SDK and CLI for evaluating existing RAG and AI agent systems. It records retrieved chunks, selected context, answer claims, citations, token usage, latency, and agent events, then writes local traces and HTML reports without requiring a hosted dashboard.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install contexttrace
11
+ contexttrace --version
12
+ contexttrace init
13
+ ```
14
+
15
+ Optional integrations:
16
+
17
+ ```bash
18
+ pip install "contexttrace[langchain]"
19
+ pip install "contexttrace[llamaindex]"
20
+ pip install "contexttrace[fastapi]"
21
+ pip install "contexttrace[langgraph]"
22
+ pip install "contexttrace[otel]"
23
+ pip install "contexttrace[all]"
24
+ ```
25
+
26
+ ## Quickstart
27
+
28
+ ```bash
29
+ contexttrace init
30
+ contexttrace demo --dataset refund_policy
31
+ contexttrace report --last
32
+ contexttrace doctor
33
+ ```
34
+
35
+ By default, traces are stored locally in:
36
+
37
+ ```text
38
+ .contexttrace/contexttrace.db
39
+ ```
40
+
41
+ ## SDK Example
42
+
43
+ ```python
44
+ from contexttrace import ContextTrace
45
+
46
+ ct = ContextTrace(project="support-rag")
47
+
48
+ with ct.trace(query="What is the refund policy?") as trace:
49
+ chunks = retriever.search("What is the refund policy?")
50
+ trace.log_retrieval(chunks)
51
+ trace.log_context(chunks[:5])
52
+
53
+ answer = llm.generate("What is the refund policy?", chunks[:5])
54
+ trace.log_answer(answer, usage={"total_tokens": 1200})
55
+ trace.log_citations([
56
+ {"claim": "Refunds are available within 30 days.", "source_chunk_id": "chunk_12"}
57
+ ])
58
+
59
+ result = trace.evaluate()
60
+ print(result["failure"]["failure_type"])
61
+ ```
62
+
63
+ ## BYO RAG Endpoint
64
+
65
+ Evaluate a running local or hosted RAG API without adding SDK code:
66
+
67
+ ```bash
68
+ contexttrace eval \
69
+ --dataset evals/questions.json \
70
+ --endpoint http://localhost:8000/query \
71
+ --method POST \
72
+ --input-key question \
73
+ --answer-path $.answer \
74
+ --contexts-path $.contexts \
75
+ --citations-path $.citations \
76
+ --fail-on "failure_rate>0.25"
77
+ ```
78
+
79
+ ## What It Catches
80
+
81
+ - `retrieval_miss`
82
+ - `citation_mismatch`
83
+ - `unsupported_answer`
84
+ - `contradicted_answer`
85
+ - `conflicting_sources`
86
+ - `should_have_abstained`
87
+ - agent failures such as `stale_memory_used` and `tool_error`
88
+
89
+ ## Privacy
90
+
91
+ Local mode is the default. ContextTrace makes no network calls unless you configure an LLM judge provider or evaluate a RAG endpoint you provide.
92
+
93
+ ## Links
94
+
95
+ - Repository: https://github.com/samarth1412/Context-Trace
96
+ - Documentation: https://github.com/samarth1412/Context-Trace/tree/main/docs
97
+ - Issues: https://github.com/samarth1412/Context-Trace/issues
@@ -0,0 +1,36 @@
1
+ from contexttrace._version import __version__
2
+ from contexttrace.client import AsyncContextTrace, ContextTrace
3
+ from contexttrace.config import ContextTraceConfig
4
+ from contexttrace.errors import (
5
+ ContextTraceConfigError,
6
+ ContextTraceError,
7
+ ContextTraceHTTPError,
8
+ ContextTraceLocalError,
9
+ )
10
+ from contexttrace.integrations.fastapi import ContextTraceFastAPIMiddleware
11
+ from contexttrace.integrations.langchain import ContextTraceCallbackHandler
12
+ from contexttrace.integrations.langgraph import ContextTraceLangGraphTracer
13
+ from contexttrace.integrations.llamaindex import ContextTraceLlamaIndexCallbackHandler
14
+ from contexttrace.integrations.opentelemetry import OpenTelemetryExporter, export_contexttrace_trace
15
+ from contexttrace.reliability import ReliabilityScore, ReliabilityScorer
16
+ from contexttrace.report import ReportGenerator
17
+
18
+ __all__ = [
19
+ "AsyncContextTrace",
20
+ "ContextTrace",
21
+ "ContextTraceConfig",
22
+ "ContextTraceConfigError",
23
+ "ContextTraceCallbackHandler",
24
+ "ContextTraceError",
25
+ "ContextTraceFastAPIMiddleware",
26
+ "ContextTraceHTTPError",
27
+ "ContextTraceLocalError",
28
+ "ContextTraceLangGraphTracer",
29
+ "ContextTraceLlamaIndexCallbackHandler",
30
+ "OpenTelemetryExporter",
31
+ "ReliabilityScore",
32
+ "ReliabilityScorer",
33
+ "ReportGenerator",
34
+ "export_contexttrace_trace",
35
+ "__version__",
36
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"