pip install mellea,
Ollama running locally. RAG examples require faiss-cpu and sentence-transformers.
RichDocument requires pip install "mellea[docling]" or docling installed separately.
Grounding context
Attach reference documents to anyinstruct() call via grounding_context. The dict
maps string keys to document text injected as reference material into the prompt:
RAG with relevance filtering
Combine vector retrieval with@generative relevance filtering for full RAG:
@generative filter returns a typed bool, giving you deterministic branching
over LLM relevance judgments.
Full example: docs/examples/rag/simple_rag_with_filter.py
MObjects — making data LLM-aware
The@mify decorator wraps any Python class so Mellea sessions can query and
transform its instances. This is the MObject pattern: store data alongside the
operations that apply to it, and expose both to the LLM in a controlled way.
fields_include controls which fields are visible to the LLM. template controls
how the object is formatted in the prompt.
Full example: docs/examples/tutorial/table_mobject.py
query() and transform()
m.query() asks a question about an MObject. m.transform() asks the model to
produce a modified version:
transform(). The LLM can call transpose() directly rather than generating the
transformation from scratch.
Mifying an existing object ad-hoc
You can mify any existing object at call time without decorating the class:Custom stringify
By default, mified objects use__str__. Override with stringify_func:
Controlling exposed methods
Usefuncs_include or funcs_exclude to control which methods the LLM can call:
RichDocument — working with PDFs and structured documents
Backend note:RichDocumentrequires thedoclinglibrary:pip install docling. First-time use downloads parser models.
RichDocument loads and parses PDFs and other documents into a Mellea-ready
structure, including extractable tables:
Table is itself an MObject — its methods (e.g., transpose()) are registered as
tools during transform() calls automatically.
Full example: docs/examples/tutorial/document_mobject.py
See also: act() and aact() | MObjects and mify