contextgem 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.
- contextgem-0.1.0/LICENSE +204 -0
- contextgem-0.1.0/NOTICE +56 -0
- contextgem-0.1.0/PKG-INFO +335 -0
- contextgem-0.1.0/README.md +286 -0
- contextgem-0.1.0/contextgem/__init__.py +81 -0
- contextgem-0.1.0/contextgem/internal/__init__.py +158 -0
- contextgem-0.1.0/contextgem/internal/base/__init__.py +49 -0
- contextgem-0.1.0/contextgem/internal/base/attrs.py +562 -0
- contextgem-0.1.0/contextgem/internal/base/concepts.py +141 -0
- contextgem-0.1.0/contextgem/internal/base/examples.py +46 -0
- contextgem-0.1.0/contextgem/internal/base/instances.py +133 -0
- contextgem-0.1.0/contextgem/internal/base/items.py +67 -0
- contextgem-0.1.0/contextgem/internal/base/llms.py +2054 -0
- contextgem-0.1.0/contextgem/internal/base/mixins.py +79 -0
- contextgem-0.1.0/contextgem/internal/base/paras_and_sents.py +76 -0
- contextgem-0.1.0/contextgem/internal/base/serialization.py +405 -0
- contextgem-0.1.0/contextgem/internal/data_models.py +182 -0
- contextgem-0.1.0/contextgem/internal/decorators.py +109 -0
- contextgem-0.1.0/contextgem/internal/items.py +210 -0
- contextgem-0.1.0/contextgem/internal/llm_output_structs/__init__.py +34 -0
- contextgem-0.1.0/contextgem/internal/llm_output_structs/aspect_structs.py +123 -0
- contextgem-0.1.0/contextgem/internal/llm_output_structs/concept_structs.py +113 -0
- contextgem-0.1.0/contextgem/internal/llm_output_structs/utils.py +38 -0
- contextgem-0.1.0/contextgem/internal/loggers.py +122 -0
- contextgem-0.1.0/contextgem/internal/prompts/extract_aspect_items.j2 +199 -0
- contextgem-0.1.0/contextgem/internal/prompts/extract_concept_items.j2 +298 -0
- contextgem-0.1.0/contextgem/internal/system/default_system_message.j2 +43 -0
- contextgem-0.1.0/contextgem/internal/typings/__init__.py +67 -0
- contextgem-0.1.0/contextgem/internal/typings/aliases.py +79 -0
- contextgem-0.1.0/contextgem/internal/typings/strings_to_types.py +200 -0
- contextgem-0.1.0/contextgem/internal/typings/types_to_strings.py +191 -0
- contextgem-0.1.0/contextgem/internal/typings/user_type_hints_validation.py +146 -0
- contextgem-0.1.0/contextgem/internal/utils.py +566 -0
- contextgem-0.1.0/contextgem/public/__init__.py +70 -0
- contextgem-0.1.0/contextgem/public/aspects.py +222 -0
- contextgem-0.1.0/contextgem/public/concepts.py +555 -0
- contextgem-0.1.0/contextgem/public/data_models.py +108 -0
- contextgem-0.1.0/contextgem/public/documents.py +356 -0
- contextgem-0.1.0/contextgem/public/examples.py +98 -0
- contextgem-0.1.0/contextgem/public/images.py +67 -0
- contextgem-0.1.0/contextgem/public/llms.py +1029 -0
- contextgem-0.1.0/contextgem/public/paragraphs.py +101 -0
- contextgem-0.1.0/contextgem/public/pipelines.py +67 -0
- contextgem-0.1.0/contextgem/public/sentences.py +60 -0
- contextgem-0.1.0/contextgem/public/utils.py +59 -0
- contextgem-0.1.0/pyproject.toml +128 -0
contextgem-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright (c) 2025 Shcherbak AI AS. All rights reserved. Developed by Sergii Shcherbak.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
contextgem-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
ContextGem - Easier and faster way to build LLM extraction workflows through powerful abstractions
|
|
2
|
+
=========================================================================================================
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2025 Shcherbak AI AS
|
|
5
|
+
All rights reserved
|
|
6
|
+
Developed by Sergii Shcherbak
|
|
7
|
+
|
|
8
|
+
This software is licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License.
|
|
10
|
+
You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
See the License for the specific language governing permissions and
|
|
18
|
+
limitations under the License.
|
|
19
|
+
|
|
20
|
+
==============================================================================
|
|
21
|
+
THIRD-PARTY COMPONENTS
|
|
22
|
+
==============================================================================
|
|
23
|
+
|
|
24
|
+
This software includes the following third-party components:
|
|
25
|
+
|
|
26
|
+
Core Dependencies:
|
|
27
|
+
- aiolimiter: Rate limiting for asynchronous operations
|
|
28
|
+
- Jinja2: Template engine
|
|
29
|
+
- litellm: LLM interface library (this software uses only MIT-licensed portions of LiteLLM and does not utilize any components from the enterprise/ directory)
|
|
30
|
+
- loguru: Logging utility
|
|
31
|
+
- pydantic: Data validation
|
|
32
|
+
- python-ulid: ULID generation
|
|
33
|
+
- torch: PyTorch for machine learning
|
|
34
|
+
- wtpsplit: Text splitting utility
|
|
35
|
+
|
|
36
|
+
Development Dependencies:
|
|
37
|
+
- black: Code formatting
|
|
38
|
+
- coverage: Test coverage measurement
|
|
39
|
+
- isort: Sorting imports
|
|
40
|
+
- pip-tools: Dependency management
|
|
41
|
+
- pre-commit: Pre-commit hooks
|
|
42
|
+
- pytest: Testing framework
|
|
43
|
+
- pytest-cov: Coverage plugin for pytest
|
|
44
|
+
- pytest-vcr: Recording HTTP interactions for tests
|
|
45
|
+
- python-dotenv: Environment variable management
|
|
46
|
+
- sphinx: Documentation generator
|
|
47
|
+
- sphinx-autodoc-typehints: Type annotation support for Sphinx
|
|
48
|
+
- sphinx-book-theme: Book-like theme for Sphinx
|
|
49
|
+
- sphinx-copybutton: Adds copy button to code blocks in Sphinx docs
|
|
50
|
+
- sphinx-design: Component library for Sphinx documentation
|
|
51
|
+
- sphinxext-opengraph: OpenGraph metadata support for Sphinx documentation
|
|
52
|
+
|
|
53
|
+
Each of these components may have their own licenses. Users should refer to the
|
|
54
|
+
respective project repositories for detailed license information.
|
|
55
|
+
|
|
56
|
+
==============================================================================
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: contextgem
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Easier and faster way to build LLM extraction workflows through powerful abstractions
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Keywords: document,extraction,llm,ai,nlp,insights,structured-data,document-processing,text-analysis,information-extraction,insights-extraction,document-parsing,data-extraction,machine-learning,large-language-models,document-intelligence,document-understanding,semantic-analysis,text-processing,content-extraction,unstructured-data,legaltech,contract-analysis,contract-review,contract-parsing,contract-intelligence,contract-automation,contract-management,document-qa,question-answering,generative-ai,knowledge-extraction,entity-extraction,context-aware,zero-shot,few-shot,prompt-engineering
|
|
7
|
+
Author: shcherbak-ai
|
|
8
|
+
Author-email: sergii@shcherbak.ai
|
|
9
|
+
Maintainer: shcherbak-ai
|
|
10
|
+
Maintainer-email: sergii@shcherbak.ai
|
|
11
|
+
Requires-Python: >=3.10,<3.14
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Information Technology
|
|
16
|
+
Classifier: Intended Audience :: Legal Industry
|
|
17
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
18
|
+
Classifier: Intended Audience :: Education
|
|
19
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
26
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Topic :: Office/Business
|
|
29
|
+
Classifier: Topic :: Text Processing :: General
|
|
30
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
31
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
32
|
+
Classifier: Topic :: Utilities
|
|
33
|
+
Classifier: Topic :: Education
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Requires-Dist: aiolimiter (>=1.2.1,<2.0.0)
|
|
36
|
+
Requires-Dist: jinja2 (>=3.1.5,<4.0.0)
|
|
37
|
+
Requires-Dist: litellm (>=1.63.3,<2.0.0)
|
|
38
|
+
Requires-Dist: loguru (>=0.7.3,<0.8.0)
|
|
39
|
+
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
|
|
40
|
+
Requires-Dist: python-ulid (>=3.0.0,<4.0.0)
|
|
41
|
+
Requires-Dist: torch (>=2.6.0,<3.0.0)
|
|
42
|
+
Requires-Dist: wtpsplit (>=2.1.4,<3.0.0)
|
|
43
|
+
Project-URL: Bug Tracker, https://github.com/shcherbak-ai/contextgem/issues
|
|
44
|
+
Project-URL: Documentation, https://github.com/shcherbak-ai/contextgem/blob/main/README.md
|
|
45
|
+
Project-URL: Homepage, https://github.com/shcherbak-ai/contextgem
|
|
46
|
+
Project-URL: Repository, https://github.com/shcherbak-ai/contextgem.git
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
# ContextGem: Easier and faster way to build LLM extraction workflows
|
|
52
|
+
|
|
53
|
+
[](https://github.com/shcherbak-ai/contextgem/actions/workflows/ci-tests.yml)
|
|
54
|
+
[](https://github.com/shcherbak-ai/contextgem/actions)
|
|
55
|
+
[](https://github.com/shcherbak-ai/contextgem/actions/workflows/docs.yml)
|
|
56
|
+
[](https://shcherbak-ai.github.io/contextgem/)
|
|
57
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
58
|
+
[](https://www.python.org/downloads/)
|
|
59
|
+
[](https://github.com/psf/black)
|
|
60
|
+
[](https://pycqa.github.io/isort/)
|
|
61
|
+
[](https://pydantic.dev)
|
|
62
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
63
|
+
[](CODE_OF_CONDUCT.md)
|
|
64
|
+
|
|
65
|
+
ContextGem is an LLM framework for easier, faster extraction of structured data and insights from documents through powerful abstractions.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## 💎 Why ContextGem?
|
|
69
|
+
|
|
70
|
+
Most popular LLM frameworks for extracting structured data from documents require extensive boilerplate code to extract even basic information. This significantly increases development time and complexity.
|
|
71
|
+
|
|
72
|
+
ContextGem addresses this challenge by providing a flexible, intuitive framework that extracts structured data and insights from documents with minimal effort. Complex, most time-consuming parts are handled with **powerful abstractions**, eliminating boilerplate code and reducing development overhead.
|
|
73
|
+
|
|
74
|
+
Read more on the project [motivation](https://contextgem.dev/motivation.html) in the documentation.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## ⭐ Key features
|
|
78
|
+
|
|
79
|
+
<table>
|
|
80
|
+
<thead>
|
|
81
|
+
<tr style="text-align: left; opacity: 0.8;">
|
|
82
|
+
<th style="width: 75%">Built-in abstractions</th>
|
|
83
|
+
<th style="width: 10%"><strong>ContextGem</strong></th>
|
|
84
|
+
<th style="width: 15%">Other LLM frameworks*</th>
|
|
85
|
+
</tr>
|
|
86
|
+
</thead>
|
|
87
|
+
<tbody>
|
|
88
|
+
<tr>
|
|
89
|
+
<td>
|
|
90
|
+
Automated dynamic prompts
|
|
91
|
+
</td>
|
|
92
|
+
<td>✅</td>
|
|
93
|
+
<td>❌</td>
|
|
94
|
+
</tr>
|
|
95
|
+
<tr>
|
|
96
|
+
<td>
|
|
97
|
+
Automated data modelling and validators
|
|
98
|
+
</td>
|
|
99
|
+
<td>✅</td>
|
|
100
|
+
<td>❌</td>
|
|
101
|
+
</tr>
|
|
102
|
+
<tr>
|
|
103
|
+
<td>
|
|
104
|
+
Precise granular reference mapping (paragraphs & sentences)
|
|
105
|
+
</td>
|
|
106
|
+
<td>✅</td>
|
|
107
|
+
<td>❌</td>
|
|
108
|
+
</tr>
|
|
109
|
+
<tr>
|
|
110
|
+
<td>
|
|
111
|
+
Justifications (reasoning backing the extraction)
|
|
112
|
+
</td>
|
|
113
|
+
<td>✅</td>
|
|
114
|
+
<td>❌</td>
|
|
115
|
+
</tr>
|
|
116
|
+
<tr>
|
|
117
|
+
<td>
|
|
118
|
+
Neural segmentation (SaT)
|
|
119
|
+
</td>
|
|
120
|
+
<td>✅</td>
|
|
121
|
+
<td>❌</td>
|
|
122
|
+
</tr>
|
|
123
|
+
<tr>
|
|
124
|
+
<td>
|
|
125
|
+
Multilingual support (I/O without prompting)
|
|
126
|
+
</td>
|
|
127
|
+
<td>✅</td>
|
|
128
|
+
<td>❌</td>
|
|
129
|
+
</tr>
|
|
130
|
+
<tr>
|
|
131
|
+
<td>
|
|
132
|
+
Single, unified extraction pipeline (declarative, reusable, fully serializable)
|
|
133
|
+
</td>
|
|
134
|
+
<td>✅</td>
|
|
135
|
+
<td>⚠️</td>
|
|
136
|
+
</tr>
|
|
137
|
+
<tr>
|
|
138
|
+
<td>
|
|
139
|
+
Grouped LLMs with role-specific tasks
|
|
140
|
+
</td>
|
|
141
|
+
<td>✅</td>
|
|
142
|
+
<td>⚠️</td>
|
|
143
|
+
</tr>
|
|
144
|
+
<tr>
|
|
145
|
+
<td>
|
|
146
|
+
Nested context extraction
|
|
147
|
+
</td>
|
|
148
|
+
<td>✅</td>
|
|
149
|
+
<td>⚠️</td>
|
|
150
|
+
</tr>
|
|
151
|
+
<tr>
|
|
152
|
+
<td>
|
|
153
|
+
Unified, fully serializable results storage model (document)
|
|
154
|
+
</td>
|
|
155
|
+
<td>✅</td>
|
|
156
|
+
<td>⚠️</td>
|
|
157
|
+
</tr>
|
|
158
|
+
<tr>
|
|
159
|
+
<td>
|
|
160
|
+
Extraction task calibration with examples
|
|
161
|
+
</td>
|
|
162
|
+
<td>✅</td>
|
|
163
|
+
<td>⚠️</td>
|
|
164
|
+
</tr>
|
|
165
|
+
<tr>
|
|
166
|
+
<td>
|
|
167
|
+
Built-in concurrent I/O processing
|
|
168
|
+
</td>
|
|
169
|
+
<td>✅</td>
|
|
170
|
+
<td>⚠️</td>
|
|
171
|
+
</tr>
|
|
172
|
+
<tr>
|
|
173
|
+
<td>
|
|
174
|
+
Automated usage & costs tracking
|
|
175
|
+
</td>
|
|
176
|
+
<td>✅</td>
|
|
177
|
+
<td>⚠️</td>
|
|
178
|
+
</tr>
|
|
179
|
+
<tr>
|
|
180
|
+
<td>
|
|
181
|
+
Fallback and retry logic
|
|
182
|
+
</td>
|
|
183
|
+
<td>✅</td>
|
|
184
|
+
<td>✅</td>
|
|
185
|
+
</tr>
|
|
186
|
+
<tr>
|
|
187
|
+
<td>
|
|
188
|
+
Multiple LLM providers
|
|
189
|
+
</td>
|
|
190
|
+
<td>✅</td>
|
|
191
|
+
<td>✅</td>
|
|
192
|
+
</tr>
|
|
193
|
+
</tbody>
|
|
194
|
+
</table>
|
|
195
|
+
|
|
196
|
+
✅ - fully supported - no additional setup required<br>
|
|
197
|
+
⚠️ - partially supported - requires additional setup<br>
|
|
198
|
+
❌ - not supported - requires custom logic
|
|
199
|
+
|
|
200
|
+
\* See [descriptions](https://contextgem.dev/motivation.html#the-contextgem-solution) of ContextGem abstractions and [comparisons](https://contextgem.dev/vs_other_frameworks.html) of specific implementation examples using ContextGem and other popular open-source LLM frameworks.
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## 📦 Installation
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
pip install -U contextgem
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## 🚀 Quick start
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
# Quick Start Example - Extracting anomalies from a document, with source references and justifications
|
|
214
|
+
|
|
215
|
+
import os
|
|
216
|
+
|
|
217
|
+
from contextgem import Document, DocumentLLM, StringConcept
|
|
218
|
+
|
|
219
|
+
# Example document instance
|
|
220
|
+
# Document content is shortened for brevity
|
|
221
|
+
doc = Document(
|
|
222
|
+
raw_text=(
|
|
223
|
+
"Consultancy Agreement\n"
|
|
224
|
+
"This agreement between Company A (Supplier) and Company B (Customer)...\n"
|
|
225
|
+
"The term of the agreement is 1 year from the Effective Date...\n"
|
|
226
|
+
"The Supplier shall provide consultancy services as described in Annex 2...\n"
|
|
227
|
+
"The Customer shall pay the Supplier within 30 calendar days of receiving an invoice...\n"
|
|
228
|
+
"The purple elephant danced gracefully on the moon while eating ice cream.\n" # out-of-context / anomaly
|
|
229
|
+
"This agreement is governed by the laws of Norway...\n"
|
|
230
|
+
),
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
# Attach a document-level concept
|
|
234
|
+
doc.concepts = [
|
|
235
|
+
StringConcept(
|
|
236
|
+
name="Anomalies", # in longer contexts, this concept is hard to capture with RAG
|
|
237
|
+
description="Anomalies in the document",
|
|
238
|
+
add_references=True,
|
|
239
|
+
reference_depth="sentences",
|
|
240
|
+
add_justifications=True,
|
|
241
|
+
justification_depth="brief",
|
|
242
|
+
# add more concepts to the document, if needed
|
|
243
|
+
)
|
|
244
|
+
]
|
|
245
|
+
# Or use doc.add_concepts([...])
|
|
246
|
+
|
|
247
|
+
# Create an LLM for extracting data and insights from the document
|
|
248
|
+
llm = DocumentLLM(
|
|
249
|
+
model="openai/gpt-4o-mini", # or any other LLM from e.g. Anthropic, etc.
|
|
250
|
+
api_key=os.environ.get(
|
|
251
|
+
"CONTEXTGEM_OPENAI_API_KEY"
|
|
252
|
+
), # your API key for the LLM provider
|
|
253
|
+
# see the docs for more configuration options
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Extract information from the document
|
|
257
|
+
doc = llm.extract_all(doc) # or use async version llm.extract_all_async(doc)
|
|
258
|
+
|
|
259
|
+
# Access extracted information in the document object
|
|
260
|
+
print(doc.concepts[0].extracted_items) # extracted items with references justifications
|
|
261
|
+
# or doc.get_concept_by_name("Anomalies").extracted_items
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
See more examples in the documentation:
|
|
266
|
+
|
|
267
|
+
### Basic usage examples
|
|
268
|
+
- [Aspect Extraction from Document](https://contextgem.dev/quickstart.html#aspect-extraction-from-document)
|
|
269
|
+
- [Extracting Aspect with Sub-Aspects](https://contextgem.dev/quickstart.html#extracting-aspect-with-sub-aspects)
|
|
270
|
+
- [Concept Extraction from Aspect](https://contextgem.dev/quickstart.html#concept-extraction-from-aspect)
|
|
271
|
+
- [Concept Extraction from Document (text)](https://contextgem.dev/quickstart.html#concept-extraction-from-document-text)
|
|
272
|
+
- [Concept Extraction from Document (vision)](https://contextgem.dev/quickstart.html#concept-extraction-from-document-vision)
|
|
273
|
+
|
|
274
|
+
### Advanced usage examples
|
|
275
|
+
- [Extracting Aspects Containing Concepts](https://contextgem.dev/advanced_usage.html#extracting-aspects-with-concepts)
|
|
276
|
+
- [Extracting Aspects and Concepts from a Document](https://contextgem.dev/advanced_usage.html#extracting-aspects-and-concepts-from-a-document)
|
|
277
|
+
- [Using a Multi-LLM Pipeline to Extract Data from Several Documents](https://contextgem.dev/advanced_usage.html#using-a-multi-llm-pipeline-to-extract-data-from-several-documents)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
## 🎯 Focused document analysis
|
|
281
|
+
|
|
282
|
+
ContextGem leverages LLMs' long context windows to deliver superior extraction accuracy from individual documents. Unlike RAG approaches that often [struggle with complex concepts and nuanced insights](https://www.linkedin.com/pulse/raging-contracts-pitfalls-rag-contract-review-shcherbak-ai-ptg3f), ContextGem capitalizes on [continuously expanding context capacity](https://arxiv.org/abs/2502.12962), evolving LLM capabilities, and decreasing costs. This focused approach enables direct information extraction from complete documents, eliminating retrieval inconsistencies while optimizing for in-depth single-document analysis. While this delivers maximum accuracy for individual documents, ContextGem does not currently support cross-document querying or corpus-wide retrieval - for these use cases, traditional RAG systems (e.g., LlamaIndex, Haystack) remain more appropriate.
|
|
283
|
+
|
|
284
|
+
Read more on [how it works](https://contextgem.dev/how_it_works.html) in the documentation.
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
## ⚡ Optimizations
|
|
288
|
+
|
|
289
|
+
ContextGem documentation offers guidance on optimization strategies to maximize performance, minimize costs, and enhance extraction accuracy:
|
|
290
|
+
|
|
291
|
+
- [Optimizing for Accuracy](https://contextgem.dev/optimizations/optimization_accuracy.html)
|
|
292
|
+
- [Optimizing for Speed](https://contextgem.dev/optimizations/optimization_speed.html)
|
|
293
|
+
- [Optimizing for Cost](https://contextgem.dev/optimizations/optimization_cost.html)
|
|
294
|
+
- [Dealing with Long Documents](https://contextgem.dev/optimizations/optimization_long_docs.html)
|
|
295
|
+
- [Choosing the Right LLM(s)](https://contextgem.dev/optimizations/optimization_choosing_llm.html)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
## 📚 Documentation
|
|
299
|
+
|
|
300
|
+
Full documentation is available at [contextgem.dev](https://contextgem.dev).
|
|
301
|
+
|
|
302
|
+
A raw text version of the full documentation is available at [`docs/docs-raw-for-llm.txt`](https://github.com/shcherbak-ai/contextgem/blob/main/docs/docs-raw-for-llm.txt). This file is automatically generated and contains all documentation in a format optimized for LLM ingestion (e.g. for Q&A).
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
## 💬 Community
|
|
306
|
+
|
|
307
|
+
If you have a feature request or a bug report, feel free to [open an issue](https://github.com/shcherbak-ai/contextgem/issues/new) on GitHub. If you'd like to discuss a topic or get general advice on using ContextGem for your project, start a thread in [GitHub Discussions](https://github.com/shcherbak-ai/contextgem/discussions/new/).
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
## 🤝 Contributing
|
|
311
|
+
|
|
312
|
+
We welcome contributions from the community - whether it's fixing a typo or developing a completely new feature! To get started, please check out our [Contributor Guidelines](https://github.com/shcherbak-ai/contextgem/blob/main/CONTRIBUTING.md).
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
## 🗺️ Roadmap
|
|
316
|
+
|
|
317
|
+
ContextGem is at an early stage. Our development roadmap includes:
|
|
318
|
+
|
|
319
|
+
- **Enhanced Analytical Abstractions**: Building more sophisticated analytical layers on top of the core extraction workflow to enable deeper insights and more complex document understanding
|
|
320
|
+
- **API Simplification**: Continuing to refine and streamline the API surface to make document analysis more intuitive and accessible
|
|
321
|
+
- **Terminology Refinement**: Improving consistency and clarity of terminology throughout the framework to enhance developer experience
|
|
322
|
+
|
|
323
|
+
We are committed to making ContextGem the most effective tool for extracting structured information from documents.
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
## 📄 License & Contact
|
|
327
|
+
|
|
328
|
+
This project is licensed under the Apache 2.0 License - see the [LICENSE](https://github.com/shcherbak-ai/contextgem/blob/main/LICENSE) and [NOTICE](https://github.com/shcherbak-ai/contextgem/blob/main/NOTICE) files for details.
|
|
329
|
+
|
|
330
|
+
Copyright © 2025 [Shcherbak AI AS](https://shcherbak.ai) - AI engineering company developing tools for AI/ML/NLP developers.
|
|
331
|
+
|
|
332
|
+
[Connect with us on LinkedIn](https://www.linkedin.com/in/sergii-shcherbak-10068866/) for questions or collaboration ideas.
|
|
333
|
+
|
|
334
|
+
Built with ❤️ in Oslo, Norway.
|
|
335
|
+
|