Skip to content

docs(examples): standardize data, extraction, and RAG examples - #1764

Open
rafvasq wants to merge 2 commits into
generative-computing:mainfrom
rafvasq:docs/data-extraction-rag-standardize
Open

rafvasq wants to merge 2 commits into
generative-computing:mainfrom
rafvasq:docs/data-extraction-rag-standardize

Conversation

@rafvasq

@rafvasq rafvasq commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Issue

Towards #1746

Description

Docstrings

  • Kept the original titles and descriptions. Added docstrings to scripts that had none.
  • Added Prerequisites: and Usage: blocks.

READMEs

  • Each is now a short description, links to the relevant docs, and includes a ## Examples table. Removed content was checked against the site docs first.

Other fixes

  • Removed unused model_ids imports in both information_extraction/ scripts.
  • ollama pull tags match each script's actual model.
  • Docling examples use uv sync --extra docling.
  • rich_document_advanced.py: added an MPS→CPU accelerator guard that RichDocument uses (fix: force cpu accelerator for docling on apple silicon mps #1417), so docling conversion completes on Apple Silicon.

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code was added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Attribution

  • AI coding assistants used

Adding a new component, requirement, sampling strategy, or tool?

If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.

  • Component
  • Requirement
  • Sampling Strategy
  • Tool

NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.

…ed-by: IBM Bob

Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
@rafvasq
rafvasq requested a review from a team as a code owner October 26, 2026 20:00
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 26, 2026

@planetf1 planetf1 left a comment

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.

Overall this looks good, apart from the inline comments. I ran 101_with_gen_stubs.py, advanced_with_m_instruct.py, mify.py and table.py against granite4.2:3b and they run, and every ollama pull tag matches the model the script actually uses. The comments are mostly about link depth and install commands.

Separately, not for this PR: docs/docs/examples/data-extraction-pipeline.md mirrors 101_with_gen_stubs.py and still shows the model_ids import this PR removes, and it and legacy-code-integration.md tell readers to pull granite4.1:3b while the session default is granite4.2:3b. That page could do with its own pass.

Comment thread docs/examples/mify/README.md Outdated
This directory demonstrates the `@mify` decorator for making custom Python objects work seamlessly with Mellea.
Examples demonstrating the `@mify` decorator for making custom Python objects
LLM-compatible with Mellea. For a conceptual overview, see
[MObjects and mify](../../docs/docs/concepts/mobjects-and-mify.md).

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.

The link resolves one directory too deep: from docs/examples/mify/, ../../docs/docs/... lands on docs/docs/docs/..., which doesn't exist. Dropping one docs/ segment fixes it and matches the form mcp/README.md and telemetry/README.md already use.

The concepts page covers fields_include and funcs_include but has nothing on stringify_func, query_type or template_order, which the old README's advanced section and mify.py both feature. That content lives in the legacy code integration example, so a second link covers it:

Suggested change
[MObjects and mify](../../docs/docs/concepts/mobjects-and-mify.md).
[MObjects and mify](../../docs/concepts/mobjects-and-mify.md) and
[Legacy Code Integration with @mify](../../docs/examples/legacy-code-integration.md).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment thread docs/examples/mobject/README.md Outdated
Comment on lines +5 to +6
[MObjects and mify](../../docs/docs/concepts/mobjects-and-mify.md) and
[Working with Data](../../docs/docs/how-to/working-with-data.md).

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.

Same link-depth issue as the mify README, on both links:

Suggested change
[MObjects and mify](../../docs/docs/concepts/mobjects-and-mify.md) and
[Working with Data](../../docs/docs/how-to/working-with-data.md).
[MObjects and mify](../../docs/concepts/mobjects-and-mify.md) and
[Working with Data](../../docs/how-to/working-with-data.md).

Also, the old README pointed to notebooks/table_mobject.ipynb, which still exists and is the interactive version of this directory's only example. Dropping it is fine if deliberate, just confirming it was a choice; a one-line pointer would keep it discoverable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I introduced a pointer to this link in the README table.

Comment thread docs/examples/rag/README.md Outdated
This directory contains examples of implementing RAG systems with Mellea.
Examples demonstrating Retrieval-Augmented Generation (RAG) patterns in Mellea.
For a step-by-step guide to building a full pipeline, see the
[Build a RAG Pipeline](../../docs/docs/how-to/build-a-rag-pipeline.md) how-to.

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.

Same link-depth issue. This is the pointer a newcomer is most likely to follow, since the table rows assume the step-by-step guide:

Suggested change
[Build a RAG Pipeline](../../docs/docs/how-to/build-a-rag-pipeline.md) how-to.
[Build a RAG Pipeline](../../docs/how-to/build-a-rag-pipeline.md) how-to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread docs/examples/rag/README.md Outdated
| File | Description |
| :--- | :--- |
| [`simple_rag_with_filter.py`](./simple_rag_with_filter.py) | Two-stage pipeline: FAISS semantic search followed by a `@generative` relevance filter, then grounded answer generation with `grounding_context`. Requires `faiss-cpu` and `sentence-transformers`. |
| [`mellea_pdf.py`](./mellea_pdf.py) | Loading a remote PDF into a `RichDocument` component and passing it as `grounding_context` for document-grounded question answering. |

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.

Nit: the mellea_pdf.py row could say Requires docling like the mify rows, since the script's Prerequisites install it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

Comment on lines +10 to +12
Prerequisites:
ollama pull granite4.2:3b
ollama serve

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.

The Prerequisites miss a hard dependency: line 18 imports TableQuery from mellea.stdlib.components.docs.richdocument, and that module raises ImportError on a base install (its message suggests pip install "mellea[docling]"). I checked by importing it with docling absent, and it fails before any mify code runs. uv sync --extra docling covers it, and the README row could say Requires docling like its siblings.

The ollama pull before ollama serve ordering is worth a tweak as well: pull needs the server up. Something like this covers the common setups, and would be worth applying across the other new blocks too:

Suggested change
Prerequisites:
ollama pull granite4.2:3b
ollama serve
Prerequisites:
uv sync --extra docling
Ollama running (service, desktop app, or `ollama serve`)
ollama pull granite4.2:3b

@rafvasq rafvasq Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, but I kept the ollama serve command instead of the different options in the suggestion.

Comment thread docs/examples/rag/mellea_pdf.py Outdated
Comment on lines +8 to +9
uv sync --extra backends
pip install docling

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.

Same as the rich_table example: pip install docling lands outside the venv uv run uses, and the default Ollama backend means --extra backends isn't needed either:

Suggested change
uv sync --extra backends
pip install docling
uv sync --extra docling

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +14 to +15
uv sync --extra backends
pip install docling docling-core

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.

This one does need --extra backends since it runs backend_name="hf", but the pip install line has the same venv problem as the other scripts. docling-core is also redundant in the list, since docling depends on it:

Suggested change
uv sync --extra backends
pip install docling docling-core
uv sync --extra backends --extra docling

Since this is the only HF-backend script in these directories, one line saying the model downloads on first run would also explain why there's no Ollama step.

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.

Follow-up from validating the install commands by running this end to end: the script can't complete on Apple Silicon as written, regardless of install method. The layout model's position embedding is built in float64, which MPS doesn't support, and this example builds its own DocumentConverter, so it misses the CPU guard RichDocument gained in #1417 (that closed #1344 for the library paths; mellea_pdf.py runs fine through RichDocument). Root cause is upstream (huggingface/transformers#46159, tracked as docling-project/docling#3483); mellea's transformers>5.5.0,<6.0.0 override keeps 5.10.2, which still has it.

Adding the same guard here fixes it. I ran the patched script end to end on an M-series Mac and the full walkthrough completes:

from docling.datamodel.pipeline_options import (
    AcceleratorDevice,
    AcceleratorOptions,
    PdfPipelineOptions,
)

pipeline_options = PdfPipelineOptions(images_scale=2.0, generate_picture_images=True)
pipeline_options.accelerator_options = AcceleratorOptions(device=AcceleratorDevice.CPU)

Happy for this to land here or as a tiny follow-up PR, whichever you prefer. If it goes in here, a one-line note in the description would cover it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Included this patch in the script here.

Comment thread docs/examples/mobject/table.py Outdated
updating it with `m.transform()`.

Prerequisites:
pip install pandas

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.

The pandas prerequisite is right (pandas isn't a mellea dependency), but pip beside a uv run Usage line installs into a different environment than the one the script runs in. uv pip install pandas is the drop-in fix:

Suggested change
pip install pandas
uv pip install pandas

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +16 to +18
Prerequisites:
ollama pull mistral:7b
ollama serve

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.

The Prerequisites are right, but a reader who copies the uv run python ... pattern from the sibling examples gets ModuleNotFoundError: faiss, because this script's dependencies come from its PEP 723 header and only uv run (without python) resolves them. One sentence saves that trip:

Suggested change
Prerequisites:
ollama pull mistral:7b
ollama serve
Prerequisites:
ollama pull mistral:7b
ollama serve
faiss-cpu and sentence-transformers come from the PEP 723 header, so
`uv run` (without `python`) installs them automatically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

# Information Extraction Examples

This directory contains examples for extracting structured information from unstructured text using Mellea.
Examples demonstrating structured information extraction from text using Mellea.

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.

This is the only one of the four directories without a link to the site docs. The removed Basic Usage content lives in the Data Extraction Pipeline example, which also links back to 101_with_gen_stubs.py, so one link closes the loop:

Suggested change
Examples demonstrating structured information extraction from text using Mellea.
Examples demonstrating structured information extraction from text using Mellea.
For a walkthrough, see [Data Extraction Pipeline](../../docs/examples/data-extraction-pipeline.md).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
@rafvasq
rafvasq requested a review from planetf1 October 28, 2026 20:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants