vestigia 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.
- vestigia-0.1.0/LICENSE +201 -0
- vestigia-0.1.0/PKG-INFO +379 -0
- vestigia-0.1.0/README.md +348 -0
- vestigia-0.1.0/pyproject.toml +49 -0
- vestigia-0.1.0/pyproject.toml.orig +55 -0
- vestigia-0.1.0/src/vestigia/__init__.py +11 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/__init__.py +75 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/classifier.py +71 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/langchain/__init__.py +44 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/langchain/chat_model_classifier.py +167 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/langchain/system_one_classifier.py +163 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/models.py +216 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/prompts/chat_model_prompt.md +53 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/prompts/system_one_model_prompt.yaml +80 -0
- vestigia-0.1.0/src/vestigia/chunk_classification/prompts.py +66 -0
vestigia-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
vestigia-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vestigia
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Evidence attribution for LLM-generated answers using retrieved text chunks.
|
|
5
|
+
Keywords: llm,rag,evidence,attribution,langchain
|
|
6
|
+
Author: Lorenzo Gardini
|
|
7
|
+
Author-email: Lorenzo Gardini <l.gardo98@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Dist: pydantic>=2.14.1
|
|
17
|
+
Requires-Dist: vestigia[typesafe,openai,anthropic] ; extra == 'all'
|
|
18
|
+
Requires-Dist: langchain-anthropic>=1.7.7 ; extra == 'anthropic'
|
|
19
|
+
Requires-Dist: langchain-openai>=1.7.3 ; extra == 'openai'
|
|
20
|
+
Requires-Dist: langchain-typesafe>=0.0.1a3 ; extra == 'typesafe'
|
|
21
|
+
Requires-Dist: pyyaml>=6.0 ; extra == 'typesafe'
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Project-URL: Homepage, https://github.com/Lorenzo-Gardini/vestigia
|
|
24
|
+
Project-URL: Repository, https://github.com/Lorenzo-Gardini/vestigia
|
|
25
|
+
Project-URL: Issues, https://github.com/Lorenzo-Gardini/vestigia/issues
|
|
26
|
+
Provides-Extra: all
|
|
27
|
+
Provides-Extra: anthropic
|
|
28
|
+
Provides-Extra: openai
|
|
29
|
+
Provides-Extra: typesafe
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
<div align="center">
|
|
33
|
+
|
|
34
|
+
<img src="https://raw.githubusercontent.com/Lorenzo-Gardini/vestigia/main/assets/vestigia-banner.svg" alt="Vestigia - Trace answers back to evidence. An illustrated magnifying glass connects source passages to an answer." width="100%">
|
|
35
|
+
|
|
36
|
+
Classify how retrieved text supports, partially supports, contradicts, or does
|
|
37
|
+
not contribute to an answer.
|
|
38
|
+
|
|
39
|
+
<p>
|
|
40
|
+
<a href="https://github.com/Lorenzo-Gardini/vestigia/actions/workflows/tests.yml">
|
|
41
|
+
<img src="https://github.com/Lorenzo-Gardini/vestigia/actions/workflows/tests.yml/badge.svg?branch=main" alt="Tests">
|
|
42
|
+
</a>
|
|
43
|
+
<a href="https://pypi.org/project/vestigia/">
|
|
44
|
+
<img src="https://img.shields.io/pypi/v/vestigia" alt="PyPI version">
|
|
45
|
+
</a>
|
|
46
|
+
<img src="https://img.shields.io/badge/python-3.12%2B-blue" alt="Python 3.12 or newer">
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<p>
|
|
50
|
+
<a href="#features">Features</a> ·
|
|
51
|
+
<a href="#quick-start">Quick start</a> ·
|
|
52
|
+
<a href="#classification-statuses">Statuses</a> ·
|
|
53
|
+
<a href="#development">Development</a> ·
|
|
54
|
+
<a href="#releasing-to-pypi">Releases</a>
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Two classification approaches:** structured chat-model output and a
|
|
62
|
+
TypeSafe system-one classifier.
|
|
63
|
+
- **Traceable results:** each result retains the original chunk and its stable
|
|
64
|
+
identifier.
|
|
65
|
+
- **Typed data:** Pydantic models with frozen attributes validate inputs and outputs.
|
|
66
|
+
- **Packaged prompts:** Markdown and YAML prompt templates are available through
|
|
67
|
+
Python APIs.
|
|
68
|
+
- **Optional integrations:** install only the provider dependencies you need.
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
Requires Python 3.12 or newer. Install the OpenAI integration with your package
|
|
73
|
+
manager:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# pip (inside your virtual environment)
|
|
77
|
+
python -m pip install "vestigia[openai]"
|
|
78
|
+
|
|
79
|
+
# uv (in a uv-managed project)
|
|
80
|
+
uv add "vestigia[openai]"
|
|
81
|
+
|
|
82
|
+
# Poetry (in a Poetry-managed project)
|
|
83
|
+
poetry add "vestigia[openai]"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Set `OPENAI_API_KEY` in your environment. Save the following example as
|
|
87
|
+
`classify.py` and run it with `python classify.py` (or `uv run classify.py`,
|
|
88
|
+
`poetry run python classify.py`).
|
|
89
|
+
This example sends data to the configured provider and may incur API charges.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import asyncio
|
|
93
|
+
|
|
94
|
+
from langchain_openai import ChatOpenAI
|
|
95
|
+
|
|
96
|
+
from vestigia.chunk_classification import Chunk
|
|
97
|
+
from vestigia.chunk_classification.langchain import ChatModelChunkClassifier
|
|
98
|
+
|
|
99
|
+
classifier = ChatModelChunkClassifier(
|
|
100
|
+
ChatOpenAI(model="gpt-4o-mini"),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
async def classify_answer():
|
|
105
|
+
result = await classifier.classify(
|
|
106
|
+
query="What is the repayment term?",
|
|
107
|
+
answer="The plan lasts 60 months.",
|
|
108
|
+
chunks=[
|
|
109
|
+
Chunk(
|
|
110
|
+
id="repayment-term",
|
|
111
|
+
text="The repayment plan lasts 60 months.",
|
|
112
|
+
),
|
|
113
|
+
Chunk(
|
|
114
|
+
id="early-repayment",
|
|
115
|
+
text="Early repayment has no additional fee.",
|
|
116
|
+
),
|
|
117
|
+
],
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
for item in result.classifications:
|
|
121
|
+
print(item.chunk.id, item.status.value, item.explanation)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
asyncio.run(classify_answer())
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`ChatModelChunkClassifier` accepts any LangChain `BaseChatModel` that supports
|
|
129
|
+
structured output; the OpenAI integration above is one option.
|
|
130
|
+
|
|
131
|
+
### Use a TypeSafe system-one model
|
|
132
|
+
|
|
133
|
+
Install the extra with `python -m pip install "vestigia[typesafe]"`
|
|
134
|
+
(`uv add` or `poetry add` work the same way) and set `TYPESAFE_API_KEY`.
|
|
135
|
+
Save this example as `classify.py` and run it with
|
|
136
|
+
`python classify.py`:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
import asyncio
|
|
140
|
+
|
|
141
|
+
from langchain_typesafe import TypeSafeClassifier
|
|
142
|
+
|
|
143
|
+
from vestigia.chunk_classification import Chunk
|
|
144
|
+
from vestigia.chunk_classification.langchain import SystemOneModelChunkClassifier
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
async def classify_answer():
|
|
148
|
+
classifier = SystemOneModelChunkClassifier(TypeSafeClassifier())
|
|
149
|
+
result = await classifier.classify(
|
|
150
|
+
query="What is the repayment term?",
|
|
151
|
+
answer="The plan lasts 60 months.",
|
|
152
|
+
chunks=[Chunk(id="source-1", text="The plan lasts 60 months.")],
|
|
153
|
+
)
|
|
154
|
+
for item in result.classifications:
|
|
155
|
+
print(item.chunk.id, item.status.value, item.probabilities, item.confidence)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if __name__ == "__main__":
|
|
159
|
+
asyncio.run(classify_answer())
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Like the chat-model example, this makes a real provider request. System-one
|
|
163
|
+
results include per-status probabilities and confidence.
|
|
164
|
+
|
|
165
|
+
### Use the data models directly
|
|
166
|
+
|
|
167
|
+
The package exports its domain models from `vestigia.chunk_classification`:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from vestigia.chunk_classification import (
|
|
171
|
+
ChatModelChunkClassification,
|
|
172
|
+
ChatModelChunksClassificationResult,
|
|
173
|
+
Chunk,
|
|
174
|
+
ChunkStatus,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
chunk = Chunk(id="source-1", text="The plan lasts 60 months.")
|
|
178
|
+
result = ChatModelChunksClassificationResult(
|
|
179
|
+
classifications=(
|
|
180
|
+
ChatModelChunkClassification(
|
|
181
|
+
chunk=chunk,
|
|
182
|
+
status=ChunkStatus.USED,
|
|
183
|
+
explanation="The answer states the same repayment term.",
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Classification statuses
|
|
190
|
+
|
|
191
|
+
| Status | Meaning |
|
|
192
|
+
| --- | --- |
|
|
193
|
+
| `used` | The answer states or faithfully paraphrases meaningful information from the chunk. |
|
|
194
|
+
| `partially_used` | The answer uses meaningful information but omits or incompletely represents other significant details. |
|
|
195
|
+
| `contradicted` | The answer makes a claim incompatible with information in the chunk. |
|
|
196
|
+
| `not_used` | No meaningful information from the chunk appears in the answer, and it is not contradicted. |
|
|
197
|
+
| `uncertain` | The available text does not support a reliable classification. |
|
|
198
|
+
|
|
199
|
+
Omission alone is not a contradiction. Both packaged prompts instruct the model
|
|
200
|
+
to assess each chunk against the answer and avoid relying on external knowledge.
|
|
201
|
+
The labels describe observable overlap and conflict, not proof of the generating
|
|
202
|
+
model's internal reasoning or actual use of a retrieved chunk.
|
|
203
|
+
|
|
204
|
+
## Classifiers and prompts
|
|
205
|
+
|
|
206
|
+
| API | Purpose | Optional dependency |
|
|
207
|
+
| --- | --- | --- |
|
|
208
|
+
| `ChatModelChunkClassifier` | Classify chunks using a LangChain chat model with structured output. | `openai`, `anthropic`, or another installed LangChain chat integration |
|
|
209
|
+
| `SystemOneModelChunkClassifier` | Classify chunks using a TypeSafe system-one model and per-status criteria. | `typesafe` |
|
|
210
|
+
|
|
211
|
+
The adapters are exported from `vestigia.chunk_classification.langchain`.
|
|
212
|
+
`ChunkClassifier` is exported from `vestigia.chunk_classification.classifier`.
|
|
213
|
+
|
|
214
|
+
Load the packaged prompt templates directly when needed:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from vestigia.chunk_classification.prompts import (
|
|
218
|
+
load_chat_model_prompt,
|
|
219
|
+
load_system_one_prompt,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
chat_prompt_text = load_chat_model_prompt()
|
|
223
|
+
system_one_template = load_system_one_prompt()
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`load_system_one_prompt()` requires the `typesafe` extra, which includes
|
|
227
|
+
PyYAML.
|
|
228
|
+
|
|
229
|
+
### Custom prompts
|
|
230
|
+
|
|
231
|
+
Pass a `langchain_core.prompts.PromptTemplate` as `prompt=` to the chat
|
|
232
|
+
classifier. Its available variables are `query`, `answer`, and `chunks`; the
|
|
233
|
+
last contains XML-escaped source text and identifiers. The model returns only
|
|
234
|
+
each chunk's `chunk_id`, `status`, and optional `explanation`; results reference
|
|
235
|
+
the original `Chunk` objects.
|
|
236
|
+
|
|
237
|
+
For the system-one classifier, pass a `SystemOneModelTemplate`:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from vestigia.chunk_classification import ChunkStatus, SystemOneModelTemplate
|
|
241
|
+
|
|
242
|
+
template = SystemOneModelTemplate(
|
|
243
|
+
state="Question: {query}\nAnswer: {answer}",
|
|
244
|
+
instruction="Evaluate the following evidence: {chunk}",
|
|
245
|
+
criteria={
|
|
246
|
+
ChunkStatus.USED: "Meaningful information appears in the answer.",
|
|
247
|
+
ChunkStatus.NOT_USED: "No meaningful information appears in the answer.",
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
The state template receives `query` and `answer`; the instruction template
|
|
253
|
+
receives each chunk's text as `chunk`. Criteria require at least two statuses.
|
|
254
|
+
|
|
255
|
+
## Input and output contracts
|
|
256
|
+
|
|
257
|
+
- Chunk IDs must be unique within each call. Duplicates raise `ValueError`
|
|
258
|
+
before a provider is invoked.
|
|
259
|
+
- An empty chunk sequence returns `classifications=()` without a provider call.
|
|
260
|
+
- Results follow input order and contain the original `Chunk` objects. Missing,
|
|
261
|
+
extra, or duplicate response IDs raise `ValueError`.
|
|
262
|
+
- System-one answers must be choice answers whose labels belong to the prompt's
|
|
263
|
+
criteria. Confidence and probability values must be finite and in `[0, 1]`.
|
|
264
|
+
The package does not normalize the distribution or require an exact sum of 1.
|
|
265
|
+
- Backend, prompt-formatting, and Pydantic validation errors propagate to the
|
|
266
|
+
caller; the package does not substitute partial or empty success responses.
|
|
267
|
+
- Model attributes are frozen and extra fields are rejected. Freezing is
|
|
268
|
+
shallow: nested dictionaries remain mutable, and normal Pydantic type
|
|
269
|
+
coercion applies.
|
|
270
|
+
|
|
271
|
+
## Installation options
|
|
272
|
+
|
|
273
|
+
The PyPI distribution, Python import package, and GitHub repository are all
|
|
274
|
+
named `vestigia`.
|
|
275
|
+
|
|
276
|
+
Install the core models without provider integrations:
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
python -m pip install vestigia
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Install optional integrations with `python -m pip install "vestigia[<extra>]"`,
|
|
283
|
+
`uv add "vestigia[<extra>]"`, or `poetry add "vestigia[<extra>]"`:
|
|
284
|
+
|
|
285
|
+
| Extra | Includes |
|
|
286
|
+
| --- | --- |
|
|
287
|
+
| `openai` | LangChain OpenAI integration |
|
|
288
|
+
| `typesafe` | TypeSafe classifier and YAML prompt support |
|
|
289
|
+
| `anthropic` | LangChain Anthropic integration |
|
|
290
|
+
| `all` | All optional integrations |
|
|
291
|
+
|
|
292
|
+
`ChatModelChunkClassifier` accepts any LangChain `BaseChatModel`, so the
|
|
293
|
+
`openai` and `anthropic` extras are conveniences rather than requirements.
|
|
294
|
+
|
|
295
|
+
## Development
|
|
296
|
+
|
|
297
|
+
Install [uv](https://docs.astral.sh/uv/), clone the repository, and install the
|
|
298
|
+
test and classifier dependencies:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
git clone https://github.com/Lorenzo-Gardini/vestigia.git
|
|
302
|
+
cd vestigia
|
|
303
|
+
uv sync --locked --group dev --all-extras
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Run the test suite:
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
uv run --locked --group dev --all-extras pytest
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The tests use real LangChain runnables and TypeSafe response models with mocked
|
|
313
|
+
providers. They require neither API keys nor network access to a model.
|
|
314
|
+
Documentation examples are tested without making real provider requests.
|
|
315
|
+
GitHub Actions runs on pushes and pull requests, checking the base installation,
|
|
316
|
+
each classifier extra separately, and the combined configuration on Python 3.12.
|
|
317
|
+
It also builds distributions, validates their metadata and README, and checks
|
|
318
|
+
imports and packaged resources from an isolated wheel installation.
|
|
319
|
+
|
|
320
|
+
For architecture and contribution guidance, see [AGENTS.md](AGENTS.md).
|
|
321
|
+
|
|
322
|
+
## Releasing to PyPI
|
|
323
|
+
|
|
324
|
+
Publishing uses [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/):
|
|
325
|
+
no PyPI API token needs to be stored in GitHub.
|
|
326
|
+
|
|
327
|
+
### Publishing configuration
|
|
328
|
+
|
|
329
|
+
Releases upload through the `pypi` GitHub environment in this repository's
|
|
330
|
+
settings; configure required reviewers there for manual approval before an
|
|
331
|
+
upload. The [vestigia PyPI project](https://pypi.org/manage/project/vestigia/settings/publishing/)
|
|
332
|
+
trusts this GitHub publisher:
|
|
333
|
+
|
|
334
|
+
| Setting | Value |
|
|
335
|
+
| --- | --- |
|
|
336
|
+
| PyPI project name | `vestigia` |
|
|
337
|
+
| Owner | `Lorenzo-Gardini` |
|
|
338
|
+
| Repository | `vestigia` |
|
|
339
|
+
| Workflow filename | `publish.yml` |
|
|
340
|
+
| Environment | `pypi` |
|
|
341
|
+
|
|
342
|
+
Ensure the PyPI Trusted Publisher configuration uses the current repository,
|
|
343
|
+
workflow, and environment values shown above.
|
|
344
|
+
|
|
345
|
+
### Publish a version
|
|
346
|
+
|
|
347
|
+
1. Update `project.version` in [pyproject.toml](pyproject.toml), run `uv lock`,
|
|
348
|
+
and commit the version and lockfile together.
|
|
349
|
+
2. Verify the tests and packaging locally:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
uv run --locked --group dev --all-extras pytest
|
|
353
|
+
uv build --no-sources
|
|
354
|
+
uvx --from twine twine check --strict dist/*
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Use a clean `dist/` directory so old artifacts are not included.
|
|
358
|
+
3. Merge the changes into the default branch and push them before releasing.
|
|
359
|
+
4. Publish a GitHub Release targeting that commit, with a tag exactly matching
|
|
360
|
+
`v<project.version>` (for example, `v0.1.0`). Creating a tag alone or saving a
|
|
361
|
+
draft release does not publish to PyPI.
|
|
362
|
+
5. The [publishing workflow](.github/workflows/publish.yml) checks the version,
|
|
363
|
+
runs all CI profiles, builds and validates the packages, then uploads those
|
|
364
|
+
same artifacts to PyPI after any environment approval.
|
|
365
|
+
6. Confirm the new version on [PyPI](https://pypi.org/project/vestigia/) and
|
|
366
|
+
install it in a fresh virtual environment:
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
python -m pip install "vestigia[openai]==0.1.0"
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Replace `0.1.0` with the version being verified.
|
|
373
|
+
|
|
374
|
+
PyPI releases cannot be overwritten. For a corrected artifact, bump the version
|
|
375
|
+
and publish a new release.
|
|
376
|
+
|
|
377
|
+
## License
|
|
378
|
+
|
|
379
|
+
Licensed under [Apache-2.0](LICENSE).
|