graph-knowledge-doc-parser 0.2.10__tar.gz → 0.2.11__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.
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/PKG-INFO +12 -2
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/README.md +11 -1
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/__init__.py +2 -1
- graph_knowledge_doc_parser-0.2.11/kg_doc_parser/workflow_ingest/cache.py +150 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/demo_harness.py +10 -4
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/handlers.py +3 -1
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/parser_core.py +4 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/providers.py +13 -1
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/pyproject.toml +1 -1
- graph_knowledge_doc_parser-0.2.10/kg_doc_parser/workflow_ingest/cache.py +0 -76
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/__init__.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/cast_hinting.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/document_ingest_log_config.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/document_ingester_logger.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/llm_structured_output.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/models.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/ocr.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/pdf2png.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/semantic_document_splitting_layerwise_edits.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/text_processing_utils.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/__init__.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/bounded_threadpool_executor.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/file_loaders.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/langchain.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/log.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/version_chaining.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/_kogwistar.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/adapters.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/cli.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/clients.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/design.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/layered_contracts.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/layerwise_llm.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/models.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/ocr_pipeline.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/page_index.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/parsing.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/probe.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/runners.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/semantics.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/serialization.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/service.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/smoke_assets.py +0 -0
- {graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/workflow_ingest/strategy.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graph-knowledge-doc-parser
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.11
|
|
4
4
|
Summary: doc parser using llm driven engine with graph knowledge awareness
|
|
5
5
|
Author: humblemat810
|
|
6
6
|
Author-email: 67593116+humblemat810@users.noreply.github.com
|
|
@@ -86,8 +86,12 @@ to normal strategy selection. See the
|
|
|
86
86
|
The deterministic and text-only Bonsai fixture evaluation is recorded in the
|
|
87
87
|
[`PageIndex adversarial fixture report`](doc/page_index_adversarial_fixture_report.md).
|
|
88
88
|
The current patch release is documented in the
|
|
89
|
-
[`0.2.
|
|
89
|
+
[`0.2.11` release note](doc/release_0.2.11.md); the prior
|
|
90
90
|
[`0.2.7` release note](doc/release_0.2.7.md) remains available for history.
|
|
91
|
+
For cache reuse and provider/runtime isolation rules, see
|
|
92
|
+
[`doc/cache_reuse_and_isolation.md`](doc/cache_reuse_and_isolation.md).
|
|
93
|
+
For provider timeout, in-flight slot, and orphaned-call safety, see
|
|
94
|
+
[`doc/provider_timeout_safety.md`](doc/provider_timeout_safety.md).
|
|
91
95
|
|
|
92
96
|
For an adoption path that starts with parser-grounded source units and later
|
|
93
97
|
adds LLM-Wiki cross-document maintenance, see
|
|
@@ -256,6 +260,11 @@ and structured extraction.
|
|
|
256
260
|
- `KG_DOC_PARSER_PROVIDER=openai`
|
|
257
261
|
- `KG_DOC_PARSER_MODEL=gpt-4.1-mini`
|
|
258
262
|
- `KG_DOC_PARSER_API_KEY_ENV=OPENAI_API_KEY`
|
|
263
|
+
- `KG_DOC_PARSER_REASONING_EFFORT=medium` (optional)
|
|
264
|
+
- OpenAI-compatible REST endpoint:
|
|
265
|
+
- `KG_DOC_PARSER_PROVIDER=openai`
|
|
266
|
+
- `KG_DOC_PARSER_BASE_URL=http://127.0.0.1:8181/v1`
|
|
267
|
+
- `KG_DOC_PARSER_REASONING_EFFORT=medium` (optional)
|
|
259
268
|
- LangChain Ollama:
|
|
260
269
|
- `KG_DOC_PARSER_PROVIDER=ollama`
|
|
261
270
|
- `KG_DOC_PARSER_MODEL=llama3.1`
|
|
@@ -295,6 +304,7 @@ KG_DOC_OCR_MODEL=gemini-2.5-flash
|
|
|
295
304
|
KG_DOC_PARSER_PROVIDER=openai
|
|
296
305
|
KG_DOC_PARSER_MODEL=gpt-4.1-mini
|
|
297
306
|
KG_DOC_PARSER_API_KEY_ENV=OPENAI_API_KEY
|
|
307
|
+
KG_DOC_PARSER_REASONING_EFFORT=medium
|
|
298
308
|
KG_DOC_EMBED_PROVIDER=fake
|
|
299
309
|
```
|
|
300
310
|
|
|
@@ -45,8 +45,12 @@ to normal strategy selection. See the
|
|
|
45
45
|
The deterministic and text-only Bonsai fixture evaluation is recorded in the
|
|
46
46
|
[`PageIndex adversarial fixture report`](doc/page_index_adversarial_fixture_report.md).
|
|
47
47
|
The current patch release is documented in the
|
|
48
|
-
[`0.2.
|
|
48
|
+
[`0.2.11` release note](doc/release_0.2.11.md); the prior
|
|
49
49
|
[`0.2.7` release note](doc/release_0.2.7.md) remains available for history.
|
|
50
|
+
For cache reuse and provider/runtime isolation rules, see
|
|
51
|
+
[`doc/cache_reuse_and_isolation.md`](doc/cache_reuse_and_isolation.md).
|
|
52
|
+
For provider timeout, in-flight slot, and orphaned-call safety, see
|
|
53
|
+
[`doc/provider_timeout_safety.md`](doc/provider_timeout_safety.md).
|
|
50
54
|
|
|
51
55
|
For an adoption path that starts with parser-grounded source units and later
|
|
52
56
|
adds LLM-Wiki cross-document maintenance, see
|
|
@@ -215,6 +219,11 @@ and structured extraction.
|
|
|
215
219
|
- `KG_DOC_PARSER_PROVIDER=openai`
|
|
216
220
|
- `KG_DOC_PARSER_MODEL=gpt-4.1-mini`
|
|
217
221
|
- `KG_DOC_PARSER_API_KEY_ENV=OPENAI_API_KEY`
|
|
222
|
+
- `KG_DOC_PARSER_REASONING_EFFORT=medium` (optional)
|
|
223
|
+
- OpenAI-compatible REST endpoint:
|
|
224
|
+
- `KG_DOC_PARSER_PROVIDER=openai`
|
|
225
|
+
- `KG_DOC_PARSER_BASE_URL=http://127.0.0.1:8181/v1`
|
|
226
|
+
- `KG_DOC_PARSER_REASONING_EFFORT=medium` (optional)
|
|
218
227
|
- LangChain Ollama:
|
|
219
228
|
- `KG_DOC_PARSER_PROVIDER=ollama`
|
|
220
229
|
- `KG_DOC_PARSER_MODEL=llama3.1`
|
|
@@ -254,6 +263,7 @@ KG_DOC_OCR_MODEL=gemini-2.5-flash
|
|
|
254
263
|
KG_DOC_PARSER_PROVIDER=openai
|
|
255
264
|
KG_DOC_PARSER_MODEL=gpt-4.1-mini
|
|
256
265
|
KG_DOC_PARSER_API_KEY_ENV=OPENAI_API_KEY
|
|
266
|
+
KG_DOC_PARSER_REASONING_EFFORT=medium
|
|
257
267
|
KG_DOC_EMBED_PROVIDER=fake
|
|
258
268
|
```
|
|
259
269
|
|
|
@@ -4,7 +4,7 @@ from .adapters import (
|
|
|
4
4
|
build_parser_source_map,
|
|
5
5
|
normalize_ocr_pages,
|
|
6
6
|
)
|
|
7
|
-
from .cache import WorkflowLLMCallCache
|
|
7
|
+
from .cache import WorkflowLLMCallCache, workflow_cache_namespace
|
|
8
8
|
from .clients import (
|
|
9
9
|
CanonicalGraphPersistenceClient,
|
|
10
10
|
DirectRuntimeIngestClient,
|
|
@@ -186,6 +186,7 @@ __all__ = [
|
|
|
186
186
|
"WorkflowExportBundle",
|
|
187
187
|
"WorkflowIngestInput",
|
|
188
188
|
"WorkflowLLMCallCache",
|
|
189
|
+
"workflow_cache_namespace",
|
|
189
190
|
"WorkflowPersistenceLike",
|
|
190
191
|
"WorkflowProbe",
|
|
191
192
|
"WorkflowProviderSettings",
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import platform
|
|
6
|
+
import tempfile
|
|
7
|
+
import threading
|
|
8
|
+
from collections.abc import Callable, Mapping
|
|
9
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import TypeVar, cast
|
|
12
|
+
|
|
13
|
+
from kogwistar.id_provider import stable_id
|
|
14
|
+
|
|
15
|
+
from .probe import WorkflowProbe, emit_probe_event
|
|
16
|
+
|
|
17
|
+
T = TypeVar("T")
|
|
18
|
+
CACHE_CONTRACT_VERSION = 2
|
|
19
|
+
_PACKAGE_NAME = "graph-knowledge-doc-parser"
|
|
20
|
+
_CACHE_WRITE_LOCK = threading.Lock()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def workflow_cache_namespace(provider_settings: object | None = None) -> dict[str, object]:
|
|
24
|
+
"""Return stable, non-secret identity for workflow LLM cache entries.
|
|
25
|
+
|
|
26
|
+
The request fingerprint remains responsible for source and prompt inputs.
|
|
27
|
+
This namespace prevents an entry produced by a different parser release,
|
|
28
|
+
runtime, or provider configuration from being reused accidentally.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
package_version = version(_PACKAGE_NAME)
|
|
33
|
+
except PackageNotFoundError:
|
|
34
|
+
package_version = "uninstalled"
|
|
35
|
+
settings: object = provider_settings
|
|
36
|
+
model_dump = getattr(settings, "model_dump", None)
|
|
37
|
+
if callable(model_dump):
|
|
38
|
+
try:
|
|
39
|
+
settings = model_dump(mode="json", exclude_none=True)
|
|
40
|
+
except TypeError:
|
|
41
|
+
settings = model_dump()
|
|
42
|
+
return {
|
|
43
|
+
"cache_contract_version": CACHE_CONTRACT_VERSION,
|
|
44
|
+
"parser_package": _PACKAGE_NAME,
|
|
45
|
+
"parser_package_version": package_version,
|
|
46
|
+
"python_implementation": platform.python_implementation(),
|
|
47
|
+
"python_version": list(platform.python_version_tuple()[:2]),
|
|
48
|
+
"provider_settings": _jsonable(settings) if provider_settings is not None else None,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _jsonable(value: object) -> object:
|
|
53
|
+
model_dump = getattr(value, "model_dump", None)
|
|
54
|
+
if callable(model_dump):
|
|
55
|
+
dump = cast(Callable[..., object], model_dump)
|
|
56
|
+
try:
|
|
57
|
+
return dump(field_mode="backend", dump_format="json")
|
|
58
|
+
except TypeError:
|
|
59
|
+
return dump()
|
|
60
|
+
if isinstance(value, dict):
|
|
61
|
+
return {str(k): _jsonable(v) for k, v in value.items()}
|
|
62
|
+
if isinstance(value, (list, tuple)):
|
|
63
|
+
return [_jsonable(v) for v in value]
|
|
64
|
+
return value
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class WorkflowLLMCallCache:
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
cache_dir: str | Path,
|
|
71
|
+
*,
|
|
72
|
+
probe: WorkflowProbe | None = None,
|
|
73
|
+
namespace: Mapping[str, object] | None = None,
|
|
74
|
+
) -> None:
|
|
75
|
+
self.cache_dir = Path(cache_dir)
|
|
76
|
+
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
|
77
|
+
self.probe = probe
|
|
78
|
+
self.namespace = dict(namespace or workflow_cache_namespace())
|
|
79
|
+
|
|
80
|
+
def _cache_path(self, operation: str, fingerprint: Mapping[str, object]) -> Path:
|
|
81
|
+
payload = json.dumps(
|
|
82
|
+
_jsonable({"namespace": self.namespace, "request": fingerprint}),
|
|
83
|
+
sort_keys=True,
|
|
84
|
+
ensure_ascii=False,
|
|
85
|
+
separators=(",", ":"),
|
|
86
|
+
)
|
|
87
|
+
cache_id = stable_id("workflow_ingest.llm_call", operation, payload)
|
|
88
|
+
return self.cache_dir / f"{cache_id}.json"
|
|
89
|
+
|
|
90
|
+
def cached_call(
|
|
91
|
+
self,
|
|
92
|
+
*,
|
|
93
|
+
operation: str,
|
|
94
|
+
fingerprint: Mapping[str, object],
|
|
95
|
+
fn: Callable[[], T],
|
|
96
|
+
) -> T:
|
|
97
|
+
path = self._cache_path(operation, fingerprint)
|
|
98
|
+
if path.exists():
|
|
99
|
+
try:
|
|
100
|
+
cached = json.loads(path.read_text(encoding="utf-8"))
|
|
101
|
+
except (OSError, json.JSONDecodeError):
|
|
102
|
+
# A cache entry is an optimization, not parser state. A
|
|
103
|
+
# truncated or unreadable entry must not abort ingestion.
|
|
104
|
+
try:
|
|
105
|
+
path.unlink(missing_ok=True)
|
|
106
|
+
except OSError:
|
|
107
|
+
pass
|
|
108
|
+
else:
|
|
109
|
+
emit_probe_event(
|
|
110
|
+
self.probe,
|
|
111
|
+
"workflow.llm_cache_hit",
|
|
112
|
+
operation=operation,
|
|
113
|
+
cache_path=str(path),
|
|
114
|
+
)
|
|
115
|
+
return cast(T, cached)
|
|
116
|
+
result = fn()
|
|
117
|
+
payload = _jsonable(result)
|
|
118
|
+
serialized = json.dumps(payload, ensure_ascii=False, indent=2)
|
|
119
|
+
temporary_path: Path | None = None
|
|
120
|
+
try:
|
|
121
|
+
# Windows can reject simultaneous replacements of the same target
|
|
122
|
+
# even when each writer uses a distinct temporary file. Serialize
|
|
123
|
+
# writers in-process, then publish with one atomic replacement.
|
|
124
|
+
with _CACHE_WRITE_LOCK:
|
|
125
|
+
with tempfile.NamedTemporaryFile(
|
|
126
|
+
mode="w",
|
|
127
|
+
encoding="utf-8",
|
|
128
|
+
dir=self.cache_dir,
|
|
129
|
+
prefix=f".{path.stem}.",
|
|
130
|
+
suffix=".tmp",
|
|
131
|
+
delete=False,
|
|
132
|
+
) as temporary:
|
|
133
|
+
temporary.write(serialized)
|
|
134
|
+
temporary.flush()
|
|
135
|
+
os.fsync(temporary.fileno())
|
|
136
|
+
temporary_path = Path(temporary.name)
|
|
137
|
+
os.replace(temporary_path, path)
|
|
138
|
+
finally:
|
|
139
|
+
if temporary_path is not None:
|
|
140
|
+
try:
|
|
141
|
+
temporary_path.unlink(missing_ok=True)
|
|
142
|
+
except OSError:
|
|
143
|
+
pass
|
|
144
|
+
emit_probe_event(
|
|
145
|
+
self.probe,
|
|
146
|
+
"workflow.llm_cache_miss",
|
|
147
|
+
operation=operation,
|
|
148
|
+
cache_path=str(path),
|
|
149
|
+
)
|
|
150
|
+
return cast(T, payload)
|
|
@@ -28,7 +28,7 @@ from pathlib import Path
|
|
|
28
28
|
from types import TracebackType
|
|
29
29
|
from typing import Literal, Protocol
|
|
30
30
|
|
|
31
|
-
from .cache import WorkflowLLMCallCache
|
|
31
|
+
from .cache import WorkflowLLMCallCache, workflow_cache_namespace
|
|
32
32
|
from .clients import (
|
|
33
33
|
DocumentTreeApiPersistenceClient,
|
|
34
34
|
HttpClientLike,
|
|
@@ -394,6 +394,7 @@ def run_demo_harness(config: DemoHarnessConfig) -> DemoHarnessArtifacts:
|
|
|
394
394
|
"""Run the ingest demo and persist probe and summary artifacts."""
|
|
395
395
|
output_dir = Path(config.output_dir)
|
|
396
396
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
397
|
+
effective_provider_settings = config.provider_settings or WorkflowProviderSettings.from_env()
|
|
397
398
|
probe = WorkflowProbe(output_dir / config.probe_filename)
|
|
398
399
|
if config.enable_sys_monitoring:
|
|
399
400
|
probe.enable_sys_monitoring()
|
|
@@ -414,7 +415,12 @@ def run_demo_harness(config: DemoHarnessConfig) -> DemoHarnessArtifacts:
|
|
|
414
415
|
)
|
|
415
416
|
|
|
416
417
|
deps = dict(config.deps)
|
|
417
|
-
deps["llm_cache"] = WorkflowLLMCallCache(
|
|
418
|
+
deps["llm_cache"] = WorkflowLLMCallCache(
|
|
419
|
+
artifacts.cache_dir,
|
|
420
|
+
probe=probe,
|
|
421
|
+
namespace=workflow_cache_namespace(effective_provider_settings),
|
|
422
|
+
)
|
|
423
|
+
deps.setdefault("provider_settings", effective_provider_settings)
|
|
418
424
|
if config.parser_mode == "fake_layered":
|
|
419
425
|
deps.update(_fake_layered_deps(inp))
|
|
420
426
|
else:
|
|
@@ -457,7 +463,7 @@ def run_demo_harness(config: DemoHarnessConfig) -> DemoHarnessArtifacts:
|
|
|
457
463
|
workflow_engine, conversation_engine, knowledge_engine = build_default_engines(
|
|
458
464
|
artifacts.engine_dir,
|
|
459
465
|
backend_factory=config.backend_factory,
|
|
460
|
-
provider_settings=
|
|
466
|
+
provider_settings=effective_provider_settings,
|
|
461
467
|
)
|
|
462
468
|
engines = (workflow_engine, conversation_engine, knowledge_engine)
|
|
463
469
|
persistence_client = DocumentTreeApiPersistenceClient(
|
|
@@ -491,7 +497,7 @@ def run_demo_harness(config: DemoHarnessConfig) -> DemoHarnessArtifacts:
|
|
|
491
497
|
"cache_dir": str(artifacts.cache_dir),
|
|
492
498
|
"engine_dir": str(artifacts.engine_dir),
|
|
493
499
|
"server_data_dir": str(artifacts.server_data_dir),
|
|
494
|
-
"proposal_mode":
|
|
500
|
+
"proposal_mode": effective_provider_settings.proposal_mode,
|
|
495
501
|
"parser_mode": config.parser_mode,
|
|
496
502
|
"server_mode": config.server_mode,
|
|
497
503
|
}
|
|
@@ -21,7 +21,7 @@ from .adapters import (
|
|
|
21
21
|
build_parser_source_map,
|
|
22
22
|
select_primary_collection,
|
|
23
23
|
)
|
|
24
|
-
from .cache import WorkflowLLMCallCache
|
|
24
|
+
from .cache import WorkflowLLMCallCache, workflow_cache_namespace
|
|
25
25
|
from .clients import CanonicalGraphPersistenceClient
|
|
26
26
|
from .models import (
|
|
27
27
|
CanonicalGraphWriteResult,
|
|
@@ -767,6 +767,7 @@ def register_layerwise_parser_steps(
|
|
|
767
767
|
semantic_tree=semantic_tree,
|
|
768
768
|
propose_layer_fn=runtime_deps.get("propose_layer_fn"),
|
|
769
769
|
llm_cache=runtime_deps.get("llm_cache"),
|
|
770
|
+
cache_namespace=workflow_cache_namespace(runtime_deps.get("provider_settings")),
|
|
770
771
|
)
|
|
771
772
|
with ctx.state_write as st:
|
|
772
773
|
st["current_layer_result"] = result.model_dump(field_mode="backend", dump_format="json")
|
|
@@ -784,6 +785,7 @@ def register_layerwise_parser_steps(
|
|
|
784
785
|
parser_source_map=_parser_source_map(ctx.state_view["parser_source_map"]),
|
|
785
786
|
review_layer_fn=runtime_deps.get("review_layer_fn"),
|
|
786
787
|
llm_cache=runtime_deps.get("llm_cache"),
|
|
788
|
+
cache_namespace=workflow_cache_namespace(runtime_deps.get("provider_settings")),
|
|
787
789
|
)
|
|
788
790
|
updated_context = current_layer_context.model_copy(
|
|
789
791
|
update={"retry_count": current_layer_context.retry_count + 1}
|
|
@@ -803,6 +803,7 @@ def propose_layer_breakdown(
|
|
|
803
803
|
semantic_tree: SemanticNode,
|
|
804
804
|
propose_layer_fn: ProposeLayerFn | None = None,
|
|
805
805
|
llm_cache: WorkflowLLMCallCache | None = None,
|
|
806
|
+
cache_namespace: Mapping[str, object] | None = None,
|
|
806
807
|
) -> CurrentLayerResult:
|
|
807
808
|
_assert_source_map_matches_session(
|
|
808
809
|
parse_session=parse_session,
|
|
@@ -829,6 +830,7 @@ def propose_layer_breakdown(
|
|
|
829
830
|
proposed = llm_cache.cached_call(
|
|
830
831
|
operation="propose_layer_breakdown",
|
|
831
832
|
fingerprint={
|
|
833
|
+
"cache_namespace": dict(cache_namespace or {}),
|
|
832
834
|
"collection_id": collection.collection_id,
|
|
833
835
|
"parse_session": parse_session,
|
|
834
836
|
"current_layer_context": current_layer_context,
|
|
@@ -857,6 +859,7 @@ def review_layer(
|
|
|
857
859
|
parser_source_map: ParserSourceMap | None = None,
|
|
858
860
|
review_layer_fn: ReviewLayerFn | None = None,
|
|
859
861
|
llm_cache: WorkflowLLMCallCache | None = None,
|
|
862
|
+
cache_namespace: Mapping[str, object] | None = None,
|
|
860
863
|
) -> tuple[CurrentLayerReview, ParseSessionState]:
|
|
861
864
|
if parser_source_map is not None:
|
|
862
865
|
_assert_source_map_matches_session(
|
|
@@ -909,6 +912,7 @@ def review_layer(
|
|
|
909
912
|
reviewed = llm_cache.cached_call(
|
|
910
913
|
operation=f"review_cud_proposal:{current_layer_context.split_strategy}",
|
|
911
914
|
fingerprint={
|
|
915
|
+
"cache_namespace": dict(cache_namespace or {}),
|
|
912
916
|
"parse_session": parse_session,
|
|
913
917
|
"current_layer_context": current_layer_context,
|
|
914
918
|
"current_layer_result": current_layer_result,
|
|
@@ -1030,7 +1030,13 @@ def build_chat_model(
|
|
|
1030
1030
|
if spec.provider == "codex":
|
|
1031
1031
|
if not spec.base_url or not spec.api_key_env or not os.getenv(spec.api_key_env):
|
|
1032
1032
|
raise ValueError("codex provider requires base_url and a configured api_key_env token")
|
|
1033
|
-
|
|
1033
|
+
# Keep the transport deadline inside the parser's caller deadline. The
|
|
1034
|
+
# outer timeout cannot stop a daemon thread, so allowing the bridge to
|
|
1035
|
+
# run longer would retain an in-flight slot after the parser gives up.
|
|
1036
|
+
configured_timeout = float(
|
|
1037
|
+
os.getenv("KOGWISTAR_MAINTENANCE_CODEX_TIMEOUT_SECONDS", str(spec.timeout_seconds))
|
|
1038
|
+
)
|
|
1039
|
+
timeout = min(spec.timeout_seconds, configured_timeout)
|
|
1034
1040
|
return StructuredBridgeChatModel(
|
|
1035
1041
|
endpoint=spec.base_url,
|
|
1036
1042
|
token=os.environ[spec.api_key_env],
|
|
@@ -1046,6 +1052,7 @@ def build_chat_model(
|
|
|
1046
1052
|
"temperature": spec.temperature,
|
|
1047
1053
|
"callbacks": callback_list,
|
|
1048
1054
|
"max_retries": spec.max_retries,
|
|
1055
|
+
"request_timeout": spec.timeout_seconds,
|
|
1049
1056
|
}
|
|
1050
1057
|
if spec.max_output_tokens is not None:
|
|
1051
1058
|
kwargs["max_output_tokens"] = spec.max_output_tokens
|
|
@@ -1065,6 +1072,7 @@ def build_chat_model(
|
|
|
1065
1072
|
"temperature": _chat_temperature_for_model(spec.model, spec.temperature),
|
|
1066
1073
|
"callbacks": callback_list,
|
|
1067
1074
|
"max_retries": spec.max_retries,
|
|
1075
|
+
"timeout": spec.timeout_seconds,
|
|
1068
1076
|
}
|
|
1069
1077
|
if max_output_tokens is not None:
|
|
1070
1078
|
kwargs["max_tokens"] = max_output_tokens
|
|
@@ -1088,6 +1096,7 @@ def build_chat_model(
|
|
|
1088
1096
|
"temperature": _chat_temperature_for_model(spec.model, spec.temperature),
|
|
1089
1097
|
"callbacks": callback_list,
|
|
1090
1098
|
"max_retries": spec.max_retries,
|
|
1099
|
+
"timeout": spec.timeout_seconds,
|
|
1091
1100
|
}
|
|
1092
1101
|
if max_output_tokens is not None:
|
|
1093
1102
|
kwargs["max_tokens"] = max_output_tokens
|
|
@@ -1117,6 +1126,7 @@ def build_chat_model(
|
|
|
1117
1126
|
"temperature": spec.temperature,
|
|
1118
1127
|
"callbacks": callback_list,
|
|
1119
1128
|
"max_retries": spec.max_retries,
|
|
1129
|
+
"timeout": spec.timeout_seconds,
|
|
1120
1130
|
}
|
|
1121
1131
|
if spec.max_output_tokens is not None:
|
|
1122
1132
|
kwargs["max_tokens"] = spec.max_output_tokens
|
|
@@ -1132,6 +1142,7 @@ def build_chat_model(
|
|
|
1132
1142
|
"model": spec.model,
|
|
1133
1143
|
"temperature": _chat_temperature_for_model(spec.model, spec.temperature),
|
|
1134
1144
|
"callbacks": callback_list,
|
|
1145
|
+
"client_kwargs": {"timeout": spec.timeout_seconds},
|
|
1135
1146
|
}
|
|
1136
1147
|
if spec.max_output_tokens is not None:
|
|
1137
1148
|
kwargs["num_predict"] = spec.max_output_tokens
|
|
@@ -1148,6 +1159,7 @@ def build_chat_model(
|
|
|
1148
1159
|
"temperature": _chat_temperature_for_model(spec.model, spec.temperature),
|
|
1149
1160
|
"callbacks": callback_list,
|
|
1150
1161
|
"max_retries": spec.max_retries,
|
|
1162
|
+
"request_timeout": spec.timeout_seconds,
|
|
1151
1163
|
}
|
|
1152
1164
|
if spec.max_output_tokens is not None:
|
|
1153
1165
|
kwargs["max_output_tokens"] = spec.max_output_tokens
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "graph-knowledge-doc-parser"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.11"
|
|
4
4
|
description = "doc parser using llm driven engine with graph knowledge awareness"
|
|
5
5
|
authors = ["humblemat810 <67593116+humblemat810@users.noreply.github.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from collections.abc import Callable, Mapping
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from typing import TypeVar, cast
|
|
7
|
-
|
|
8
|
-
from kogwistar.id_provider import stable_id
|
|
9
|
-
|
|
10
|
-
from .probe import WorkflowProbe, emit_probe_event
|
|
11
|
-
|
|
12
|
-
T = TypeVar("T")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def _jsonable(value: object) -> object:
|
|
16
|
-
model_dump = getattr(value, "model_dump", None)
|
|
17
|
-
if callable(model_dump):
|
|
18
|
-
dump = cast(Callable[..., object], model_dump)
|
|
19
|
-
try:
|
|
20
|
-
return dump(field_mode="backend", dump_format="json")
|
|
21
|
-
except TypeError:
|
|
22
|
-
return dump()
|
|
23
|
-
if isinstance(value, dict):
|
|
24
|
-
return {str(k): _jsonable(v) for k, v in value.items()}
|
|
25
|
-
if isinstance(value, (list, tuple)):
|
|
26
|
-
return [_jsonable(v) for v in value]
|
|
27
|
-
return value
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class WorkflowLLMCallCache:
|
|
31
|
-
def __init__(self, cache_dir: str | Path, *, probe: WorkflowProbe | None = None) -> None:
|
|
32
|
-
self.cache_dir = Path(cache_dir)
|
|
33
|
-
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
|
34
|
-
self.probe = probe
|
|
35
|
-
|
|
36
|
-
def _cache_path(self, operation: str, fingerprint: Mapping[str, object]) -> Path:
|
|
37
|
-
payload = json.dumps(_jsonable(fingerprint), sort_keys=True, ensure_ascii=False, separators=(",", ":"))
|
|
38
|
-
cache_id = stable_id("workflow_ingest.llm_call", operation, payload)
|
|
39
|
-
return self.cache_dir / f"{cache_id}.json"
|
|
40
|
-
|
|
41
|
-
def cached_call(
|
|
42
|
-
self,
|
|
43
|
-
*,
|
|
44
|
-
operation: str,
|
|
45
|
-
fingerprint: Mapping[str, object],
|
|
46
|
-
fn: Callable[[], T],
|
|
47
|
-
) -> T:
|
|
48
|
-
path = self._cache_path(operation, fingerprint)
|
|
49
|
-
if path.exists():
|
|
50
|
-
try:
|
|
51
|
-
cached = json.loads(path.read_text(encoding="utf-8"))
|
|
52
|
-
except (OSError, json.JSONDecodeError):
|
|
53
|
-
# A cache entry is an optimization, not parser state. A
|
|
54
|
-
# truncated or unreadable entry must not abort ingestion.
|
|
55
|
-
try:
|
|
56
|
-
path.unlink(missing_ok=True)
|
|
57
|
-
except OSError:
|
|
58
|
-
pass
|
|
59
|
-
else:
|
|
60
|
-
emit_probe_event(
|
|
61
|
-
self.probe,
|
|
62
|
-
"workflow.llm_cache_hit",
|
|
63
|
-
operation=operation,
|
|
64
|
-
cache_path=str(path),
|
|
65
|
-
)
|
|
66
|
-
return cast(T, cached)
|
|
67
|
-
result = fn()
|
|
68
|
-
payload = _jsonable(result)
|
|
69
|
-
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
70
|
-
emit_probe_event(
|
|
71
|
-
self.probe,
|
|
72
|
-
"workflow.llm_cache_miss",
|
|
73
|
-
operation=operation,
|
|
74
|
-
cache_path=str(path),
|
|
75
|
-
)
|
|
76
|
-
return cast(T, payload)
|
{graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/models.py
RENAMED
|
File without changes
|
{graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/ocr.py
RENAMED
|
File without changes
|
{graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/pdf2png.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graph_knowledge_doc_parser-0.2.10 → graph_knowledge_doc_parser-0.2.11}/kg_doc_parser/utils/log.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|