biblicus 0.2.0__py3-none-any.whl → 0.4.0__py3-none-any.whl
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.
- biblicus/__init__.py +2 -2
- biblicus/_vendor/dotyaml/__init__.py +14 -0
- biblicus/_vendor/dotyaml/interpolation.py +63 -0
- biblicus/_vendor/dotyaml/loader.py +181 -0
- biblicus/_vendor/dotyaml/transformer.py +135 -0
- biblicus/backends/__init__.py +0 -2
- biblicus/backends/base.py +3 -3
- biblicus/backends/scan.py +21 -15
- biblicus/backends/sqlite_full_text_search.py +14 -15
- biblicus/cli.py +177 -53
- biblicus/corpus.py +209 -59
- biblicus/crawl.py +186 -0
- biblicus/errors.py +15 -0
- biblicus/evaluation.py +4 -8
- biblicus/extraction.py +280 -79
- biblicus/extractors/__init__.py +14 -3
- biblicus/extractors/base.py +12 -5
- biblicus/extractors/metadata_text.py +13 -5
- biblicus/extractors/openai_stt.py +180 -0
- biblicus/extractors/pass_through_text.py +16 -6
- biblicus/extractors/pdf_text.py +100 -0
- biblicus/extractors/pipeline.py +105 -0
- biblicus/extractors/rapidocr_text.py +129 -0
- biblicus/extractors/select_longest_text.py +105 -0
- biblicus/extractors/select_text.py +100 -0
- biblicus/extractors/unstructured_text.py +100 -0
- biblicus/frontmatter.py +0 -3
- biblicus/hook_logging.py +0 -5
- biblicus/hook_manager.py +3 -5
- biblicus/hooks.py +3 -7
- biblicus/ignore.py +0 -3
- biblicus/models.py +118 -0
- biblicus/retrieval.py +0 -4
- biblicus/sources.py +44 -9
- biblicus/time.py +1 -2
- biblicus/uris.py +3 -4
- biblicus/user_config.py +138 -0
- {biblicus-0.2.0.dist-info → biblicus-0.4.0.dist-info}/METADATA +96 -18
- biblicus-0.4.0.dist-info/RECORD +45 -0
- biblicus/extractors/cascade.py +0 -101
- biblicus-0.2.0.dist-info/RECORD +0 -32
- {biblicus-0.2.0.dist-info → biblicus-0.4.0.dist-info}/WHEEL +0 -0
- {biblicus-0.2.0.dist-info → biblicus-0.4.0.dist-info}/entry_points.txt +0 -0
- {biblicus-0.2.0.dist-info → biblicus-0.4.0.dist-info}/licenses/LICENSE +0 -0
- {biblicus-0.2.0.dist-info → biblicus-0.4.0.dist-info}/top_level.txt +0 -0
biblicus/uris.py
CHANGED
|
@@ -18,7 +18,6 @@ def _looks_like_uri(value: str) -> bool:
|
|
|
18
18
|
:return: True if the string has a valid uniform resource identifier scheme prefix.
|
|
19
19
|
:rtype: bool
|
|
20
20
|
"""
|
|
21
|
-
|
|
22
21
|
return "://" in value and value.split("://", 1)[0].isidentifier()
|
|
23
22
|
|
|
24
23
|
|
|
@@ -33,7 +32,6 @@ def corpus_ref_to_path(ref: Union[str, Path]) -> Path:
|
|
|
33
32
|
:raises NotImplementedError: If a non-file uniform resource identifier scheme is used.
|
|
34
33
|
:raises ValueError: If a file:// uniform resource identifier has a non-local host.
|
|
35
34
|
"""
|
|
36
|
-
|
|
37
35
|
if isinstance(ref, Path):
|
|
38
36
|
return ref.resolve()
|
|
39
37
|
|
|
@@ -45,7 +43,9 @@ def corpus_ref_to_path(ref: Union[str, Path]) -> Path:
|
|
|
45
43
|
f"(got {parsed.scheme}://)"
|
|
46
44
|
)
|
|
47
45
|
if parsed.netloc not in ("", "localhost"):
|
|
48
|
-
raise ValueError(
|
|
46
|
+
raise ValueError(
|
|
47
|
+
f"Unsupported file uniform resource identifier host: {parsed.netloc!r}"
|
|
48
|
+
)
|
|
49
49
|
return Path(unquote(parsed.path)).resolve()
|
|
50
50
|
|
|
51
51
|
return Path(ref).resolve()
|
|
@@ -60,5 +60,4 @@ def normalize_corpus_uri(ref: Union[str, Path]) -> str:
|
|
|
60
60
|
:return: Canonical file:// uniform resource identifier.
|
|
61
61
|
:rtype: str
|
|
62
62
|
"""
|
|
63
|
-
|
|
64
63
|
return corpus_ref_to_path(ref).as_uri()
|
biblicus/user_config.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""
|
|
2
|
+
User configuration file loading for Biblicus.
|
|
3
|
+
|
|
4
|
+
User configuration is intended for small, local settings such as credentials for optional
|
|
5
|
+
integrations. It is separate from corpus configuration.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Dict, Optional
|
|
13
|
+
|
|
14
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
15
|
+
|
|
16
|
+
from ._vendor.dotyaml import ConfigLoader
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OpenAiUserConfig(BaseModel):
|
|
20
|
+
"""
|
|
21
|
+
Configuration for OpenAI integrations.
|
|
22
|
+
|
|
23
|
+
:ivar api_key: OpenAI API key used for authenticated requests.
|
|
24
|
+
:vartype api_key: str
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
model_config = ConfigDict(extra="forbid")
|
|
28
|
+
|
|
29
|
+
api_key: str = Field(min_length=1)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class BiblicusUserConfig(BaseModel):
|
|
33
|
+
"""
|
|
34
|
+
Parsed user configuration for Biblicus.
|
|
35
|
+
|
|
36
|
+
:ivar openai: Optional OpenAI configuration.
|
|
37
|
+
:vartype openai: OpenAiUserConfig or None
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
model_config = ConfigDict(extra="forbid")
|
|
41
|
+
|
|
42
|
+
openai: Optional[OpenAiUserConfig] = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def default_user_config_paths(
|
|
46
|
+
*, cwd: Optional[Path] = None, home: Optional[Path] = None
|
|
47
|
+
) -> list[Path]:
|
|
48
|
+
"""
|
|
49
|
+
Compute the default user configuration file search paths.
|
|
50
|
+
|
|
51
|
+
The search order is:
|
|
52
|
+
|
|
53
|
+
1. Home configuration: ``~/.biblicus/config.yml``
|
|
54
|
+
2. Local configuration: ``./.biblicus/config.yml``
|
|
55
|
+
|
|
56
|
+
Local configuration overrides home configuration when both exist.
|
|
57
|
+
|
|
58
|
+
:param cwd: Optional working directory to use instead of the process current directory.
|
|
59
|
+
:type cwd: Path or None
|
|
60
|
+
:param home: Optional home directory to use instead of the current user's home directory.
|
|
61
|
+
:type home: Path or None
|
|
62
|
+
:return: Ordered list of configuration file paths.
|
|
63
|
+
:rtype: list[Path]
|
|
64
|
+
"""
|
|
65
|
+
resolved_home = (home or Path.home()).expanduser()
|
|
66
|
+
resolved_cwd = cwd or Path.cwd()
|
|
67
|
+
return [
|
|
68
|
+
resolved_home / ".biblicus" / "config.yml",
|
|
69
|
+
resolved_cwd / ".biblicus" / "config.yml",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _deep_merge(base: Dict[str, Any], override: Dict[str, Any]) -> Dict[str, Any]:
|
|
74
|
+
merged: Dict[str, Any] = {key: value for key, value in base.items()}
|
|
75
|
+
for key, value in override.items():
|
|
76
|
+
if key in merged and isinstance(merged[key], dict) and isinstance(value, dict):
|
|
77
|
+
merged[key] = _deep_merge(merged[key], value)
|
|
78
|
+
else:
|
|
79
|
+
merged[key] = value
|
|
80
|
+
return merged
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _load_dotyaml_data(path: Path) -> Dict[str, Any]:
|
|
84
|
+
"""
|
|
85
|
+
Load a dotyaml configuration file and return a nested mapping.
|
|
86
|
+
|
|
87
|
+
:param path: Configuration file path.
|
|
88
|
+
:type path: Path
|
|
89
|
+
:return: Parsed YAML data mapping.
|
|
90
|
+
:rtype: dict[str, Any]
|
|
91
|
+
"""
|
|
92
|
+
loader = ConfigLoader(prefix="", load_dotenv_first=False)
|
|
93
|
+
loaded = loader.load_from_yaml(path)
|
|
94
|
+
return loaded if isinstance(loaded, dict) else {}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def load_user_config(*, paths: Optional[list[Path]] = None) -> BiblicusUserConfig:
|
|
98
|
+
"""
|
|
99
|
+
Load user configuration from known locations.
|
|
100
|
+
|
|
101
|
+
This function merges multiple configuration files in order. Later files override earlier files.
|
|
102
|
+
|
|
103
|
+
:param paths: Optional explicit search paths. When omitted, the default paths are used.
|
|
104
|
+
:type paths: list[Path] or None
|
|
105
|
+
:return: Parsed user configuration. When no files exist, the configuration is empty.
|
|
106
|
+
:rtype: BiblicusUserConfig
|
|
107
|
+
:raises ValueError: If an existing configuration file is not parseable.
|
|
108
|
+
"""
|
|
109
|
+
search_paths = paths or default_user_config_paths()
|
|
110
|
+
merged_data: Dict[str, Any] = {}
|
|
111
|
+
|
|
112
|
+
for path in search_paths:
|
|
113
|
+
if not path.is_file():
|
|
114
|
+
continue
|
|
115
|
+
loaded = _load_dotyaml_data(path)
|
|
116
|
+
merged_data = _deep_merge(merged_data, loaded)
|
|
117
|
+
|
|
118
|
+
return BiblicusUserConfig.model_validate(merged_data)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def resolve_openai_api_key(*, config: Optional[BiblicusUserConfig] = None) -> Optional[str]:
|
|
122
|
+
"""
|
|
123
|
+
Resolve an OpenAI API key from environment or user configuration.
|
|
124
|
+
|
|
125
|
+
Environment takes precedence over configuration.
|
|
126
|
+
|
|
127
|
+
:param config: Optional pre-loaded user configuration.
|
|
128
|
+
:type config: BiblicusUserConfig or None
|
|
129
|
+
:return: API key string, or None when no key is available.
|
|
130
|
+
:rtype: str or None
|
|
131
|
+
"""
|
|
132
|
+
env_key = os.environ.get("OPENAI_API_KEY")
|
|
133
|
+
if env_key:
|
|
134
|
+
return env_key
|
|
135
|
+
loaded = config or load_user_config()
|
|
136
|
+
if loaded.openai is None:
|
|
137
|
+
return None
|
|
138
|
+
return loaded.openai.api_key
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: biblicus
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Command line interface and Python library for corpus ingestion, retrieval, and evaluation.
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -8,20 +8,30 @@ Description-Content-Type: text/markdown
|
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Dist: pydantic>=2.0
|
|
10
10
|
Requires-Dist: PyYAML>=6.0
|
|
11
|
+
Requires-Dist: pypdf>=4.0
|
|
11
12
|
Provides-Extra: dev
|
|
12
13
|
Requires-Dist: behave>=1.2.6; extra == "dev"
|
|
13
14
|
Requires-Dist: coverage[toml]>=7.0; extra == "dev"
|
|
14
15
|
Requires-Dist: sphinx>=7.0; extra == "dev"
|
|
15
16
|
Requires-Dist: myst-parser>=2.0; extra == "dev"
|
|
17
|
+
Requires-Dist: sphinx_rtd_theme>=2.0; extra == "dev"
|
|
16
18
|
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
17
19
|
Requires-Dist: black>=24.0; extra == "dev"
|
|
18
20
|
Requires-Dist: python-semantic-release>=9.0.0; extra == "dev"
|
|
21
|
+
Provides-Extra: openai
|
|
22
|
+
Requires-Dist: openai>=1.0; extra == "openai"
|
|
23
|
+
Provides-Extra: unstructured
|
|
24
|
+
Requires-Dist: unstructured>=0.12.0; extra == "unstructured"
|
|
25
|
+
Requires-Dist: python-docx>=1.1.0; extra == "unstructured"
|
|
26
|
+
Provides-Extra: ocr
|
|
27
|
+
Requires-Dist: rapidocr-onnxruntime>=1.3.0; extra == "ocr"
|
|
19
28
|
Dynamic: license-file
|
|
20
29
|
|
|
21
30
|
# Biblicus
|
|
22
31
|
|
|
23
32
|
![Continuous integration][continuous-integration-badge]
|
|
24
33
|
![Coverage][coverage-badge]
|
|
34
|
+
![Documentation][documentation-badge]
|
|
25
35
|
|
|
26
36
|
Make your documents usable by your assistant, then decide later how you will search and retrieve them.
|
|
27
37
|
|
|
@@ -31,28 +41,34 @@ The first practical problem is not retrieval. It is collection and care. You nee
|
|
|
31
41
|
|
|
32
42
|
This library gives you a corpus, which is a normal folder on disk. It stores each ingested item as a file, with optional metadata stored next to it. You can open and inspect the raw files directly. Any derived catalog or index can be rebuilt from the raw corpus.
|
|
33
43
|
|
|
34
|
-
It
|
|
44
|
+
It can be used alongside LangChain, Tactus, Pydantic AI, or the agent development kit. Use it from Python or from the command line interface.
|
|
35
45
|
|
|
36
46
|
See [retrieval augmented generation overview] for a short introduction to the idea.
|
|
37
47
|
|
|
38
|
-
##
|
|
48
|
+
## A beginner friendly mental model
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
Think in three stages.
|
|
51
|
+
|
|
52
|
+
- Ingest puts raw items into a corpus. This is file first and human inspectable.
|
|
53
|
+
- Extract turns items into usable text. This is where you would do text extraction from Portable Document Format files, optical character recognition for images, or speech to text for audio. If an item is already text, extraction can simply read it. Extraction outputs are derived artifacts, not edits to the raw files.
|
|
54
|
+
- Retrieve searches extracted text and returns evidence. Evidence is structured so you can turn it into context for your model call in whatever way your project prefers.
|
|
55
|
+
|
|
56
|
+
If you learn a few project words, the rest of the system becomes predictable.
|
|
41
57
|
|
|
42
58
|
- Corpus is the folder that holds raw items and their metadata.
|
|
43
|
-
- Item is the raw bytes
|
|
59
|
+
- Item is the raw bytes plus optional metadata and source information.
|
|
44
60
|
- Catalog is the rebuildable index of the corpus.
|
|
45
|
-
-
|
|
46
|
-
- Run is a recorded retrieval build for a corpus.
|
|
61
|
+
- Extraction run is a recorded extraction build that produces text artifacts.
|
|
47
62
|
- Backend is a pluggable retrieval implementation.
|
|
48
|
-
-
|
|
49
|
-
-
|
|
63
|
+
- Run is a recorded retrieval build for a corpus.
|
|
64
|
+
- Evidence is what retrieval returns, with identifiers and source information.
|
|
50
65
|
|
|
51
66
|
## Diagram
|
|
52
67
|
|
|
53
68
|
This diagram shows how a corpus becomes evidence for an assistant.
|
|
54
|
-
|
|
55
|
-
The
|
|
69
|
+
Extraction is introduced here as a separate stage so you can swap extraction approaches without changing the raw corpus.
|
|
70
|
+
The legend shows what the block styles mean.
|
|
71
|
+
Your code is where you decide how to turn evidence into context and how to call a model.
|
|
56
72
|
|
|
57
73
|
```mermaid
|
|
58
74
|
%%{init: {"flowchart": {"useMaxWidth": true, "nodeSpacing": 18, "rankSpacing": 22}}}%%
|
|
@@ -74,12 +90,19 @@ flowchart LR
|
|
|
74
90
|
Raw --> Catalog[Catalog file]
|
|
75
91
|
end
|
|
76
92
|
|
|
77
|
-
subgraph
|
|
93
|
+
subgraph PluggableExtractionPipeline[Pluggable: extraction pipeline]
|
|
94
|
+
direction TB
|
|
95
|
+
Catalog --> Extract[Extract pipeline]
|
|
96
|
+
Extract --> ExtractedText[Extracted text artifacts]
|
|
97
|
+
ExtractedText --> ExtractionRun[Extraction run manifest]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
subgraph PluggableRetrievalBackend[Pluggable: retrieval backend]
|
|
78
101
|
direction LR
|
|
79
102
|
|
|
80
103
|
subgraph BackendIngestionIndexing[Ingestion and indexing]
|
|
81
104
|
direction TB
|
|
82
|
-
|
|
105
|
+
ExtractionRun --> Build[Build run]
|
|
83
106
|
Build --> BackendIndex[Backend index]
|
|
84
107
|
BackendIndex --> Run[Run manifest]
|
|
85
108
|
end
|
|
@@ -100,6 +123,7 @@ flowchart LR
|
|
|
100
123
|
end
|
|
101
124
|
|
|
102
125
|
style StableCore fill:#ffffff,stroke:#8e24aa,stroke-width:2px,color:#111111
|
|
126
|
+
style PluggableExtractionPipeline fill:#ffffff,stroke:#5e35b1,stroke-dasharray:6 3,stroke-width:2px,color:#111111
|
|
103
127
|
style PluggableRetrievalBackend fill:#ffffff,stroke:#1e88e5,stroke-dasharray:6 3,stroke-width:2px,color:#111111
|
|
104
128
|
style YourCode fill:#ffffff,stroke:#d81b60,stroke-width:2px,color:#111111
|
|
105
129
|
style BackendIngestionIndexing fill:#ffffff,stroke:#cfd8dc,color:#111111
|
|
@@ -107,6 +131,8 @@ flowchart LR
|
|
|
107
131
|
|
|
108
132
|
style Raw fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
109
133
|
style Catalog fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
134
|
+
style ExtractedText fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
135
|
+
style ExtractionRun fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
110
136
|
style BackendIndex fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
111
137
|
style Run fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
112
138
|
style Evidence fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
@@ -115,6 +141,7 @@ flowchart LR
|
|
|
115
141
|
style Source fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
116
142
|
|
|
117
143
|
style Ingest fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
144
|
+
style Extract fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
118
145
|
style Build fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
119
146
|
style Query fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
120
147
|
style Model fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
@@ -136,6 +163,8 @@ flowchart LR
|
|
|
136
163
|
|
|
137
164
|
- Initialize a corpus folder.
|
|
138
165
|
- Ingest items from file paths, web addresses, or text input.
|
|
166
|
+
- Crawl a website section into corpus items when you want a repeatable “import from the web” workflow.
|
|
167
|
+
- Run extraction when you want derived text artifacts from non-text sources.
|
|
139
168
|
- Reindex to refresh the catalog after edits.
|
|
140
169
|
- Build a retrieval run with a backend.
|
|
141
170
|
- Query the run to collect evidence and evaluate it with datasets.
|
|
@@ -154,17 +183,40 @@ After the first release, you can install it from Python Package Index.
|
|
|
154
183
|
python3 -m pip install biblicus
|
|
155
184
|
```
|
|
156
185
|
|
|
186
|
+
### Optional extras
|
|
187
|
+
|
|
188
|
+
Some extractors are optional so the base install stays small.
|
|
189
|
+
|
|
190
|
+
- Optical character recognition for images: `python3 -m pip install "biblicus[ocr]"`
|
|
191
|
+
- Speech to text transcription: `python3 -m pip install "biblicus[openai]"` (requires an OpenAI API key in `~/.biblicus/config.yml` or `./.biblicus/config.yml`)
|
|
192
|
+
- Broad document parsing fallback: `python3 -m pip install "biblicus[unstructured]"`
|
|
193
|
+
|
|
157
194
|
## Quick start
|
|
158
195
|
|
|
159
196
|
```
|
|
197
|
+
mkdir -p notes
|
|
198
|
+
echo "A small file note" > notes/example.txt
|
|
199
|
+
|
|
160
200
|
biblicus init corpora/example
|
|
161
201
|
biblicus ingest --corpus corpora/example notes/example.txt
|
|
162
202
|
echo "A short note" | biblicus ingest --corpus corpora/example --stdin --title "First note"
|
|
163
203
|
biblicus list --corpus corpora/example
|
|
204
|
+
biblicus extract build --corpus corpora/example --step pass-through-text --step metadata-text
|
|
205
|
+
biblicus extract list --corpus corpora/example
|
|
164
206
|
biblicus build --corpus corpora/example --backend scan
|
|
165
207
|
biblicus query --corpus corpora/example --query "note"
|
|
166
208
|
```
|
|
167
209
|
|
|
210
|
+
If you want to turn a website section into corpus items, crawl a root web address while restricting the crawl to an allowed prefix:
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
biblicus crawl --corpus corpora/example \\
|
|
214
|
+
--root-url https://example.com/docs/index.html \\
|
|
215
|
+
--allowed-prefix https://example.com/docs/ \\
|
|
216
|
+
--max-items 50 \\
|
|
217
|
+
--tag crawled
|
|
218
|
+
```
|
|
219
|
+
|
|
168
220
|
## Python usage
|
|
169
221
|
|
|
170
222
|
From Python, the same flow is available through the Corpus class and backend interfaces. The public surface area is small on purpose.
|
|
@@ -188,13 +240,18 @@ In an assistant system, retrieval usually produces context for a model call. Thi
|
|
|
188
240
|
|
|
189
241
|
## Learn more
|
|
190
242
|
|
|
243
|
+
Full documentation is published on GitHub Pages: https://anthusai.github.io/Biblicus/
|
|
244
|
+
|
|
191
245
|
The documents below are written to be read in order.
|
|
192
246
|
|
|
193
247
|
- [Architecture][architecture]
|
|
248
|
+
- [Roadmap][roadmap]
|
|
249
|
+
- [Feature index][feature-index]
|
|
194
250
|
- [Corpus][corpus]
|
|
195
251
|
- [Text extraction][text-extraction]
|
|
252
|
+
- [User configuration][user-configuration]
|
|
196
253
|
- [Backends][backends]
|
|
197
|
-
- [
|
|
254
|
+
- [Demos][demos]
|
|
198
255
|
- [Testing][testing]
|
|
199
256
|
|
|
200
257
|
## Metadata and catalog
|
|
@@ -212,7 +269,16 @@ corpus/
|
|
|
212
269
|
config.json
|
|
213
270
|
catalog.json
|
|
214
271
|
runs/
|
|
215
|
-
|
|
272
|
+
extraction/
|
|
273
|
+
pipeline/
|
|
274
|
+
<run id>/
|
|
275
|
+
manifest.json
|
|
276
|
+
text/
|
|
277
|
+
<item id>.txt
|
|
278
|
+
retrieval/
|
|
279
|
+
<backend id>/
|
|
280
|
+
<run id>/
|
|
281
|
+
manifest.json
|
|
216
282
|
```
|
|
217
283
|
|
|
218
284
|
## Retrieval backends
|
|
@@ -252,10 +318,18 @@ Publishing uses a Python Package Index token stored in the GitHub secret named P
|
|
|
252
318
|
|
|
253
319
|
## Documentation
|
|
254
320
|
|
|
255
|
-
Reference documentation is generated from Sphinx style docstrings.
|
|
321
|
+
Reference documentation is generated from Sphinx style docstrings.
|
|
322
|
+
|
|
323
|
+
Install development dependencies:
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
python3 -m pip install -e ".[dev]"
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Build the documentation:
|
|
256
330
|
|
|
257
331
|
```
|
|
258
|
-
|
|
332
|
+
python3 -m sphinx -b html docs docs/_build/html
|
|
259
333
|
```
|
|
260
334
|
|
|
261
335
|
## License
|
|
@@ -264,11 +338,15 @@ License terms are in `LICENSE`.
|
|
|
264
338
|
|
|
265
339
|
[retrieval augmented generation overview]: https://en.wikipedia.org/wiki/Retrieval-augmented_generation
|
|
266
340
|
[architecture]: docs/ARCHITECTURE.md
|
|
341
|
+
[roadmap]: docs/ROADMAP.md
|
|
342
|
+
[feature-index]: docs/FEATURE_INDEX.md
|
|
267
343
|
[corpus]: docs/CORPUS.md
|
|
268
344
|
[text-extraction]: docs/EXTRACTION.md
|
|
345
|
+
[user-configuration]: docs/USER_CONFIGURATION.md
|
|
269
346
|
[backends]: docs/BACKENDS.md
|
|
270
|
-
[
|
|
347
|
+
[demos]: docs/DEMOS.md
|
|
271
348
|
[testing]: docs/TESTING.md
|
|
272
349
|
|
|
273
350
|
[continuous-integration-badge]: https://github.com/AnthusAI/Biblicus/actions/workflows/ci.yml/badge.svg?branch=main
|
|
274
351
|
[coverage-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AnthusAI/Biblicus/main/coverage_badge.json
|
|
352
|
+
[documentation-badge]: https://img.shields.io/badge/docs-GitHub%20Pages-blue
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
biblicus/__init__.py,sha256=6TFpzDiMJlFyBfVrHfS6xnGd8P7Zybj6DxpWkCJqyf4,432
|
|
2
|
+
biblicus/__main__.py,sha256=ipfkUoTlocVnrQDM69C7TeBqQxmHVeiWMRaT3G9rtnk,117
|
|
3
|
+
biblicus/cli.py,sha256=MtYTkJh0lVOTrbwY3u6V8ti5WZUsb96fLatqh23cUYg,24289
|
|
4
|
+
biblicus/constants.py,sha256=R6fZDoLVMCwgKvTaxEx7G0CstwHGaUTlW9MsmNLDZ44,269
|
|
5
|
+
biblicus/corpus.py,sha256=gF1RNl6fdz7wplzpHEIkEBkhYxHgKTKguBR_kD9IgUw,54109
|
|
6
|
+
biblicus/crawl.py,sha256=n8rXBMnziBK9vtKQQCXYOpBzqsPCswj2PzVJUb370KY,6250
|
|
7
|
+
biblicus/errors.py,sha256=uMajd5DvgnJ_-jq5sbeom1GV8DPUc-kojBaECFi6CsY,467
|
|
8
|
+
biblicus/evaluation.py,sha256=5xWpb-8f49Osh9aHzo1ab3AXOmls3Imc5rdnEC0pN-8,8143
|
|
9
|
+
biblicus/extraction.py,sha256=VEjBjIpaBboftGgEcpDj7z7um41e5uDZpP_7acQg7fw,19448
|
|
10
|
+
biblicus/frontmatter.py,sha256=JOGjIDzbbOkebQw2RzA-3WDVMAMtJta2INjS4e7-LMg,2463
|
|
11
|
+
biblicus/hook_logging.py,sha256=IMvde-JhVWrx9tNz3eDJ1CY_rr5Sj7DZ2YNomYCZbz0,5366
|
|
12
|
+
biblicus/hook_manager.py,sha256=ZCAkE5wLvn4lnQz8jho_o0HGEC9KdQd9qitkAEUQRcw,6997
|
|
13
|
+
biblicus/hooks.py,sha256=OHQOmOi7rUcQqYWVeod4oPe8nVLepD7F_SlN7O_-BsE,7863
|
|
14
|
+
biblicus/ignore.py,sha256=fyjt34E6tWNNrm1FseOhgH2MgryyVBQVzxhKL5s4aio,1800
|
|
15
|
+
biblicus/models.py,sha256=6SWQ2Czg9O3zjuam8a4m8V3LlEgcGLbEctYDB6F1rRs,15317
|
|
16
|
+
biblicus/retrieval.py,sha256=A1SI4WK5cX-WbtN6FJ0QQxqlEOtQhddLrL0LZIuoTC4,4180
|
|
17
|
+
biblicus/sources.py,sha256=EFy8-rQNLsyzz-98mH-z8gEHMYbqigcNFKLaR92KfDE,7241
|
|
18
|
+
biblicus/time.py,sha256=3BSKOSo7R10K-0Dzrbdtl3fh5_yShTYqfdlKvvdkx7M,485
|
|
19
|
+
biblicus/uris.py,sha256=xXD77lqsT9NxbyzI1spX9Y5a3-U6sLYMnpeSAV7g-nM,2013
|
|
20
|
+
biblicus/user_config.py,sha256=DqO08yLn82DhTiFpmIyyLj_J0nMbrtE8xieTj2Cgd6A,4287
|
|
21
|
+
biblicus/_vendor/dotyaml/__init__.py,sha256=e4zbejeJRwlD4I0q3YvotMypO19lXqmT8iyU1q6SvhY,376
|
|
22
|
+
biblicus/_vendor/dotyaml/interpolation.py,sha256=PfUAEEOTFobv7Ox0E6nAxht6BqhHIDe4hP32fZn5TOs,1992
|
|
23
|
+
biblicus/_vendor/dotyaml/loader.py,sha256=KePkjyhKZSvQZphmlmlzTYZJBQsqL5qhtGV1y7G6wzM,5624
|
|
24
|
+
biblicus/_vendor/dotyaml/transformer.py,sha256=2AKPS8DMOPuYtzmM-dlwIqVbARfbBH5jYV1m5qpR49E,3725
|
|
25
|
+
biblicus/backends/__init__.py,sha256=wLXIumV51l6ZIKzjoKKeU7AgIxGOryG7T7ls3a_Fv98,1212
|
|
26
|
+
biblicus/backends/base.py,sha256=Erfj9dXg0nkRKnEcNjHR9_0Ddb2B1NvbmRksVm_g1dU,1776
|
|
27
|
+
biblicus/backends/scan.py,sha256=hdNnQWqi5IH6j95w30BZHxLJ0W9PTaOkqfWJuxCCEMI,12478
|
|
28
|
+
biblicus/backends/sqlite_full_text_search.py,sha256=KgmwOiKvkA0pv7vD0V7bcOdDx_nZIOfuIN6Z4Ij7I68,16516
|
|
29
|
+
biblicus/extractors/__init__.py,sha256=X3pu18QL85IBpYf56l6_5PUxFPhEN5qLTlOrxYpfGck,1776
|
|
30
|
+
biblicus/extractors/base.py,sha256=ka-nz_1zHPr4TS9sU4JfOoY-PJh7lbHPBOEBrbQFGSc,2171
|
|
31
|
+
biblicus/extractors/metadata_text.py,sha256=7FbEPp0K1mXc7FH1_c0KhPhPexF9U6eLd3TVY1vTp1s,3537
|
|
32
|
+
biblicus/extractors/openai_stt.py,sha256=fggErIu6YN6tXbleNTuROhfYi7zDgMd2vD_ecXZ7eXs,7162
|
|
33
|
+
biblicus/extractors/pass_through_text.py,sha256=DNxkCwpH2bbXjPGPEQwsx8kfqXi6rIxXNY_n3TU2-WI,2777
|
|
34
|
+
biblicus/extractors/pdf_text.py,sha256=YtUphgLVxyWJXew6ZsJ8wBRh67Y5ri4ZTRlMmq3g1Bk,3255
|
|
35
|
+
biblicus/extractors/pipeline.py,sha256=LY6eM3ypw50MDB2cPEQqZrjxkhVvIc6sv4UEhHdNDrE,3208
|
|
36
|
+
biblicus/extractors/rapidocr_text.py,sha256=OMAuZealLSSTFVVmBalT-AFJy2pEpHyyvpuWxlnY-GU,4531
|
|
37
|
+
biblicus/extractors/select_longest_text.py,sha256=wRveXAfYLdj7CpGuo4RoD7zE6SIfylRCbv40z2azO0k,3702
|
|
38
|
+
biblicus/extractors/select_text.py,sha256=w0ATmDy3tWWbOObzW87jGZuHbgXllUhotX5XyySLs-o,3395
|
|
39
|
+
biblicus/extractors/unstructured_text.py,sha256=l2S_wD_htu7ZHoJQNQtP-kGlEgOeKV_w2IzAC93lePE,3564
|
|
40
|
+
biblicus-0.4.0.dist-info/licenses/LICENSE,sha256=lw44GXFG_Q0fS8m5VoEvv_xtdBXK26pBcbSPUCXee_Q,1078
|
|
41
|
+
biblicus-0.4.0.dist-info/METADATA,sha256=JMZjfIOMEmbWFHgzjUHsQDUUg11jdxudtJdRK8Iu29U,13586
|
|
42
|
+
biblicus-0.4.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
43
|
+
biblicus-0.4.0.dist-info/entry_points.txt,sha256=BZmO4H8Uz00fyi1RAFryOCGfZgX7eHWkY2NE-G54U5A,47
|
|
44
|
+
biblicus-0.4.0.dist-info/top_level.txt,sha256=sUD_XVZwDxZ29-FBv1MknTGh4mgDXznGuP28KJY_WKc,9
|
|
45
|
+
biblicus-0.4.0.dist-info/RECORD,,
|
biblicus/extractors/cascade.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Cascade extractor plugin that composes multiple extractors.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
from typing import Any, Dict, List, Optional
|
|
8
|
-
|
|
9
|
-
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
10
|
-
|
|
11
|
-
from ..corpus import Corpus
|
|
12
|
-
from ..models import CatalogItem, ExtractedText
|
|
13
|
-
from .base import TextExtractor
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class CascadeStepSpec(BaseModel):
|
|
17
|
-
"""
|
|
18
|
-
Single extractor step within a cascade pipeline.
|
|
19
|
-
|
|
20
|
-
:ivar extractor_id: Extractor plugin identifier.
|
|
21
|
-
:vartype extractor_id: str
|
|
22
|
-
:ivar config: Extractor configuration mapping.
|
|
23
|
-
:vartype config: dict[str, Any]
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
model_config = ConfigDict(extra="forbid")
|
|
27
|
-
|
|
28
|
-
extractor_id: str = Field(min_length=1)
|
|
29
|
-
config: Dict[str, Any] = Field(default_factory=dict)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class CascadeExtractorConfig(BaseModel):
|
|
33
|
-
"""
|
|
34
|
-
Configuration for the cascade extractor.
|
|
35
|
-
|
|
36
|
-
:ivar steps: Ordered list of extractor steps to try.
|
|
37
|
-
:vartype steps: list[CascadeStepSpec]
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
model_config = ConfigDict(extra="forbid")
|
|
41
|
-
|
|
42
|
-
steps: List[CascadeStepSpec] = Field(min_length=1)
|
|
43
|
-
|
|
44
|
-
@model_validator(mode="after")
|
|
45
|
-
def _forbid_self_reference(self) -> "CascadeExtractorConfig":
|
|
46
|
-
if any(step.extractor_id == "cascade" for step in self.steps):
|
|
47
|
-
raise ValueError("Cascade extractor cannot include itself as a step")
|
|
48
|
-
return self
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class CascadeExtractor(TextExtractor):
|
|
52
|
-
"""
|
|
53
|
-
Extractor that tries a sequence of extractors and uses the first usable text result.
|
|
54
|
-
|
|
55
|
-
A result is considered usable when its text is non-empty after stripping whitespace.
|
|
56
|
-
|
|
57
|
-
:ivar extractor_id: Extractor identifier.
|
|
58
|
-
:vartype extractor_id: str
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
extractor_id = "cascade"
|
|
62
|
-
|
|
63
|
-
def validate_config(self, config: Dict[str, Any]) -> BaseModel:
|
|
64
|
-
"""
|
|
65
|
-
Validate cascade extractor configuration.
|
|
66
|
-
|
|
67
|
-
:param config: Configuration mapping.
|
|
68
|
-
:type config: dict[str, Any]
|
|
69
|
-
:return: Parsed config.
|
|
70
|
-
:rtype: CascadeExtractorConfig
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
return CascadeExtractorConfig.model_validate(config)
|
|
74
|
-
|
|
75
|
-
def extract_text(self, *, corpus: Corpus, item: CatalogItem, config: BaseModel) -> Optional[ExtractedText]:
|
|
76
|
-
"""
|
|
77
|
-
Run each configured extractor step until usable text is produced.
|
|
78
|
-
|
|
79
|
-
:param corpus: Corpus containing the item bytes.
|
|
80
|
-
:type corpus: Corpus
|
|
81
|
-
:param item: Catalog item being processed.
|
|
82
|
-
:type item: CatalogItem
|
|
83
|
-
:param config: Parsed configuration model.
|
|
84
|
-
:type config: CascadeExtractorConfig
|
|
85
|
-
:return: Extracted text payload or None.
|
|
86
|
-
:rtype: ExtractedText or None
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
cascade_config = config if isinstance(config, CascadeExtractorConfig) else CascadeExtractorConfig.model_validate(config)
|
|
90
|
-
for step in cascade_config.steps:
|
|
91
|
-
from . import get_extractor
|
|
92
|
-
|
|
93
|
-
extractor = get_extractor(step.extractor_id)
|
|
94
|
-
parsed_step_config = extractor.validate_config(step.config)
|
|
95
|
-
result = extractor.extract_text(corpus=corpus, item=item, config=parsed_step_config)
|
|
96
|
-
if result is None:
|
|
97
|
-
continue
|
|
98
|
-
if not result.text.strip():
|
|
99
|
-
continue
|
|
100
|
-
return result
|
|
101
|
-
return None
|
biblicus-0.2.0.dist-info/RECORD
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
biblicus/__init__.py,sha256=3IXdbt-q80_BlKDwTsZw7MScRW4hBgQ-Vn6xHbgNwE8,432
|
|
2
|
-
biblicus/__main__.py,sha256=ipfkUoTlocVnrQDM69C7TeBqQxmHVeiWMRaT3G9rtnk,117
|
|
3
|
-
biblicus/cli.py,sha256=zDD6juQGTDmrRE2DHUku-G3wV3AtXjwYTNDFACwpdC0,19501
|
|
4
|
-
biblicus/constants.py,sha256=R6fZDoLVMCwgKvTaxEx7G0CstwHGaUTlW9MsmNLDZ44,269
|
|
5
|
-
biblicus/corpus.py,sha256=5naoFi0GSKBg4RFd6wOU-U30NMbG6bfs_RM90JcvDGA,47460
|
|
6
|
-
biblicus/evaluation.py,sha256=H_W35vF5_L4B2JCfLu19VRu402tZ2pFkN2BbBP69lVY,8119
|
|
7
|
-
biblicus/extraction.py,sha256=WX1LRsKrsyHI4Wido6gMwukzRGf5cfPWvRASgu_MRN4,10614
|
|
8
|
-
biblicus/frontmatter.py,sha256=8Tqlpd3bVzZrGRB9Rdj2IwHMSJLvd2ABxMNOi3L5br4,2466
|
|
9
|
-
biblicus/hook_logging.py,sha256=8Rl3BpkfTexSJ7rFi94kl6DMRDD-8eu2N7zv18wXyUM,5371
|
|
10
|
-
biblicus/hook_manager.py,sha256=ucDZoVM-9fg1gQAhUxi-PECaNlHoegAxb-kYCx-OMZs,6987
|
|
11
|
-
biblicus/hooks.py,sha256=OfG3VsCDWQVVZnOTQHnN9GQ0AIws9SK6-85WYTrKkzk,7847
|
|
12
|
-
biblicus/ignore.py,sha256=Di37CTlg6Mg3SKJc2qxZcZdYX00IcTORB2hb0g-Jins,1803
|
|
13
|
-
biblicus/models.py,sha256=6cgJX7Jmm5rBVrXWH46fQf3v__jSyDy73MnKaUQMSHQ,11099
|
|
14
|
-
biblicus/retrieval.py,sha256=T7HELWCNAxZ26yj7dPH8IBUaxV_gx8Ql9iwwGz0teyI,4184
|
|
15
|
-
biblicus/sources.py,sha256=C4P8oM6d50tLXr4z9Shsv4z-hDiQuylXfkT3Bx03dEM,5844
|
|
16
|
-
biblicus/time.py,sha256=rvp2fJXSLVmyA76GCfNKtZoifASodemJTOWN8smPt0s,486
|
|
17
|
-
biblicus/uris.py,sha256=sRDyGmoHr_H4XR4qv_lSbQJXylYD0fNEr02H5wjomnQ,1986
|
|
18
|
-
biblicus/backends/__init__.py,sha256=5OXKSzsn7THhwh9T5StOvEqojx_85XXuYSGdTpMK11U,1214
|
|
19
|
-
biblicus/backends/base.py,sha256=699TKygGgL72Ifkhz1V890nOK6BslwO0-OY7xeqZl-I,1764
|
|
20
|
-
biblicus/backends/scan.py,sha256=DZ-CgZ0jy6_928hu4dASJ8_JH7BTfF8gwVkVhd38W1U,12421
|
|
21
|
-
biblicus/backends/sqlite_full_text_search.py,sha256=FMpASLeK5diK-Uyhr4pqtpDpb_Qyk5_XRaXAKUHDzjs,16502
|
|
22
|
-
biblicus/extractors/__init__.py,sha256=_6Z_JkLoDYwmay76y1fy11lCSqDDizMDPX3Vke_l8x4,1008
|
|
23
|
-
biblicus/extractors/base.py,sha256=yvp709uUCnPEbK-bx6u5WKNPPH3SBWhbSaewoyUIgvA,1870
|
|
24
|
-
biblicus/extractors/cascade.py,sha256=ExojAYsARtF99zVg78wY_wifVfDaJFa6wiRIaT-cpRo,3209
|
|
25
|
-
biblicus/extractors/metadata_text.py,sha256=C0i8fcEC9aLmwhSdK9IlZVZ9ugOocIe0y522pSjvaCA,3203
|
|
26
|
-
biblicus/extractors/pass_through_text.py,sha256=ngDyI13RpCldP-OzV4q9lBTGPxDL6MDxp7OCo1rORyQ,2421
|
|
27
|
-
biblicus-0.2.0.dist-info/licenses/LICENSE,sha256=lw44GXFG_Q0fS8m5VoEvv_xtdBXK26pBcbSPUCXee_Q,1078
|
|
28
|
-
biblicus-0.2.0.dist-info/METADATA,sha256=nTB344GRVrKuT6oPOrWBpFA_BiG3UAIgq3wCoHEVDgw,10307
|
|
29
|
-
biblicus-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
30
|
-
biblicus-0.2.0.dist-info/entry_points.txt,sha256=BZmO4H8Uz00fyi1RAFryOCGfZgX7eHWkY2NE-G54U5A,47
|
|
31
|
-
biblicus-0.2.0.dist-info/top_level.txt,sha256=sUD_XVZwDxZ29-FBv1MknTGh4mgDXznGuP28KJY_WKc,9
|
|
32
|
-
biblicus-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|