fastrag.ingestion.steps.parsing.docusaurus#
Docusaurus documentation parsing: the article, not the site chrome.
A Docusaurus site (docs.pontus-x.eu, agrospai.udl.cat/*/docs/*) wraps
its actual article in a container div carrying a markdown class,
surrounded by navigation, sidebars, breadcrumbs, footers, and “edit this
page” links that HtmlParser
has no way to distinguish from content. Feeding the whole page to it buries
the article in boilerplate that then gets chunked and embedded — noise a RAG
index does not want. This parser extracts only the first such div and
converts that subtree; a page carrying no such container is parsed whole,
the way HtmlParser does, with a metadata marker recording the fallback.
Module Attributes
Article headers contain the page heading; permalink anchors are UI chrome. |
|
Metadata key set on every produced document, |
|
The filter a |
Classes
|
Extract a Docusaurus page's article, discarding the surrounding chrome. |
- fastrag.ingestion.steps.parsing.docusaurus.DEFAULT_DOCUSAURUS_SELECTORS = ('script', 'style', 'noscript', 'nav', 'footer', 'aside', 'a.hash-link')#
Article headers contain the page heading; permalink anchors are UI chrome.
- fastrag.ingestion.steps.parsing.docusaurus.FALLBACK_METADATA_KEY = 'docusaurus_fallback'#
Metadata key set on every produced document,
Truewhen the page carried nomarkdown-classeddivand this parser fell back to parsing the whole document instead — the marker a caller reads to tell the two cases apart.
- fastrag.ingestion.steps.parsing.docusaurus.docusaurus_filter: Filter[Source | Document] = <fastrag.ingestion.steps.parsing.docusaurus._DocusaurusFilter object>#
The filter a
ParserRouterroutes Docusaurus pages with. It inspects content, so it is notheader_safe:parser = ParserRouter(cache=cache).route( html_filter & docusaurus_filter, DocusaurusParser() )
- Parameters:
item (T_contra)
- Return type:
- class fastrag.ingestion.steps.parsing.docusaurus.DocusaurusParser(*, strip_selectors=('script', 'style', 'noscript', 'nav', 'footer', 'aside', 'a.hash-link'), encoding=None, vision=None, cache=None, policy=None)[source]#
Bases:
ParserExtract a Docusaurus page’s article, discarding the surrounding chrome.
Finds the first
divwhose class list includesmarkdown(Docusaurus themes typically render it asclass="theme-doc-markdown markdown") and converts only that subtree to Markdown, using the sameHtmlParsermachinery (strip selectors, link absolutization, HTML-to-Markdown conversion) — just scoped to the article rather than the whole document. A page with no suchdivis parsed whole, exactly asHtmlParserwould, and the produced document’s metadata records that the fallback happened.from fastrag.ingestion.steps.parsing import DocusaurusParser, ParserRouter parser = ParserRouter(cache=cache).route(docs_filter, DocusaurusParser())
- Parameters:
strip_selectors (Sequence[str])
encoding (str | None)
vision (OpenAIVisionParser | None)
cache (CacheStore | Literal[False] | None)
policy (Policy | None)
- content_format: ContentFormat = 'markdown'#
The
ContentFormatthis parser’s documents carry by default, stamped bybuild_document()intometadata["content_format"]. Override on a subclass whose output is always one format (HtmlParser/DocusaurusParsersetMARKDOWN); passcontent_format=to a singlebuild_document()call instead for a parser whose output format depends on its own configuration.
- accepted_media_types: frozenset[str] | None = frozenset({'application/xhtml+xml', 'text/html'})#
None retains legacy permissiveness; MIME patterns may use
type/*.
- config()[source]#
This parser’s cache-identity configuration.
strip_selectors/encodingchange what a given page’s bytes parse into, so both are part of the fingerprint. Whichdivis matched is not configurable, so it is not part of it.
- async transform(item, context)[source]#
Yield one Markdown document per page, extracted or whole.
- Parameters:
item (Source)
context (ExecutionContext)
- Return type:
- build_document(source, content, metadata=None, *, content_format=None)#
Build one document from
source’s parsedcontent.Sets
id(a hash of the source identity and parsed content),source_id,step_config_hash(this parser’s ownconfig_hash), and the reserved metadata keys every parser gets right without writing them itself:source_uri,content_type(source’s own, as declared or guessed upstream), andcontent_format(what kind of stringcontentis —content_formatunless overridden for this one call). Thesite_name/favicon_urla fetcher found onsourceare carried over too, unlessmetadatasets its own.- Parameters:
source (Source) – The source
contentwas parsed from.content (str) – The parsed text.
metadata (dict[str, Any] | None) – Extra metadata to carry, e.g. an HTML page’s
title.content_format (ContentFormat | None) – Overrides
content_formatfor this one document, for a parser whose output format depends on its own configuration rather than being fixed per class.
- Return type:
- property cache: CacheStore | Literal[False] | None#
Return the cache explicitly configured for this step.
- effective_policy(context)#
Resolve this step’s policy over the one inherited from
context.The step’s own explicitly-set fields take priority; everything else falls through to the pipeline (or enclosing router/aggregator) policy.
- Parameters:
context (ExecutionContext)
- Return type:
- async evaluate(context)#
Emit
DocumentParsedper document.Wraps
DocumentStep’s concreteevaluate(which already resolved, per item, whether the document came from cache or a freshtransform()call —document.cachedis trustworthy either way) rather than emitting inside a concrete parser’s owntransform(), so the event fires the same way for a cache hit as for a fresh parse, and exactly once regardless of how many layers of routing (e.g.ParserRouter) produced the document.- Parameters:
context (ExecutionContext)
- Return type:
- async evaluate_items(items, context)#
Transform a bounded cache window independently of worker concurrency.
- Parameters:
items (AsyncIterator[Any])
context (ExecutionContext)
- Return type:
- event_name: str = 'Parsing'#
The stage this step’s work belongs to, e.g.
"Chunking".Declared as a plain class attribute by a family base class, and inherited by every concrete step in that family:
class Chunker(DocumentStep, ABC): event_name = "Chunking" class ChunkerRouter(RoutedStep[Document], Chunker): ... # -> "Chunking", inherited from `Chunker`
A concrete step overrides it to opt out of its family’s label:
class ChunkerRouter(RoutedStep[Document], Chunker): event_name = "ChunkerRouter" # -> "ChunkerRouter"
Resolution walks the MRO for the first class that declares it in its own class body (so a mixin listed first, e.g.
RoutedStep, contributes nothing unless it declares one itself), and falls back to the class’s own name when nothing in the MRO does — a step family that never declares anevent_namestill labels each of its steps distinctly rather than collapsing them under one blank heading. That fallback is computed per instance rather than assigned onto the class: assigning it would make it look “declared” to every subclass, which would then inherit their base’s name instead of getting their own.
- replay_needs_content: bool = False#
Set by a step whose cached replay reads the full documents anyway (e.g. to re-validate them): its cache reads then skip the header-only projection rather than fetching every entry twice.
- async run()#
Execute this step independently and collect every item.
Builds a default
ExecutionContextwhen none is installed (this step’s ownpolicy, or a freshPolicy). Intended primarily for testing and standalone use — pipeline-wide event observation isPipeline’s job.- Return type:
list[T]
- property upstream: PipelineStep[Any] | None#
Return the upstream step bound via
__call__, orNone.Read-only counterpart to
__call__’sself._upstreamassignment — lets external code (e.g.Pipeline, walking a graph from its root to classify each step by position) introspect composition without reaching into a private attribute.