GGitHub采集材料
ContextGem:从文档提取可溯源信息
发布时间未知 · 北京时间
本地部署
有实践材料可继续查看
代码仓库安装说明使用说明示例代码
原文与观测指标
1 个来源GGitHub
查看原文 ContextGem:从文档提取可溯源信息
shcherbak-ai星标2,020采集时的累计值
每小时增长待观察星标 / 小时 · 观测区间平均值
最近提交10-27 10:11提交时间不是项目发布时间
发布时间:未知 · 首次发现 10-27 15:47 · 北京时间
指标采集:10-27 15:47 · 指标已取得
项目文档有线索安装说明有线索使用说明有线索示例有线索
仅反映文档与示例线索,未实际运行项目。
摘要
ContextGem 用声明式流程从文档提取结构化信息,无需手写提示词,并将结果验证为指定类型、关联回原文段落或句子。它还可将开放式问题交给 LLM、封闭式判断交给决策模型,并设置概率阈值。
摘要由 AI 生成,请以原文为准。观测历史 · 最近 1 条 展开 / 收起
缺失不计为零;增长只比较同一指标来源的有效记录,按实际间隔折算每小时。上游缓存可能延迟数值更新。
| 采集时间 · 北京时间 | 指标 | 数值 | 来源 | 状态 |
|---|---|---|---|---|
| 10-27 15:47:53 | Star | 2,020 | GitHub 公开页面 | 已取得 |
采集原文 展开 / 收起
contextgem
Extract structured data and insights from documents using LLMs and decision models
项目说明 展开 / 收起
Extract structured data and insights from documents using LLMs and decision models Describe, don't prompt. Quickstart · How it works · Agentic workflows · Changelog · Security · Documentation An illustrative contract. Every extracted fact is traced back to its source. Note New in 1.0: decision models. Next to LLMs, ContextGem now works with decision models, which answer closed questions (yes/no, one of your labels, a level of a scale) with the probability of each possible answer, fast and at a low cost. A model group sends each aspect and concept to the model that suits it, and any model can fall back on others: see LLMs and decision models. Upgrading from 0.x? Some classes and parameters are renamed or removed, some defaults have changed, and Python 3.10 is no longer supported. Follow the migration guide, or point a coding agent at llms.txt, the index of the documentation. ContextGem is a free, open-source framework that does the work around the models for you: the prompts, the data models, the source references and the justifications, with minimal code. Why ContextGem Reliable extraction from documents usually means writing prompts, designing validation models, mapping outputs back to the source, orchestrating multi-step pipelines and tracking usage across models. ContextGem has all of this built in, in one declarative pipeline that you can reuse and serialize. No prompts to write Prompts are generated from your descriptions of what to extract. Typed, validated output Text, numbers, dates, booleans, labels, ratings and JSON objects. Every fact traced to its source Items map back to their paragraphs or sentences, with the reasoning on request. Nested context Aspects, sub-aspects and concepts focus the model on the text that matters. The right model for each question An LLM where it takes reasoning, a decision model where a fast, low-cost answer is enough. Answers with probabilities A decision model gives the probability of each possible answer, and you set the threshold. Read more on the motivation behind ContextGem. LLMs and decision models ContextGem works with two kinds of models. You describe what to extract in the same way for both, and each aspect and concept goes to the model that suits it. An illustrative service agreement: the open question goes to the LLM, the closed ones to the decision model. LLM Decision model How it answers Writes the answer, which ContextGem validates into typed items Gives the probability of each possible answer, and writes no text What it extracts Aspects and every type of concept, from text and images Aspects, and Boolean, label and rating concepts, from text With each item References to paragraphs or sentences, and a justification on request The probabilities of all the possible answers, and a decision threshold that you set for the model, or for each aspect and concept Use it for Open values, and answers that take reasoning Closed questions in volume, where a fast, low-cost answer is enough Models Any cloud or local LLM through LiteLLM: OpenAI, Anthropic, Google, Azure OpenAI, xAI, Ollama, LM Studio and more TypeSafe Jev, OpenAI Decisions API, Microsoft Foundry and more, cloud or local Read more Supported LLMs, configuration, extraction methods Decision models Choosing a model. ContextGem is tested with hosted LLMs such as gpt-6-luna (OpenAI) and claude-haiku-5-5 (Anthropic), and with decision models such as Jev (TypeSafe). A smaller LLM, such as many that run locally, may not follow the detailed extraction instructions: check it on a sample of your documents, and see the troubleshooting guide if it falls short. Before you give questions to a decision model, compare it with an LLM on a sample of your documents: see when to use a decision model. Quick start uv add contextgem # or: pip install -U contextgem uv add "contextgem[docling]" # with Docling, to convert PDF, DOCX and other files Extract with an LLM An LLM extracts aspects and values of any type. Below, it extracts two things from a contract: an aspect, the payment terms, which comes back as the paragraphs on payments, and a concept, the anomalies, which span the whole document and which retrieval-based approaches can miss. Each anomaly comes with a justification and the sentence it was found in. import os from contextgem import Aspect, Document, DocumentLLM, StringConcept doc = Document( raw_text=( "Consultancy Agreement\n" "This agreement between Company A (Supplier) and Company B (Customer)...\n" "The term of the agreement is 1 year from the Effective Date...\n" "The Supplier shall provide consultancy services as described in Annex 2...\n" "The Customer shall pay the Supplier within 30 calendar days of receiving an invoice...\n" "The purple elephant danced gracefully on the moon while eating ice cream.\n" # 💎 anomaly "Time-traveling dinosaurs will review all deliverables before acceptance.\n" # 💎 another anomaly "This agreement is governed by the laws of Norway...\n" ), ) doc.add_aspects( [ Aspect( name="Payment terms", description="Clauses on payments, fees and invoices", ) ] ) doc.add_concepts( [ StringConcept( name="Anomalies", description="Anomalies in the document", add_references=True, reference_depth="sentences", add_justifications=True, justification_depth="brief", ) ] ) llm = DocumentLLM( model="openai/gpt-6-luna", # or another LLM, cloud or local api_key=os.environ.get("CONTEXTGEM_OPENAI_API_KEY"), ) doc = llm.extract_all(doc) payment_terms = doc.get_aspect_by_name("Payment terms").extracted_items # 1 item, the paragraph: "The Customer shall pay the Supplier within 30 calendar # days of receiving an invoice..." anomalies = doc.get_concept_by_name("Anomalies").extracted_items # 2 items. The first one: # .value: "The statement that a purple elephant danced on the moon while eating # ice cream is anomalous and unrelated to the consultancy agreement." # .justification: "It is an implausible, fantastical statement in an otherwise # contractual document." # .reference_sentences: the sent