langchain-longprobe 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.
@@ -0,0 +1,221 @@
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
219
+
220
+ # LongProbe local storage
221
+ .longprobe/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 EnDevSols
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,388 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-longprobe
3
+ Version: 0.1.0
4
+ Summary: LangChain integration for LongProbe — sub-second RAG retrieval regression testing with chunk-level diffing
5
+ Project-URL: Homepage, https://endevsols.com/open-source/longprobe
6
+ Project-URL: Documentation, https://github.com/ENDEVSOLS/langchain-longprobe#readme
7
+ Project-URL: Repository, https://github.com/ENDEVSOLS/langchain-longprobe
8
+ Project-URL: Issues, https://github.com/ENDEVSOLS/langchain-longprobe/issues
9
+ Project-URL: LongProbe Core, https://github.com/ENDEVSOLS/LongProbe
10
+ Project-URL: Source Code, https://github.com/ENDEVSOLS/langchain-longprobe
11
+ Author-email: EnDevSols <opensource@endevsols.com>
12
+ Maintainer-email: EnDevSols <opensource@endevsols.com>
13
+ License: MIT
14
+ License-File: LICENSE
15
+ Keywords: evaluation,langchain,llm,longprobe,rag,regression,retrieval,testing,vector-store
16
+ Classifier: Development Status :: 4 - Beta
17
+ Classifier: Framework :: Pytest
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
27
+ Classifier: Topic :: Software Development :: Quality Assurance
28
+ Classifier: Topic :: Software Development :: Testing
29
+ Requires-Python: >=3.10
30
+ Requires-Dist: langchain-core>=0.2.0
31
+ Requires-Dist: longprobe>=0.1.0
32
+ Provides-Extra: all
33
+ Requires-Dist: langchain>=0.2.0; extra == 'all'
34
+ Requires-Dist: langsmith>=0.1.0; extra == 'all'
35
+ Provides-Extra: dev
36
+ Requires-Dist: langchain>=0.2.0; extra == 'dev'
37
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
38
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
40
+ Provides-Extra: langchain
41
+ Requires-Dist: langchain>=0.2.0; extra == 'langchain'
42
+ Provides-Extra: langsmith
43
+ Requires-Dist: langsmith>=0.1.0; extra == 'langsmith'
44
+ Description-Content-Type: text/markdown
45
+
46
+ <div align="center">
47
+
48
+ # 🔬 langchain-longprobe
49
+
50
+ **Sub-second RAG retrieval regression testing for LangChain**
51
+
52
+ [![PyPI version](https://badge.fury.io/py/langchain-longprobe.svg)](https://badge.fury.io/py/langchain-longprobe)
53
+ [![Python Versions](https://img.shields.io/pypi/pyversions/langchain-longprobe.svg)](https://pypi.org/project/langchain-longprobe/)
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55
+ [![LongProbe Core](https://img.shields.io/badge/Powered%20by-LongProbe-blue)](https://github.com/ENDEVSOLS/LongProbe)
56
+
57
+ *The first retrieval regression testing integration for LangChain.*
58
+ *Not another evaluation framework — a test runner that catches lost chunks in milliseconds.*
59
+
60
+ [Quick Start](#quick-start) • [API Reference](#api-reference) • [Pytest Integration](#pytest-integration) • [Examples](#examples)
61
+
62
+ </div>
63
+
64
+ ---
65
+
66
+ ## Why langchain-longprobe?
67
+
68
+ Every RAG developer faces the same problem: you upgrade LangChain, swap a vector store, or tweak a chunking strategy — and your retrieval **silently degrades**. Existing evaluation tools (Ragas, DeepEval) tell you the LLM answer got worse, but they can't tell you *which specific chunks were lost*.
69
+
70
+ **langchain-longprobe** bridges this gap:
71
+
72
+ | Feature | LangChain Evaluators / Ragas | langchain-longprobe |
73
+ | :--- | :--- | :--- |
74
+ | **Focus** | LLM response quality | Retrieval stability |
75
+ | **Speed** | 10s–60s (LLM-as-judge) | **Sub-second** (chunk match) |
76
+ | **Feedback** | Pass/Fail score | **Visual diff** of lost/gained chunks |
77
+ | **Workflow** | Batch analysis | `pytest` / CI integration |
78
+ | **Detects** | Bad answers | **Why** retrieval failed |
79
+
80
+ ## Installation
81
+
82
+ ```bash
83
+ pip install langchain-longprobe
84
+ ```
85
+
86
+ This installs both `langchain-longprobe` and the core [`longprobe`](https://pypi.org/project/longprobe/) library.
87
+
88
+ ## Quick Start
89
+
90
+ ### 1. Define Golden Questions
91
+
92
+ Create a `goldens.yaml` with your expected retrieval results:
93
+
94
+ ```yaml
95
+ name: "my-rag-golden-set"
96
+ version: "1.0"
97
+
98
+ questions:
99
+ - id: "q1"
100
+ question: "What is the refund policy?"
101
+ match_mode: "id"
102
+ required_chunks:
103
+ - "chunk_refund_01"
104
+ - "chunk_refund_02"
105
+ top_k: 5
106
+
107
+ - id: "q2"
108
+ question: "What are the payment terms?"
109
+ match_mode: "text"
110
+ required_chunks:
111
+ - "net 30 days from invoice"
112
+ top_k: 5
113
+ ```
114
+
115
+ ### 2. Probe Your Retriever
116
+
117
+ ```python
118
+ from langchain_longprobe import RetrievalProbe
119
+ from langchain_community.vectorstores import Chroma
120
+
121
+ # Your existing LangChain setup
122
+ vectorstore = Chroma(persist_directory="./db")
123
+ retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
124
+
125
+ # Create a probe
126
+ probe = RetrievalProbe.from_retriever(
127
+ retriever=retriever,
128
+ goldens_path="goldens.yaml",
129
+ )
130
+
131
+ # Run regression check (sub-second)
132
+ report = probe.run()
133
+ print(f"Recall: {report.overall_recall:.2%}")
134
+ print(f"Pass Rate: {report.pass_rate:.2%}")
135
+
136
+ # See exactly what's missing
137
+ for qid, chunks in probe.get_missing_chunks().items():
138
+ print(f" {qid}: lost {chunks}")
139
+ ```
140
+
141
+ ### 3. Track Regressions Over Time
142
+
143
+ ```python
144
+ # Save a baseline after your first successful run
145
+ probe.run()
146
+ probe.save_baseline("v1.0")
147
+
148
+ # After code changes, compare against baseline
149
+ probe.run()
150
+ diff = probe.diff("v1.0")
151
+ print(f"Regressions: {len(diff['regressions'])}")
152
+ print(f"Improvements: {len(diff['improvements'])}")
153
+ ```
154
+
155
+ ## API Reference
156
+
157
+ ### `RetrievalProbe` — Main Entry Point
158
+
159
+ The recommended way to use langchain-longprobe. Wraps any LangChain `BaseRetriever`.
160
+
161
+ ```python
162
+ from langchain_longprobe import RetrievalProbe
163
+
164
+ probe = RetrievalProbe.from_retriever(
165
+ retriever=your_retriever,
166
+ goldens_path="goldens.yaml",
167
+ recall_threshold=0.85,
168
+ )
169
+
170
+ report = probe.run()
171
+ probe.save_baseline("v1.0")
172
+ diff = probe.diff("v1.0")
173
+ missing = probe.get_missing_chunks()
174
+ ```
175
+
176
+ ### `ProbedRetriever` — Drop-in Retriever Wrapper
177
+
178
+ A LangChain `BaseRetriever` that wraps your retriever and adds regression testing.
179
+ Use as a **drop-in replacement** in your existing chains.
180
+
181
+ ```python
182
+ from langchain_longprobe import ProbedRetriever
183
+
184
+ probed = ProbedRetriever(
185
+ retriever=your_retriever,
186
+ goldens_path="goldens.yaml",
187
+ check_on_invoke=False, # set True for automatic checks
188
+ )
189
+
190
+ # Use exactly like a normal retriever
191
+ docs = probed.invoke("What is the refund policy?")
192
+
193
+ # Manually trigger a regression check
194
+ report = probed.check()
195
+ probed.save_baseline("v1.0")
196
+ ```
197
+
198
+ ### `LongProbeCallbackHandler` — Passive Monitoring
199
+
200
+ Attach to any LangChain chain to passively record retrieval events.
201
+
202
+ ```python
203
+ from langchain_longprobe import LongProbeCallbackHandler
204
+
205
+ handler = LongProbeCallbackHandler(
206
+ goldens_path="goldens.yaml",
207
+ recall_threshold=0.85,
208
+ fail_on_regression=True,
209
+ )
210
+
211
+ # Attach to retriever calls
212
+ docs = retriever.invoke("query", config={"callbacks": [handler]})
213
+
214
+ # Inspect results
215
+ print(handler.retrieval_log)
216
+
217
+ # Run a full check
218
+ report = handler.run_probe(retriever)
219
+ ```
220
+
221
+ ### `RetrievalRegressionRunnable` — LCEL Integration
222
+
223
+ Use LongProbe as a composable step in LangChain Expression Language chains.
224
+
225
+ ```python
226
+ from langchain_longprobe import RetrievalRegressionRunnable
227
+
228
+ runnable = RetrievalRegressionRunnable(
229
+ retriever=your_retriever,
230
+ goldens_path="goldens.yaml",
231
+ fail_on_regression=True,
232
+ )
233
+
234
+ # Invoke with options
235
+ result = runnable.invoke({
236
+ "top_k": 10,
237
+ "save_baseline": "v2.0",
238
+ "baseline_label": "v1.0", # compare against this
239
+ })
240
+
241
+ print(result["overall_recall"])
242
+ print(result["missing_chunks"])
243
+ ```
244
+
245
+ ## Pytest Integration
246
+
247
+ ### conftest.py
248
+
249
+ ```python
250
+ import pytest
251
+ from langchain_longprobe import RetrievalProbe
252
+
253
+ @pytest.fixture
254
+ def probe(my_retriever):
255
+ return RetrievalProbe.from_retriever(
256
+ retriever=my_retriever,
257
+ goldens_path="goldens.yaml",
258
+ recall_threshold=0.85,
259
+ )
260
+ ```
261
+
262
+ ### Writing Tests
263
+
264
+ ```python
265
+ def test_retrieval_recall(probe):
266
+ """Ensure retrieval recall stays above threshold."""
267
+ report = probe.run()
268
+ assert report.overall_recall >= 0.85, (
269
+ f"Recall dropped to {report.overall_recall:.2f}. "
270
+ f"Missing: {probe.get_missing_chunks()}"
271
+ )
272
+
273
+ def test_no_regression(probe):
274
+ """Ensure no chunks were lost vs. baseline."""
275
+ probe.assert_no_regression("v1.0")
276
+ ```
277
+
278
+ ### Command Line
279
+
280
+ ```bash
281
+ pytest --langchain-longprobe-goldens goldens.yaml --langchain-longprobe-threshold 0.85
282
+ ```
283
+
284
+ ## GitHub Actions
285
+
286
+ ```yaml
287
+ name: RAG Regression Check
288
+
289
+ on: [push, pull_request]
290
+
291
+ jobs:
292
+ rag-probe:
293
+ runs-on: ubuntu-latest
294
+ steps:
295
+ - uses: actions/checkout@v4
296
+ - uses: actions/setup-python@v5
297
+ with:
298
+ python-version: "3.12"
299
+ - run: pip install langchain-longprobe
300
+ - name: Run regression check
301
+ run: pytest tests/test_rag_regression.py -v
302
+ env:
303
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
304
+ ```
305
+
306
+ ## Examples
307
+
308
+ ### Basic Regression Check
309
+
310
+ ```python
311
+ from langchain_longprobe import RetrievalProbe
312
+ from langchain_openai import OpenAIEmbeddings
313
+ from langchain_community.vectorstores import Chroma
314
+
315
+ embeddings = OpenAIEmbeddings()
316
+ vectorstore = Chroma(
317
+ persist_directory="./chroma_db",
318
+ embedding_function=embeddings,
319
+ )
320
+ retriever = vectorstore.as_retriever()
321
+
322
+ probe = RetrievalProbe.from_retriever(retriever, goldens_path="goldens.yaml")
323
+ report = probe.run()
324
+
325
+ if report.regression_detected:
326
+ print("⚠️ Regression detected!")
327
+ for qid, chunks in probe.get_missing_chunks().items():
328
+ print(f" Question {qid}: lost chunks {chunks}")
329
+ else:
330
+ print("✅ All chunks present")
331
+ ```
332
+
333
+ ### CI/CD Pipeline Integration
334
+
335
+ ```python
336
+ # tests/test_rag_regression.py
337
+ import pytest
338
+ from langchain_longprobe import RetrievalProbe
339
+
340
+ @pytest.fixture(scope="session")
341
+ def probe():
342
+ from langchain_community.vectorstores import Chroma
343
+ retriever = Chroma(persist_directory="./db").as_retriever()
344
+ return RetrievalProbe.from_retriever(
345
+ retriever=retriever,
346
+ goldens_path="goldens.yaml",
347
+ recall_threshold=0.85,
348
+ )
349
+
350
+ def test_recall_above_threshold(probe):
351
+ report = probe.run()
352
+ assert report.overall_recall >= 0.85
353
+
354
+ def test_no_regressions_vs_baseline(probe):
355
+ probe.assert_no_regression("production")
356
+
357
+ def test_critical_questions_pass(probe):
358
+ report = probe.run()
359
+ for result in report.results:
360
+ if "critical" in result.question_id:
361
+ assert result.passed, f"Critical question {result.question_id} failed"
362
+ ```
363
+
364
+ ## Part of the Long Suite
365
+
366
+ langchain-longprobe is the official LangChain integration for [LongProbe](https://github.com/ENDEVSOLS/LongProbe), part of the [EnDevSols Long Suite](https://endevsols.com/open-source) of RAG tools:
367
+
368
+ - **[LongParser](https://github.com/ENDEVSOLS/LongParser)** — Document ingestion and chunking
369
+ - **[LongTrainer](https://github.com/ENDEVSOLS/Long-Trainer)** — RAG chatbot framework
370
+ - **[LongTracer](https://github.com/ENDEVSOLS/LongTracer)** — Hallucination detection
371
+ - **[LongProbe](https://github.com/ENDEVSOLS/LongProbe)** — Retrieval regression testing (core library)
372
+ - **[langchain-longprobe](https://github.com/ENDEVSOLS/langchain-longprobe)** — LangChain integration ← You are here
373
+
374
+ ## Contributing
375
+
376
+ We welcome contributions! Please see the [LongProbe Contributing Guide](https://github.com/ENDEVSOLS/LongProbe/blob/main/CONTRIBUTING.md) for guidelines.
377
+
378
+ ## License
379
+
380
+ MIT License — see [LICENSE](LICENSE) for details.
381
+
382
+ ---
383
+
384
+ <div align="center">
385
+
386
+ **Developed by [EnDevSols](https://endevsols.com)** • [GitHub](https://github.com/ENDEVSOLS) • [LongProbe Core](https://github.com/ENDEVSOLS/LongProbe)
387
+
388
+ </div>