Skip to main content
This cookbook demonstrates Morphik’s advanced metadata filtering capabilities with rich typed metadata fields including dates, decimals, booleans, arrays, and nested objects.
Prerequisites
  • Install the Morphik SDK: pip install morphik
  • Provide credentials via Morphik URI
  • Basic understanding of document ingestion

1. Ingest Documents with Rich Typed Metadata

Morphik supports various metadata types for sophisticated filtering:

2. Build Complex Filters

Combine multiple operators to create sophisticated queries:

Filtering by Folder Name

Documents ingested with a folder_name parameter can be filtered using that value in metadata. This enables cross-folder queries and pattern matching:

3. List Documents with Filters

Find documents matching your criteria:

4. Retrieve Chunks with Filters

Get document chunks that match your metadata filters:

Supported Filter Operators

Use Cases

Complex metadata filtering is ideal for:
  • Document management systems with multi-dimensional categorization
  • Compliance and audit systems requiring date-based queries
  • Scientific data repositories with measurements and precise numerical filtering
  • Multi-tenant applications with scope-based isolation
  • Time-series document collections with date range queries
  • Hierarchical data with nested metadata structures

Best Practices

1. Use Appropriate Types

Use the correct Python types for metadata:

2. Convert Dates for Filtering

Always convert date objects to ISO format when building filters:

3. Combine Operators Strategically

  • Use $and for required conditions that must all match
  • Use $in when a field can have multiple possible values
  • Use range operators ($gte, $lte) for numerical and date filtering
  • Use $contains for array membership checks

4. Index Important Fields

Frequently filtered fields benefit from proper indexing. Consider performance when adding many metadata fields.

Running the Example