Skip to content

Commit f4c314b

Browse files
committed
Add folder name filtering capabilities to documentation
1 parent d18cc72 commit f4c314b

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

concepts/user-folder-scoping.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,49 @@ async with AsyncMorphik() as db:
103103
- Scopes can be used for both reading and writing operations
104104
- User and folder information is stored as metadata with the documents, so you can still filter across scopes with explicit filter parameters if needed
105105

106+
## Filtering by Folder Name in Metadata
107+
108+
When you ingest documents in a folder with the `folder_name` parameter, that value is automatically available in the document's metadata for filtering. This enables powerful cross-folder queries using Morphik's metadata filter operators:
109+
110+
```python
111+
from morphik import Morphik
112+
113+
db = Morphik()
114+
115+
# Filter documents from multiple folders
116+
filters = {
117+
"folder_name": {"$in": ["legal", "hr", "finance"]}
118+
}
119+
docs = db.list_documents(filters=filters)
120+
121+
# Combine folder filtering with other metadata
122+
filters = {
123+
"$and": [
124+
{"folder_name": {"$regex": {"pattern": "^project_", "flags": "i"}}},
125+
{"status": "active"},
126+
{"priority": {"$gte": 70}}
127+
]
128+
}
129+
response = db.query("What are the high-priority project updates?", filters=filters)
130+
131+
# Exclude specific folders
132+
filters = {
133+
"$and": [
134+
{"folder_name": {"$nin": ["archived", "drafts"]}},
135+
{"created_date": {"$gte": "2024-01-01"}}
136+
]
137+
}
138+
chunks = db.retrieve_chunks("quarterly report", filters=filters, k=10)
139+
```
140+
141+
This approach is useful when you need to:
142+
- Query across multiple folders simultaneously
143+
- Use pattern matching on folder names
144+
- Combine folder filters with complex metadata conditions
145+
- Build dynamic queries where folder selection isn't known at scope creation time
146+
147+
For more filtering examples, see the [Complex Metadata Filtering](/cookbooks/complex-metadata-filtering) cookbook and [Metadata Filtering](/concepts/metadata-filtering) reference.
148+
106149
## Use Cases
107150

108151
### Multi-Project Research Team

cookbooks/complex-metadata-filtering.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ filters = {
9999
}
100100
```
101101

102+
### Filtering by Folder Name
103+
104+
Documents ingested with a `folder_name` parameter can be filtered using that value in metadata. This enables cross-folder queries and pattern matching:
105+
106+
```python
107+
# Filter specific folder
108+
filters = {"folder_name": "reports"}
109+
110+
# Query multiple folders
111+
filters = {
112+
"folder_name": {"$in": ["reports", "invoices", "contracts"]}
113+
}
114+
115+
# Exclude archived folders
116+
filters = {
117+
"folder_name": {"$nin": ["archived", "drafts", "test"]}
118+
}
119+
120+
# Pattern matching on folder names
121+
filters = {
122+
"folder_name": {"$regex": {"pattern": "^project_", "flags": "i"}}
123+
}
124+
125+
# Combine folder with other metadata
126+
filters = {
127+
"$and": [
128+
{"folder_name": {"$in": ["legal", "compliance"]}},
129+
{"priority": {"$gte": 70}},
130+
{"status": "active"},
131+
{"year": 2024}
132+
]
133+
}
134+
```
135+
102136
## 3. List Documents with Filters
103137

104138
Find documents matching your criteria:

python-sdk/query.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ response = db.query(
8585
)
8686
```
8787

88+
You can also filter by folder name and use expressive operators like `$in`, `$regex`, and `$nin`:
89+
90+
```python
91+
# Query across multiple folders
92+
filters = {
93+
"$and": [
94+
{"folder_name": {"$in": ["reports", "invoices"]}},
95+
{"year": 2024},
96+
{"priority": {"$gte": 50}}
97+
]
98+
}
99+
100+
response = db.query("What are the key financial highlights?", filters=filters)
101+
```
102+
103+
For more advanced filtering patterns, see the [Complex Metadata Filtering cookbook](/cookbooks/complex-metadata-filtering).
104+
88105
## Returns
89106

90107
- `CompletionResponse`: Response containing the completion, source information, and potentially structured output.

0 commit comments

Comments
 (0)