Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions docs/examples/rag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,54 @@ A complete RAG pipeline with relevance filtering using generative stubs.
- Using `@generative` for filtering logic

### [mellea_pdf.py](./mellea_pdf.py)
RAG example specifically for PDF documents.
Document-grounded question answering using W3C's
[WCAG 1.0 checklist PDF](https://www.w3.org/TR/1999/WAI-WEBCONTENT-19990505/full-checklist.pdf).
The question asks what the three checkpoint priority levels mean; the answer is
in the document's **Priorities** section on page 2. In brief, developers must
satisfy Priority 1 checkpoints, should satisfy Priority 2 checkpoints, and may
address Priority 3 checkpoints. Generated wording can vary.

This dated, seven-page publication is historical sample material, not current
accessibility guidance. It replaces a USDA PDF that returned HTTP 403 for users
outside the US. The PDF remains hosted by W3C under its
[document license](https://www.w3.org/Consortium/Legal/copyright-documents-19990405);
no copy is bundled with this example.

**Prerequisites:** Install the Docling extra, have internet access to download
the PDF and Docling's conversion models, and run Ollama with `granite4.2:3b`
(the current `start_session()` default). FAISS and sentence-transformers are
not needed for this example. OCR is disabled because the PDF contains text;
Docling may still download layout and table models on the first conversion.

From the repository root:

```bash
uv sync --frozen --extra docling
ollama serve # run in a separate terminal if Ollama is not already running
ollama pull granite4.2:3b
uv run python docs/examples/rag/mellea_pdf.py
```

From another working directory, use absolute paths to the checkout and script:

```bash
uv run --project /path/to/mellea python /path/to/mellea/docs/examples/rag/mellea_pdf.py
```

The document URL is independent of the working directory. PDF conversion happens
before the session is created, so document-loading failures can be distinguished
from model-inference failures. The `e2e, ollama, slow` markers opt the example
into explicit slow-test runs. Its assertions check only that the result is a
non-empty string, not the factual content of the answer. The `slow` marker
accounts for cold conversion-model downloads and inference; ordinary test runs
exclude it. `CICD=1` does not skip this structural test, but current PR CI does
not collect Python examples.

To run it through pytest, including the slow marker:

```bash
uv run pytest docs/examples/rag/mellea_pdf.py -m "e2e and ollama" --no-cov -v -s
```

@rafvasq rafvasq Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra context not needed at the moment. I think this can be kept to one-line for now as it was before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - rest of fix looks good, but this is unnecessarily verbose and historic


## Concepts Demonstrated

Expand Down Expand Up @@ -100,4 +147,4 @@ uv pip install faiss-cpu sentence-transformers

- See `intrinsics/` for RAG evaluation adapter functions
- See `mini_researcher/` for a complete RAG application
- See `mellea/stdlib/components/intrinsic/rag.py` for RAG helpers
- See `mellea/stdlib/components/intrinsic/rag.py` for RAG helpers
27 changes: 17 additions & 10 deletions docs/examples/rag/mellea_pdf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# pytest: skip_always
# pytest: e2e, ollama, slow

"""Answer a question grounded in W3C's historical WCAG 1.0 checklist."""

import mellea
from mellea.stdlib.components.docs.richdocument import RichDocument

m = mellea.start_session()

doc = RichDocument.from_document_file(
"https://www.fs.usda.gov/foresthealth/docs/fidls/FIDL-78-ArmillariaRootDisease.pdf"
"https://www.w3.org/TR/1999/WAI-WEBCONTENT-19990505/full-checklist.pdf",
do_ocr=False,
)

print(
m.instruct(
"Determine whether the mellea fungus only feeds on dead or weakened trees, thereby improving forest health",
grounding_context={"usfs": doc},
).value
)
m = mellea.start_session()

answer = m.instruct(
"Using only the provided WCAG 1.0 checklist, explain what Priority 1, "
"Priority 2, and Priority 3 mean for a Web content developer. "
"Answer with one sentence per priority level.",
grounding_context={"wcag_checklist": doc},
).value

assert isinstance(answer, str)
assert answer.strip()
print(answer)
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ unit tests you also need Ollama running locally:

```bash
ollama serve &
ollama pull granite4:micro
ollama pull granite4.2:3b
ollama pull granite4:micro-h
```

Expand Down
Loading