document.MarkdownDocument

A Markdown document with source tracking.

Usage

Source

document.MarkdownDocument(
    content,
    origin=None,
    attributes=None,
)

MarkdownDocument is the everyday document type in raghilda: read_as_markdown() returns one, and the crawlers yield them. It has the same fields as Document (content, origin, attributes), with the understanding that content is Markdown and origin records where that content came from (a URL or file path) for citation and provenance. Chunking a MarkdownDocument yields a ChunkedMarkdownDocument.

Parameters

content: str

The Markdown text of the document.

origin: Optional[str] = None

Where the content came from (a URL or file path), used for citation and provenance. Stores require a populated origin at upsert time.

attributes: Optional[dict[str, Any]] = None
Optional user-defined attributes applied at insertion time. Chunks can inherit them, and they are returned during retrieval for filtering and downstream prompt/context use.

Examples

You usually get one from read_as_markdown(), but you can also build one directly from text you already have:

from raghilda.document import MarkdownDocument

# Create from content directly
doc = MarkdownDocument(
    content="# Hello World\n\nThis is a test document.",
    origin="https://example.com/hello.md",
)
print(f"Document from: {doc.origin}")
print(f"Content length: {len(doc.content)} characters")
Document from: https://example.com/hello.md
Content length: 39 characters

Methods

Name Description
from_any() Convert any document-like or IntoDocument object to a MarkdownDocument.
to_chunked() Return a ChunkedMarkdownDocument with the same fields and chunks.

from_any()

Convert any document-like or IntoDocument object to a MarkdownDocument.

Usage

Source

from_any(doc, origin=None)

This conversion only accepts unchunked inputs. If the source object already carries chunks, use ChunkedMarkdownDocument.from_any() instead.

Parameters
doc: Union[DocumentLike, IntoDocument]

An object that implements the DocumentLike protocol or has a to_document() method.

origin: Optional[str] = None
Optional origin to set if the source object doesn’t have one.
Returns
MarkdownDocument
A raghilda MarkdownDocument instance.

to_chunked()

Return a ChunkedMarkdownDocument with the same fields and chunks.

Usage

Source

to_chunked(chunks)