webcite-haystack 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,41 @@
1
+ """Shared helpers for the Webcite Haystack components."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from typing import Any
7
+
8
+ from haystack import Document
9
+ from haystack.utils import Secret
10
+
11
+ from webcite import Webcite
12
+
13
+ DEFAULT_KEY = Secret.from_env_var("WEBCITE_API_KEY")
14
+
15
+
16
+ def make_client(api_key: Secret, timeout: float | None) -> Webcite:
17
+ return Webcite(api_key.resolve_value(), timeout=timeout)
18
+
19
+
20
+ def citations(response: Mapping[str, Any]) -> list[Mapping[str, Any]]:
21
+ groups = response.get("claim_groups") or []
22
+ if groups and groups[0].get("citations") is not None:
23
+ return list(groups[0]["citations"])
24
+ return list(response.get("citations") or [])
25
+
26
+
27
+ def citation_document(citation: Mapping[str, Any]) -> Document:
28
+ """One citation as a Document: the bound source passage as content."""
29
+ bound = citation.get("passage") or {}
30
+ passage = bound.get("text") or citation.get("snippet")
31
+ meta = {
32
+ "url": citation.get("url"),
33
+ "title": citation.get("title"),
34
+ "stance": citation.get("stance"),
35
+ "citation_id": citation.get("id"),
36
+ "passage_sha256": bound.get("sha256"),
37
+ }
38
+ return Document(
39
+ content=str(passage or citation.get("title") or citation.get("url")),
40
+ meta={k: v for k, v in meta.items() if v is not None},
41
+ )
@@ -0,0 +1,5 @@
1
+ from haystack_integrations.components.converters.webcite.converter import (
2
+ WebciteDocumentConverter,
3
+ )
4
+
5
+ __all__ = ["WebciteDocumentConverter"]
@@ -0,0 +1,90 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any, Literal
5
+
6
+ from haystack import Document, component, default_from_dict, default_to_dict
7
+ from haystack.dataclasses import ByteStream
8
+ from haystack.utils import Secret, deserialize_secrets_inplace
9
+
10
+ from haystack_integrations.common.webcite import DEFAULT_KEY, make_client
11
+ from webcite import Webcite
12
+
13
+ Source = str | Path | ByteStream
14
+
15
+
16
+ @component
17
+ class WebciteDocumentConverter:
18
+ """Read PDFs, scans, images, spreadsheets and office files into Markdown Documents.
19
+
20
+ Sources may be local paths, ``ByteStream`` objects (with ``meta["file_name"]``) or
21
+ ``https://`` URLs. Local files and byte streams are uploaded first (free); extraction is
22
+ metered per page at cost. Each Document's ``meta`` has ``state``, ``pages`` and ``credits``;
23
+ when ``state`` is not ``complete``, ``reason`` names what was not read.
24
+
25
+ ```python
26
+ from haystack_integrations.components.converters.webcite import WebciteDocumentConverter
27
+
28
+ converter = WebciteDocumentConverter(mode="lite")
29
+ docs = converter.run(sources=["https://www.irs.gov/pub/irs-pdf/fw9.pdf"])["documents"]
30
+ ```
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ api_key: Secret = DEFAULT_KEY,
36
+ mode: Literal["standard", "lite"] | None = None,
37
+ timeout: float | None = None,
38
+ ) -> None:
39
+ self.api_key = api_key
40
+ self.mode = mode
41
+ self.timeout = timeout
42
+ self._client: Webcite | None = None
43
+
44
+ def warm_up(self) -> None:
45
+ if self._client is None:
46
+ self._client = make_client(self.api_key, self.timeout)
47
+
48
+ def to_dict(self) -> dict[str, Any]:
49
+ return default_to_dict(
50
+ self, api_key=self.api_key.to_dict(), mode=self.mode, timeout=self.timeout
51
+ )
52
+
53
+ @classmethod
54
+ def from_dict(cls, data: dict[str, Any]) -> WebciteDocumentConverter:
55
+ deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
56
+ return default_from_dict(cls, data)
57
+
58
+ def _extract(self, client: Webcite, source: Source) -> tuple[dict[str, Any], str]:
59
+ if isinstance(source, str) and source.startswith("https://"):
60
+ return dict(client.extract(asset_url=source, mode=self.mode)), source
61
+ if isinstance(source, ByteStream):
62
+ name = str(source.meta.get("file_name") or "")
63
+ asset = client.upload(source.data, filename=name)["data"]
64
+ else:
65
+ name = str(source)
66
+ asset = client.upload(Path(source))["data"]
67
+ return dict(client.extract(asset["asset_id"], mode=self.mode)), name
68
+
69
+ @component.output_types(documents=list[Document])
70
+ def run(self, sources: list[Source], meta: dict[str, Any] | None = None) -> dict[str, Any]:
71
+ self.warm_up()
72
+ assert self._client is not None
73
+ documents = []
74
+ for source in sources:
75
+ response, name = self._extract(self._client, source)
76
+ usage = response.get("usage") or {}
77
+ info = {
78
+ "source": name,
79
+ "state": response.get("state"),
80
+ "reason": response.get("reason"),
81
+ "pages": usage.get("pages"),
82
+ "credits": usage.get("credits"),
83
+ }
84
+ documents.append(
85
+ Document(
86
+ content=response.get("markdown"),
87
+ meta={**(meta or {}), **{k: v for k, v in info.items() if v is not None}},
88
+ )
89
+ )
90
+ return {"documents": documents}
@@ -0,0 +1,3 @@
1
+ from haystack_integrations.components.verifiers.webcite.verifier import WebciteClaimVerifier
2
+
3
+ __all__ = ["WebciteClaimVerifier"]
@@ -0,0 +1,85 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from haystack import Document, component, default_from_dict, default_to_dict
6
+ from haystack.utils import Secret, deserialize_secrets_inplace
7
+
8
+ from haystack_integrations.common.webcite import (
9
+ DEFAULT_KEY,
10
+ citation_document,
11
+ citations,
12
+ make_client,
13
+ )
14
+ from webcite import Webcite
15
+
16
+
17
+ @component
18
+ class WebciteClaimVerifier:
19
+ """Check claims against sources with Webcite (4 credits per claim with stance and verdict).
20
+
21
+ For each claim, returns a verdict (``result`` and ``summary``) and the citations it rests on
22
+ as Documents whose content is the bound source passage. ``source_urls`` restricts the check
23
+ to given pages instead of a web search.
24
+
25
+ ```python
26
+ from haystack_integrations.components.verifiers.webcite import WebciteClaimVerifier
27
+
28
+ verifier = WebciteClaimVerifier()
29
+ result = verifier.run(claims=["The Great Wall of China is visible from the Moon."])
30
+ print(result["verdicts"][0]["result"])
31
+ ```
32
+ """
33
+
34
+ def __init__(
35
+ self,
36
+ api_key: Secret = DEFAULT_KEY,
37
+ max_citations: int = 5,
38
+ timeout: float | None = None,
39
+ ) -> None:
40
+ self.api_key = api_key
41
+ self.max_citations = max_citations
42
+ self.timeout = timeout
43
+ self._client: Webcite | None = None
44
+
45
+ def warm_up(self) -> None:
46
+ if self._client is None:
47
+ self._client = make_client(self.api_key, self.timeout)
48
+
49
+ def to_dict(self) -> dict[str, Any]:
50
+ return default_to_dict(
51
+ self,
52
+ api_key=self.api_key.to_dict(),
53
+ max_citations=self.max_citations,
54
+ timeout=self.timeout,
55
+ )
56
+
57
+ @classmethod
58
+ def from_dict(cls, data: dict[str, Any]) -> WebciteClaimVerifier:
59
+ deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
60
+ return default_from_dict(cls, data)
61
+
62
+ @component.output_types(verdicts=list[dict[str, Any]], documents=list[Document])
63
+ def run(self, claims: list[str], source_urls: list[str] | None = None) -> dict[str, Any]:
64
+ """``documents`` holds every claim's citations; each has ``meta["claim"]``."""
65
+ self.warm_up()
66
+ assert self._client is not None
67
+ verdicts: list[dict[str, Any]] = []
68
+ documents: list[Document] = []
69
+ for claim in claims:
70
+ response = self._client.verify(claim, source_urls=source_urls or None)
71
+ groups = response.get("claim_groups") or []
72
+ verdict = (groups[0].get("verdict") if groups else None) or {}
73
+ verdicts.append(
74
+ {
75
+ "claim": claim,
76
+ "result": verdict.get("result"),
77
+ "summary": verdict.get("summary"),
78
+ "credits": (response.get("usage") or {}).get("credits"),
79
+ "response": dict(response),
80
+ }
81
+ )
82
+ for cited in citations(response)[: self.max_citations]:
83
+ doc = citation_document(cited)
84
+ documents.append(Document(content=doc.content, meta={**doc.meta, "claim": claim}))
85
+ return {"verdicts": verdicts, "documents": documents}
@@ -0,0 +1,3 @@
1
+ from haystack_integrations.components.websearch.webcite.search import WebciteWebSearch
2
+
3
+ __all__ = ["WebciteWebSearch"]
@@ -0,0 +1,64 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from haystack import Document, component, default_from_dict, default_to_dict
6
+ from haystack.utils import Secret, deserialize_secrets_inplace
7
+
8
+ from haystack_integrations.common.webcite import (
9
+ DEFAULT_KEY,
10
+ citation_document,
11
+ citations,
12
+ make_client,
13
+ )
14
+ from webcite import Webcite
15
+
16
+
17
+ @component
18
+ class WebciteWebSearch:
19
+ """Find sources for a query with Webcite source search (2 credits per search).
20
+
21
+ Returns one Document per source, with the matching source passage as content and the URL,
22
+ title and stance in ``meta``, plus the list of URLs.
23
+
24
+ ```python
25
+ from haystack_integrations.components.websearch.webcite import WebciteWebSearch
26
+
27
+ search = WebciteWebSearch(top_k=3)
28
+ result = search.run(query="Apple total net sales fiscal 2024")
29
+ ```
30
+ """
31
+
32
+ def __init__(
33
+ self, api_key: Secret = DEFAULT_KEY, top_k: int | None = 5, timeout: float | None = None
34
+ ) -> None:
35
+ self.api_key = api_key
36
+ self.top_k = top_k
37
+ self.timeout = timeout
38
+ self._client: Webcite | None = None
39
+
40
+ def warm_up(self) -> None:
41
+ if self._client is None:
42
+ self._client = make_client(self.api_key, self.timeout)
43
+
44
+ def to_dict(self) -> dict[str, Any]:
45
+ return default_to_dict(
46
+ self, api_key=self.api_key.to_dict(), top_k=self.top_k, timeout=self.timeout
47
+ )
48
+
49
+ @classmethod
50
+ def from_dict(cls, data: dict[str, Any]) -> WebciteWebSearch:
51
+ deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
52
+ return default_from_dict(cls, data)
53
+
54
+ @component.output_types(documents=list[Document], links=list[str])
55
+ def run(self, query: str, top_k: int | None = None) -> dict[str, Any]:
56
+ self.warm_up()
57
+ assert self._client is not None
58
+ limit = top_k if top_k is not None else self.top_k
59
+ found = citations(self._client.search(query, limit=limit))
60
+ documents = [citation_document(c) for c in (found[:limit] if limit else found)]
61
+ return {
62
+ "documents": documents,
63
+ "links": [d.meta["url"] for d in documents if "url" in d.meta],
64
+ }
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.5
2
+ Name: webcite-haystack
3
+ Version: 0.1.0
4
+ Summary: Haystack components for Webcite: parse documents to Markdown, search sources, and verify claims with citations bound to source passages.
5
+ Project-URL: Homepage, https://webcite.co
6
+ Project-URL: Documentation, https://github.com/strategyconnect/webcite-haystack#readme
7
+ Project-URL: Repository, https://github.com/strategyconnect/webcite-haystack
8
+ Project-URL: Issues, https://github.com/strategyconnect/webcite-haystack/issues
9
+ Author: Webcite
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: citations,claim-verification,document-parsing,fact-checking,haystack,ocr,pdf-to-markdown,rag,web-search,webcite
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: haystack-ai<3.0.0,>=2.9.0
21
+ Requires-Dist: webcite<0.2.0,>=0.1.0
22
+ Description-Content-Type: text/markdown
23
+
24
+ # webcite-haystack
25
+
26
+ [Haystack](https://haystack.deepset.ai) components for [Webcite](https://webcite.co), one evidence
27
+ suite for AI apps and agents: document parsing and OCR to Markdown, claim verification with
28
+ verdicts, citations bound to source passages, and source search.
29
+
30
+ | Component | Import | What it does | Credits |
31
+ |---|---|---|---|
32
+ | `WebciteDocumentConverter` | `haystack_integrations.components.converters.webcite` | PDFs, scans, images, spreadsheets and office files (paths, `ByteStream`s or `https://` URLs) to Markdown `Document`s | Per page, at cost; upload is free |
33
+ | `WebciteWebSearch` | `haystack_integrations.components.websearch.webcite` | Sources for a query as `Document`s (passage as content; URL, title, stance in `meta`) and `links` | 2 per search |
34
+ | `WebciteClaimVerifier` | `haystack_integrations.components.verifiers.webcite` | A verdict per claim, with the citations it rests on as `Document`s | 4 per claim |
35
+
36
+ Prices are on [webcite.co/pricing](https://webcite.co/pricing). The Free plan includes 100
37
+ credits, renewing every 30 days while credits remain.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install webcite-haystack
43
+ export WEBCITE_API_KEY=... # create one at https://webcite.co/api-keys
44
+ ```
45
+
46
+ Python 3.10 or newer, Haystack 2.x. The key is read through a Haystack `Secret`
47
+ (`Secret.from_env_var("WEBCITE_API_KEY")` by default), so pipelines serialize without it.
48
+
49
+ ## Convert documents to Markdown
50
+
51
+ ```python
52
+ from haystack_integrations.components.converters.webcite import WebciteDocumentConverter
53
+
54
+ converter = WebciteDocumentConverter() # mode="lite" for the faster, cheaper read
55
+ docs = converter.run(sources=["https://www.irs.gov/pub/irs-pdf/fw9.pdf"])["documents"]
56
+ print(docs[0].meta)
57
+ print(docs[0].content.splitlines()[0])
58
+ ```
59
+
60
+ Output for page 1 of the form, from the response recorded from the API
61
+ ([webcite.co/samples/doc-irs-w9.json](https://webcite.co/samples/doc-irs-w9.json)):
62
+
63
+ ```text
64
+ {'source': 'https://www.irs.gov/pub/irs-pdf/fw9.pdf', 'state': 'complete', 'pages': 1, 'credits': 0.4966}
65
+ Form **W-9**
66
+ ```
67
+
68
+ Check `meta["state"]`: anything other than `complete` comes with `meta["reason"]` naming what was
69
+ not read. The request stays open until every page is read; there is no job to poll.
70
+
71
+ ## Verify claims
72
+
73
+ ```python
74
+ from haystack_integrations.components.verifiers.webcite import WebciteClaimVerifier
75
+
76
+ verifier = WebciteClaimVerifier(max_citations=2)
77
+ out = verifier.run(claims=["The Great Wall of China is visible from the Moon with the naked eye."])
78
+ print(out["verdicts"][0]["result"], out["verdicts"][0]["credits"])
79
+ for doc in out["documents"]:
80
+ print(doc.meta["stance"], doc.meta["url"])
81
+ ```
82
+
83
+ Output, from the response recorded from the API on 24 November 2026
84
+ ([webcite.co/samples/claim-great-wall.json](https://webcite.co/samples/claim-great-wall.json)):
85
+
86
+ ```text
87
+ contradicted 4
88
+ contradicts https://www.nasa.gov/image-article/great-wall/
89
+ inconclusive https://www.britannica.com/question/Can-you-see-the-Great-Wall-of-China-from-space
90
+ ```
91
+
92
+ Each document's content is the source passage the citation is bound to. Pass `source_urls` to
93
+ check claims against given pages instead of a web search. `verdicts[i]["response"]` keeps the full
94
+ API response.
95
+
96
+ ## Search sources
97
+
98
+ ```python
99
+ from haystack_integrations.components.websearch.webcite import WebciteWebSearch
100
+
101
+ search = WebciteWebSearch(top_k=3)
102
+ result = search.run(query="Apple total net sales fiscal 2024")
103
+ print(result["links"])
104
+ ```
105
+
106
+ ## In a pipeline
107
+
108
+ See [`examples/pipeline.py`](examples/pipeline.py). All three components support `to_dict` and
109
+ `from_dict`, so pipelines round-trip through YAML.
110
+
111
+ The same capabilities are also available to any MCP client from the hosted server at
112
+ `https://api.webcite.co/mcp` (OAuth or API key).
113
+
114
+ ## Development
115
+
116
+ ```bash
117
+ make install # uv sync --all-groups
118
+ make check # ruff, mypy, pytest
119
+ make build # wheel and sdist in dist/
120
+ ```
121
+
122
+ Tests run against recorded API responses in `tests/fixtures` with sockets disabled, so no test
123
+ reaches the network or spends credits.
124
+
125
+ ## Links
126
+
127
+ - [Webcite API reference](https://webcite.co/api-docs)
128
+ - [Webcite Python SDK](https://github.com/strategyconnect/webcite-python)
129
+ - Issues: https://github.com/strategyconnect/webcite-haystack/issues
130
+ - Support: support@webcite.co
131
+
132
+ MIT licensed.
@@ -0,0 +1,12 @@
1
+ haystack_integrations/common/webcite/__init__.py,sha256=tVQYFzppjHLnT84bK1B9rwgR1RTZMPrxhypq_zQYcGY,1342
2
+ haystack_integrations/components/converters/webcite/__init__.py,sha256=21SWraUUEmtKlwAkNjV2hl29eSakpVOJkrfYBNHyCdo,148
3
+ haystack_integrations/components/converters/webcite/converter.py,sha256=9QcSY-p_CBA_p34eTrpIMposWUxKwVK0yc3vmusChlc,3510
4
+ haystack_integrations/components/verifiers/webcite/__init__.py,sha256=2gyM4MgH5-FEBSkYqG2tKlnaWzXJBXTBxWFvDgsVHOE,129
5
+ haystack_integrations/components/verifiers/webcite/verifier.py,sha256=5kSCXCAiFybpVd6Zjoyl4JT6gxm55rlyww7sAmXjD7U,3173
6
+ haystack_integrations/components/websearch/webcite/__init__.py,sha256=omtpxznnlRlaz9plr9vuf4VH9A1zy8siX5kIwHzW_5k,119
7
+ haystack_integrations/components/websearch/webcite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ haystack_integrations/components/websearch/webcite/search.py,sha256=J8yvSRTT1olP2VOEBy6pEl9ECmhrO71IzHvJNncU_A0,2187
9
+ webcite_haystack-0.1.0.dist-info/METADATA,sha256=ZHVF6eKtWjBD59pV4K5QbIM9VZ1qcDxH-JIQe-fRbHY,5361
10
+ webcite_haystack-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ webcite_haystack-0.1.0.dist-info/licenses/LICENSE,sha256=ZfHdQvjcMlOV3tvWbiik9xYRbscmZNE4pMkIeHbUSMA,1063
12
+ webcite_haystack-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marvin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.