docforge-sdk 0.1.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.
@@ -0,0 +1,100 @@
1
+ # ====== Code Summary ======
2
+ # Response models for the jobs resource, mirrored field-for-field from the DocForge backend router
3
+ # models: the live ingestion status, one node of the execution trace, the full trace, and the live
4
+ # per-worker activity view.
5
+
6
+ # ====== Standard Library Imports ======
7
+ from datetime import datetime
8
+
9
+ # ====== Third-Party Library Imports ======
10
+ from pydantic import BaseModel, Field
11
+
12
+
13
+ class JobStatus(BaseModel):
14
+ """
15
+ One ingestion job's live state — written by the worker, only read here.
16
+
17
+ Attributes:
18
+ job_id (str): The job row's UUID.
19
+ document_id (str): The document being ingested.
20
+ collection_id (str): Its collection.
21
+ status (str): queued / running / done / failed.
22
+ progress (int): 0–100 (completed pipeline nodes over total).
23
+ current_stage (str | None): The node currently (or last) executed.
24
+ error (str | None): The failure, verbatim — only set when status is failed.
25
+ attempt (int): arq retry attempt (1 = first run).
26
+ started_at (datetime | None): When the worker picked it up.
27
+ finished_at (datetime | None): When it ended (done or failed).
28
+ """
29
+
30
+ job_id: str = Field(description="The job row's UUID.")
31
+ document_id: str = Field(description="The document being ingested.")
32
+ collection_id: str = Field(description="Its collection.")
33
+ status: str = Field(description="queued / running / done / failed.")
34
+ progress: int = Field(description="0-100, completed pipeline nodes over total.")
35
+ current_stage: str | None = Field(default=None, description="Node currently/last executed.")
36
+ error: str | None = Field(default=None, description="Failure detail when status=failed.")
37
+ attempt: int = Field(description="arq retry attempt (1 = first run).")
38
+ started_at: datetime | None = Field(default=None, description="Picked up by the worker at.")
39
+ finished_at: datetime | None = Field(default=None, description="Ended (done or failed) at.")
40
+
41
+
42
+ class JobEvent(BaseModel):
43
+ """
44
+ One node of the job's execution trace — written by the worker at each stage end.
45
+
46
+ Attributes:
47
+ stage (str): The pipeline node id.
48
+ status (str): success / failed / skipped.
49
+ started_at (datetime | None): Node start.
50
+ finished_at (datetime | None): Node end.
51
+ detail (str | None): Duration, or the error when failed.
52
+ """
53
+
54
+ stage: str = Field(description="The pipeline node id.")
55
+ status: str = Field(description="success / failed / skipped.")
56
+ started_at: datetime | None = Field(default=None, description="Node start.")
57
+ finished_at: datetime | None = Field(default=None, description="Node end.")
58
+ detail: str | None = Field(default=None, description="Duration, or the error when failed.")
59
+
60
+
61
+ class JobTrace(BaseModel):
62
+ """
63
+ A job's full per-node trace, in execution order.
64
+
65
+ Attributes:
66
+ job_id (str): The traced job.
67
+ events (list[JobEvent]): One entry per stage run.
68
+ """
69
+
70
+ job_id: str = Field(description="The traced job.")
71
+ events: list[JobEvent] = Field(default_factory=list, description="One entry per stage run.")
72
+
73
+
74
+ class WorkerActivity(BaseModel):
75
+ """
76
+ One worker's live activity — derived from its RUNNING jobs (no extra heartbeat).
77
+
78
+ Attributes:
79
+ worker_id (str): The worker's hostname.
80
+ jobs (list[JobStatus]): Its running jobs, live.
81
+ """
82
+
83
+ worker_id: str = Field(description="The worker's hostname.")
84
+ jobs: list[JobStatus] = Field(default_factory=list, description="Its running jobs, live.")
85
+
86
+
87
+ class WorkersLive(BaseModel):
88
+ """
89
+ Everything running right now, grouped by worker — the monitoring view.
90
+
91
+ Attributes:
92
+ workers (list[WorkerActivity]): One entry per active worker.
93
+ """
94
+
95
+ workers: list[WorkerActivity] = Field(
96
+ default_factory=list, description="One entry per active worker."
97
+ )
98
+
99
+
100
+ __all__ = ["JobStatus", "JobEvent", "JobTrace", "WorkerActivity", "WorkersLive"]
@@ -0,0 +1,182 @@
1
+ # ====== Code Summary ======
2
+ # Response models for the pipeline design surface, mirrored field-for-field from the DocForge backend
3
+ # router models. The graph JSON is OPAQUE to the SDK: every payload the engine owns (blob, palette,
4
+ # explored tree, issues, stages) is typed as ``dict``/``list[dict]``; only the stable ENVELOPE fields
5
+ # (valid / build_error / notices / the surface URLs) carry precise types.
6
+
7
+ # ====== Standard Library Imports ======
8
+ from typing import Any
9
+
10
+ # ====== Third-Party Library Imports ======
11
+ from pydantic import BaseModel, Field
12
+
13
+
14
+ class PipelineSurface(BaseModel):
15
+ """
16
+ One available pipeline design surface — the discovery unit a zero-hardcode UI starts from.
17
+
18
+ Attributes:
19
+ key (str): Stable pipeline identifier (e.g. ``"ingest"``).
20
+ title (str): Human label.
21
+ description (str): What this pipeline does.
22
+ design_url (str): GET — the lean design payload.
23
+ inspect_url (str): POST — blob in, validity + issues + described tree out.
24
+ edit_url (str): POST — apply graph operations server-side.
25
+ stages_view_url (str | None): POST — the stage view of a blob (None when unsupported).
26
+ stages_apply_url (str | None): POST — compile a stage action (None when unsupported).
27
+ """
28
+
29
+ key: str = Field(description="Stable pipeline identifier (e.g. 'ingest').")
30
+ title: str = Field(description="Human label.")
31
+ description: str = Field(description="What this pipeline does.")
32
+ design_url: str = Field(description="GET — the lean design payload.")
33
+ inspect_url: str = Field(description="POST — validity + issues + described tree.")
34
+ edit_url: str = Field(description="POST — apply graph operations server-side.")
35
+ stages_view_url: str | None = Field(
36
+ default=None, description="POST — the stage view of a blob (None when unsupported)."
37
+ )
38
+ stages_apply_url: str | None = Field(
39
+ default=None, description="POST — compile a stage action (None when unsupported)."
40
+ )
41
+
42
+
43
+ class PipelineIndexResponse(BaseModel):
44
+ """
45
+ The pipelines the backend serves — the UI's single bootstrap call.
46
+
47
+ Attributes:
48
+ pipelines (list[PipelineSurface]): One entry per available design surface.
49
+ """
50
+
51
+ pipelines: list[PipelineSurface] = Field(
52
+ default_factory=list, description="One entry per available design surface."
53
+ )
54
+
55
+
56
+ class PipelineDesignResponse(BaseModel):
57
+ """
58
+ Everything the product UI needs to open the design surface in one call.
59
+
60
+ Attributes:
61
+ palette (dict[str, Any]): Every available block (per family); OPAQUE engine JSON.
62
+ blob (dict[str, Any]): The editable pipeline graph; OPAQUE engine JSON.
63
+ issues (list[dict[str, Any]]): Validation problems of the blob (empty when healthy).
64
+ """
65
+
66
+ palette: dict[str, Any] = Field(description="Available blocks per family (opaque engine JSON).")
67
+ blob: dict[str, Any] = Field(description="The editable pipeline graph (opaque engine JSON).")
68
+ issues: list[dict[str, Any]] = Field(
69
+ default_factory=list,
70
+ description="Validation problems of the blob (opaque; empty = healthy).",
71
+ )
72
+
73
+
74
+ class InspectResponse(BaseModel):
75
+ """
76
+ The described mirror of an edited pipeline.
77
+
78
+ Attributes:
79
+ valid (bool): True when the graph built and has zero validation issues.
80
+ issues (list[dict[str, Any]]): Every problem found (opaque engine JSON).
81
+ explored (dict[str, Any] | None): The described tree; None when the build failed.
82
+ build_error (str | None): Precise builder failure (unknown kind, invalid config…).
83
+ """
84
+
85
+ valid: bool = Field(description="True when the graph built and has zero validation issues.")
86
+ issues: list[dict[str, Any]] = Field(
87
+ default_factory=list, description="Every problem found (opaque engine JSON)."
88
+ )
89
+ explored: dict[str, Any] | None = Field(
90
+ default=None, description="The described tree (opaque); None when the build failed."
91
+ )
92
+ build_error: str | None = Field(
93
+ default=None, description="Precise builder failure (unknown kind, invalid config…)."
94
+ )
95
+
96
+
97
+ class EditResponse(BaseModel):
98
+ """
99
+ The result of applying edit operations, then building + validating + describing the result.
100
+
101
+ Attributes:
102
+ blob (dict[str, Any]): The edited blob (or the original when an operation was impossible).
103
+ valid (bool): True when the edited blob built and has zero validation issues.
104
+ issues (list[dict[str, Any]]): Every validation problem found (opaque engine JSON).
105
+ explored (dict[str, Any] | None): The described tree; None when apply or build failed.
106
+ edit_error (str | None): Set when an operation was impossible or the result was unbuildable.
107
+ """
108
+
109
+ blob: dict[str, Any] = Field(description="The edited blob (opaque engine JSON).")
110
+ valid: bool = Field(description="True when the edited blob built and has zero issues.")
111
+ issues: list[dict[str, Any]] = Field(
112
+ default_factory=list, description="Every validation problem found (opaque engine JSON)."
113
+ )
114
+ explored: dict[str, Any] | None = Field(
115
+ default=None, description="The described tree (opaque); None when apply/build failed."
116
+ )
117
+ edit_error: str | None = Field(
118
+ default=None, description="Set when an operation was impossible or the result unbuildable."
119
+ )
120
+
121
+
122
+ class StageViewResponse(BaseModel):
123
+ """
124
+ The stage view of a blob — the full ordered skeleton PLUS its validity verdict.
125
+
126
+ Attributes:
127
+ stages (list[dict[str, Any]]): The canonical stages in run order (opaque engine JSON).
128
+ valid (bool): True when the blob built and has zero validation issues.
129
+ issues (list[dict[str, Any]]): Every validation problem found (opaque engine JSON).
130
+ build_error (str | None): Precise builder failure when the blob cannot even be built.
131
+ """
132
+
133
+ stages: list[dict[str, Any]] = Field(
134
+ description="The canonical stages in run order (opaque engine JSON)."
135
+ )
136
+ valid: bool = Field(description="True when the blob built and has zero validation issues.")
137
+ issues: list[dict[str, Any]] = Field(
138
+ default_factory=list, description="Every validation problem found (opaque engine JSON)."
139
+ )
140
+ build_error: str | None = Field(
141
+ default=None, description="Precise builder failure when the blob cannot even be built."
142
+ )
143
+
144
+
145
+ class StageApplyResponse(BaseModel):
146
+ """
147
+ The result of compiling a stage action: the new blob, its stage view, validity and notices.
148
+
149
+ Attributes:
150
+ blob (dict[str, Any]): The recompiled blob (always buildable; opaque engine JSON).
151
+ stages (list[dict[str, Any]]): The stage view of the recompiled blob, in run order.
152
+ valid (bool): True when the blob built and has zero validation issues.
153
+ issues (list[dict[str, Any]]): Validation problems — expected and shown, never fatal.
154
+ notices (list[str]): What the compiler did beyond the literal action.
155
+ build_error (str | None): Set when the recompiled blob cannot build — fix-in-place data.
156
+ """
157
+
158
+ blob: dict[str, Any] = Field(description="The recompiled blob (opaque engine JSON).")
159
+ stages: list[dict[str, Any]] = Field(
160
+ description="The stage view of the recompiled blob, in run order (opaque engine JSON)."
161
+ )
162
+ valid: bool = Field(description="True when the blob built and has zero validation issues.")
163
+ issues: list[dict[str, Any]] = Field(
164
+ default_factory=list, description="Validation problems — expected and shown, never fatal."
165
+ )
166
+ notices: list[str] = Field(
167
+ default_factory=list, description="What the compiler did beyond the literal action."
168
+ )
169
+ build_error: str | None = Field(
170
+ default=None, description="Set when the recompiled blob cannot build — fix-in-place data."
171
+ )
172
+
173
+
174
+ __all__ = [
175
+ "PipelineSurface",
176
+ "PipelineIndexResponse",
177
+ "PipelineDesignResponse",
178
+ "InspectResponse",
179
+ "EditResponse",
180
+ "StageViewResponse",
181
+ "StageApplyResponse",
182
+ ]
@@ -0,0 +1,110 @@
1
+ # ====== Code Summary ======
2
+ # Request/response models for the search resource, mirrored field-for-field from the DocForge backend
3
+ # router models. ``filters`` and ``debug_info`` are opaque, server-shaped JSON and are typed as dicts.
4
+
5
+ # ====== Standard Library Imports ======
6
+ from typing import Any
7
+
8
+ # ====== Third-Party Library Imports ======
9
+ from pydantic import BaseModel, Field
10
+
11
+
12
+ class SearchTarget(BaseModel):
13
+ """
14
+ One field to search and the modalities to search it on.
15
+
16
+ Attributes:
17
+ field (str): The field to search — ``"content"`` (the chunk body) or a metadata field name.
18
+ semantic (bool): Query the field's dense vector (semantic similarity).
19
+ lexical (bool): Query the field's sparse BM25 vector (lexical match).
20
+ """
21
+
22
+ field: str = Field(
23
+ default="content",
24
+ min_length=1,
25
+ description="Field to search — 'content' (chunk body) or a metadata field name.",
26
+ )
27
+ semantic: bool = Field(
28
+ default=False, description="Query the field's dense vector (semantic similarity)."
29
+ )
30
+ lexical: bool = Field(
31
+ default=False, description="Query the field's sparse BM25 vector (lexical match)."
32
+ )
33
+
34
+
35
+ class SearchRequest(BaseModel):
36
+ """
37
+ A hybrid search over one collection.
38
+
39
+ Attributes:
40
+ query (str): The natural-language query, embedded with the collection's own embedder.
41
+ limit (int): Number of fused results to return.
42
+ filters (dict[str, Any] | None): Exact/any-of constraints on the FILTERABLE fields.
43
+ search_in (list[SearchTarget] | None): Fields × modalities to search. None → content on both.
44
+ use_late_interaction (bool | None): Opt into the ColBERT re-score. None → off for this query.
45
+ rescore_pool_size (int | None): Size of the fused candidate pool the ColBERT stage re-scores.
46
+ """
47
+
48
+ query: str = Field(min_length=1, description="The natural-language query to search for.")
49
+ limit: int = Field(default=10, ge=1, le=100, description="Number of fused results.")
50
+ filters: dict[str, Any] | None = Field(
51
+ default=None,
52
+ description="Constraints on the FILTERABLE metadata fields (field → value or [values]).",
53
+ )
54
+ search_in: list[SearchTarget] | None = Field(
55
+ default=None,
56
+ description="Fields × modalities to search (content and/or metadata). None → content on "
57
+ "both semantic and lexical (the unchanged default).",
58
+ )
59
+ use_late_interaction: bool | None = Field(
60
+ default=None,
61
+ description="Opt into the ColBERT late-interaction re-score for this query. None → off.",
62
+ )
63
+ rescore_pool_size: int | None = Field(
64
+ default=None,
65
+ ge=1,
66
+ le=1000,
67
+ description="Fused candidate pool size the ColBERT stage re-scores. None → node/store default.",
68
+ )
69
+
70
+
71
+ class SearchHit(BaseModel):
72
+ """
73
+ One ranked search result — the flat view of a hydrated chunk hit.
74
+
75
+ Attributes:
76
+ chunk_id (str): The chunk's UUID (doubles as its Qdrant point id).
77
+ document_id (str): The document the chunk belongs to.
78
+ score (float): The fused RRF score (higher is better).
79
+ text (str): The chunk's enriched text.
80
+ chunk_index (int): The chunk's ordinal within its document.
81
+ token_count (int): The chunk's token count.
82
+ """
83
+
84
+ chunk_id: str = Field(description="The chunk's UUID.")
85
+ document_id: str = Field(description="The owning document's UUID.")
86
+ score: float = Field(description="Fused RRF score (higher is better).")
87
+ text: str = Field(description="The chunk's enriched text.")
88
+ chunk_index: int = Field(description="Ordinal within the document.")
89
+ token_count: int = Field(description="Token count of the chunk.")
90
+
91
+
92
+ class SearchResponse(BaseModel):
93
+ """
94
+ The result of a hybrid search — the echoed query and its ranked hits.
95
+
96
+ Attributes:
97
+ query (str): The query that was searched (echoed for the client).
98
+ hits (list[SearchHit]): The hydrated hits, best first.
99
+ debug_info (dict[str, Any] | None): Non-fatal diagnostics; None when there is nothing to report.
100
+ """
101
+
102
+ query: str = Field(description="The query that was searched.")
103
+ hits: list[SearchHit] = Field(default_factory=list, description="Ranked hits, best first.")
104
+ debug_info: dict[str, Any] | None = Field(
105
+ default=None,
106
+ description="Non-fatal diagnostics (e.g. late_interaction_skipped). None when empty.",
107
+ )
108
+
109
+
110
+ __all__ = ["SearchTarget", "SearchRequest", "SearchHit", "SearchResponse"]
docforge_sdk/py.typed ADDED
File without changes
@@ -0,0 +1,53 @@
1
+ # ------------------- Bases ------------------- #
2
+ from ._base import AsyncResource, SyncResource
3
+
4
+ # ------------------- Auth resource ------------------- #
5
+ from .auth import AsyncAuth, SyncAuth
6
+
7
+ # ------------------- Blobs resource ------------------- #
8
+ from .blobs import AsyncBlobs, SyncBlobs
9
+
10
+ # ------------------- Collections resource ------------------- #
11
+ from .collections import AsyncCollections, SyncCollections
12
+
13
+ # ------------------- Documents resource ------------------- #
14
+ from .documents import AsyncDocuments, SyncDocuments
15
+
16
+ # ------------------- Explorer resource ------------------- #
17
+ from .explorer import AsyncExplorer, SyncExplorer
18
+
19
+ # ------------------- Health resource ------------------- #
20
+ from .health import AsyncHealth, SyncHealth
21
+
22
+ # ------------------- Jobs resource ------------------- #
23
+ from .jobs import AsyncJobs, SyncJobs
24
+
25
+ # ------------------- Pipelines resource ------------------- #
26
+ from .pipelines import AsyncPipelines, SyncPipelines
27
+
28
+ # ------------------- Search resource ------------------- #
29
+ from .search import AsyncSearch, SyncSearch
30
+
31
+ # ------------------- Public API ------------------- #
32
+ __all__ = [
33
+ "AsyncResource",
34
+ "SyncResource",
35
+ "AsyncAuth",
36
+ "SyncAuth",
37
+ "AsyncHealth",
38
+ "SyncHealth",
39
+ "AsyncCollections",
40
+ "SyncCollections",
41
+ "AsyncDocuments",
42
+ "SyncDocuments",
43
+ "AsyncExplorer",
44
+ "SyncExplorer",
45
+ "AsyncSearch",
46
+ "SyncSearch",
47
+ "AsyncJobs",
48
+ "SyncJobs",
49
+ "AsyncBlobs",
50
+ "SyncBlobs",
51
+ "AsyncPipelines",
52
+ "SyncPipelines",
53
+ ]
@@ -0,0 +1,46 @@
1
+ # ====== Code Summary ======
2
+ # Base classes for resource groups. A resource holds only a reference to its transport; the async and
3
+ # sync bases exist so a resource can bind to the matching transport type while sharing the pure
4
+ # spec-building logic contributed by per-resource mixins (e.g. _AuthSpecs).
5
+
6
+ # ====== Local Project Imports ======
7
+ from .._transport_async import AsyncTransport
8
+ from .._transport_sync import SyncTransport
9
+
10
+
11
+ class _ResourceMixin:
12
+ """
13
+ Marker base for the pure spec-builder mixins.
14
+
15
+ Spec-builder mixins carry no state and no I/O — only methods returning ``RequestSpec`` — so the
16
+ async and sync resources can share them verbatim.
17
+ """
18
+
19
+
20
+ class AsyncResource:
21
+ """Base for asynchronous resource groups; holds the async transport."""
22
+
23
+ def __init__(self, transport: AsyncTransport) -> None:
24
+ """
25
+ Bind the resource to its async transport.
26
+
27
+ Args:
28
+ transport (AsyncTransport): The transport used to execute this resource's requests.
29
+ """
30
+ self._transport = transport
31
+
32
+
33
+ class SyncResource:
34
+ """Base for synchronous resource groups; holds the sync transport."""
35
+
36
+ def __init__(self, transport: SyncTransport) -> None:
37
+ """
38
+ Bind the resource to its sync transport.
39
+
40
+ Args:
41
+ transport (SyncTransport): The transport used to execute this resource's requests.
42
+ """
43
+ self._transport = transport
44
+
45
+
46
+ __all__ = ["_ResourceMixin", "AsyncResource", "SyncResource"]