ref() function connects documents together. It fetches content from another document while registering a dependency edge in Colin’s compilation graph.
Colin uses these dependency edges to compile documents in the correct order and rebuild only what changes.
Basic Usage
Callref() with a document’s URI to get its compiled content:
models/product-brief.md
company and products/main compile first. The .content property contains each document’s full compiled output.
What ref() Returns
Theref() function returns a RefResult object, not a raw string. This object carries metadata alongside the content:
| Property | Type | Description |
|---|---|---|
content | str | The compiled document output |
name | str | Document name from frontmatter (or filename) |
description | str | None | Description from frontmatter |
template | str | Raw source template before compilation |
updated | datetime | When the document was last compiled |
uri | str | The document’s URI |
source | object | None | Original domain object (for provider resources) |
models/index.md
String Conversion
When you use aRefResult directly in a string context (like {{ ref('doc') }}), it returns a placeholder rather than the full content. This prevents accidentally dumping large documents:
Ref('company')
Always use .content to get the actual content:
Dependency Registration
Everyref() call registers a dependency edge. Colin tracks these edges to:
- Order compilation - Referenced documents compile before their dependents
- Detect changes - When a document changes, Colin recompiles all dependents
- Build lineage - The manifest records the full dependency graph
company.md changes, Colin recompiles all three. If only sales-deck.md changes, only it recompiles.
Using with Filters
Combineref() with filters to transform referenced content:
models/summary.md
extract() filter passes the RefResult through an LLM with your prompt. Since RefResult knows its content, the filter can access what it needs.
Other useful patterns:
URI Resolution
URIs are relative paths from yourmodels/ directory, without the .md extension:
| File | URI to Reference |
|---|---|
models/overview.md | ref('overview') |
models/team/leads.md | ref('team/leads') |
models/reports/2024/q1.md | ref('reports/2024/q1') |
Referencing Provider Objects
Beyond URI strings,ref() can also accept objects from providers like MCP. Provider functions return domain objects that can be passed directly to ref() for dependency tracking:
models/sources/project-data.md
ref() function:
- Calls the object’s
to_ref_result()method to convert it - Records the dependency in the manifest
- Returns a standard
RefResult
When to Use ref() with Provider Objects
Useref() when you want Colin to track the resource as a dependency:
ref() when you just want the content without tracking:
Accessing the Original Object
When you useref() with a provider object, the original domain object is preserved in the .source property:
models/analysis.md
.source property is the escape hatch for accessing any custom fields the provider adds to its domain objects.