Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions concepts/user-folder-scoping.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: 'User and Folder Scoping'
description: 'Organizing data with user and folder scoping in Morphik'

Check warning on line 3 in concepts/user-folder-scoping.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

concepts/user-folder-scoping.mdx#L3

Did you really mean 'Morphik'?
---

Morphik provides powerful mechanisms to organize and isolate your data through **user scoping** and **folder scoping**. These features allow you to create logical boundaries for different projects or user groups while maintaining a unified database.

Check warning on line 6 in concepts/user-folder-scoping.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

concepts/user-folder-scoping.mdx#L6

Did you really mean 'Morphik'?

## Folder Scoping

Folders in Morphik allow you to organize documents into logical groups, similar to directories in a file system, but for your unstructured data. Operations performed within a folder scope only affect documents within that folder.

Check warning on line 10 in concepts/user-folder-scoping.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

concepts/user-folder-scoping.mdx#L10

Did you really mean 'Morphik'?

### When to Use Folder Scoping

Expand Down Expand Up @@ -97,12 +97,55 @@

## Important Considerations

- All methods available on the main Morphik client are also available on folder and user scopes

Check warning on line 100 in concepts/user-folder-scoping.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

concepts/user-folder-scoping.mdx#L100

Did you really mean 'Morphik'?
- Operations performed within a scope are isolated to that scope
- Documents created within a scope are only accessible within that scope, unless explicitly queried with appropriate filters
- Scopes can be used for both reading and writing operations
- User and folder information is stored as metadata with the documents, so you can still filter across scopes with explicit filter parameters if needed

## Filtering by Folder Name in Metadata

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:

Check warning on line 108 in concepts/user-folder-scoping.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

concepts/user-folder-scoping.mdx#L108

Did you really mean 'Morphik's'?

```python
from morphik import Morphik

db = Morphik()

# Filter documents from multiple folders
filters = {
"folder_name": {"$in": ["legal", "hr", "finance"]}
}
docs = db.list_documents(filters=filters)

# Combine folder filtering with other metadata
filters = {
"$and": [
{"folder_name": {"$regex": {"pattern": "^project_", "flags": "i"}}},
{"status": "active"},
{"priority": {"$gte": 70}}
]
}
response = db.query("What are the high-priority project updates?", filters=filters)

# Exclude specific folders
filters = {
"$and": [
{"folder_name": {"$nin": ["archived", "drafts"]}},
{"created_date": {"$gte": "2024-01-01"}}
]
}
chunks = db.retrieve_chunks("quarterly report", filters=filters, k=10)
```

This approach is useful when you need to:
- Query across multiple folders simultaneously
- Use pattern matching on folder names
- Combine folder filters with complex metadata conditions
- Build dynamic queries where folder selection isn't known at scope creation time

For more filtering examples, see the [Complex Metadata Filtering](/cookbooks/complex-metadata-filtering) cookbook and [Metadata Filtering](/concepts/metadata-filtering) reference.

## Use Cases

### Multi-Project Research Team
Expand Down
34 changes: 34 additions & 0 deletions cookbooks/complex-metadata-filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
description: "Advanced document filtering using dates, arrays, decimals, and multiple operators for precise retrieval."
---

This cookbook demonstrates Morphik's advanced metadata filtering capabilities with rich typed metadata fields including dates, decimals, booleans, arrays, and nested objects.

Check warning on line 6 in cookbooks/complex-metadata-filtering.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

cookbooks/complex-metadata-filtering.mdx#L6

Did you really mean 'Morphik's'?

Check warning on line 6 in cookbooks/complex-metadata-filtering.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

cookbooks/complex-metadata-filtering.mdx#L6

Did you really mean 'booleans'?

> **Prerequisites**
> - Install the Morphik SDK: `pip install morphik`

Check warning on line 9 in cookbooks/complex-metadata-filtering.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

cookbooks/complex-metadata-filtering.mdx#L9

Did you really mean 'Morphik'?
> - Provide credentials via Morphik URI

Check warning on line 10 in cookbooks/complex-metadata-filtering.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

cookbooks/complex-metadata-filtering.mdx#L10

Did you really mean 'Morphik'?
> - Basic understanding of document ingestion

## 1. Ingest Documents with Rich Typed Metadata

Morphik supports various metadata types for sophisticated filtering:

Check warning on line 15 in cookbooks/complex-metadata-filtering.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

cookbooks/complex-metadata-filtering.mdx#L15

Did you really mean 'Morphik'?

```python
from datetime import date, datetime, timezone
Expand Down Expand Up @@ -99,6 +99,40 @@
}
```

### 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:

```python
# Filter specific folder
filters = {"folder_name": "reports"}

# Query multiple folders
filters = {
"folder_name": {"$in": ["reports", "invoices", "contracts"]}
}

# Exclude archived folders
filters = {
"folder_name": {"$nin": ["archived", "drafts", "test"]}
}

# Pattern matching on folder names
filters = {
"folder_name": {"$regex": {"pattern": "^project_", "flags": "i"}}
}

# Combine folder with other metadata
filters = {
"$and": [
{"folder_name": {"$in": ["legal", "compliance"]}},
{"priority": {"$gte": 70}},
{"status": "active"},
{"year": 2024}
]
}
```

## 3. List Documents with Filters

Find documents matching your criteria:
Expand Down Expand Up @@ -222,4 +256,4 @@
## Related Cookbooks

- [Generating Completions with Retrieved Chunks](./generating-completions-with-retrieved-chunks) - Send filtered chunks to OpenAI
- [Python SDK Basic Operations](./python-basic-operations) - Core Morphik operations

Check warning on line 259 in cookbooks/complex-metadata-filtering.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

cookbooks/complex-metadata-filtering.mdx#L259

Did you really mean 'Morphik'?
17 changes: 17 additions & 0 deletions python-sdk/query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
query: str,
filters: Optional[Dict[str, Any]] = None,
k: int = 4,
min_score: float = 0.0,

Check warning on line 17 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L17

Did you really mean 'min_score'?
max_tokens: Optional[int] = None,

Check warning on line 18 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L18

Did you really mean 'max_tokens'?
temperature: Optional[float] = None,
use_colpali: bool = True,

Check warning on line 20 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L20

Did you really mean 'use_colpali'?
graph_name: Optional[str] = None,

Check warning on line 21 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L21

Did you really mean 'graph_name'?
hop_depth: int = 1,

Check warning on line 22 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L22

Did you really mean 'hop_depth'?
include_paths: bool = False,

Check warning on line 23 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L23

Did you really mean 'include_paths'?
prompt_overrides: Optional[Union[QueryPromptOverrides, Dict[str, Any]]] = None,

Check warning on line 24 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L24

Did you really mean 'prompt_overrides'?
schema: Optional[Union[Type[BaseModel], Dict[str, Any]]] = None,
llm_config: Optional[Dict[str, Any]] = None,

Check warning on line 26 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L26

Did you really mean 'llm_config'?
) -> CompletionResponse
```
</Tab>
Expand All @@ -33,16 +33,16 @@
query: str,
filters: Optional[Dict[str, Any]] = None,
k: int = 4,
min_score: float = 0.0,

Check warning on line 36 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L36

Did you really mean 'min_score'?
max_tokens: Optional[int] = None,

Check warning on line 37 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L37

Did you really mean 'max_tokens'?
temperature: Optional[float] = None,
use_colpali: bool = True,

Check warning on line 39 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L39

Did you really mean 'use_colpali'?
graph_name: Optional[str] = None,

Check warning on line 40 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L40

Did you really mean 'graph_name'?
hop_depth: int = 1,

Check warning on line 41 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L41

Did you really mean 'hop_depth'?
include_paths: bool = False,

Check warning on line 42 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L42

Did you really mean 'include_paths'?
prompt_overrides: Optional[Union[QueryPromptOverrides, Dict[str, Any]]] = None,

Check warning on line 43 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L43

Did you really mean 'prompt_overrides'?
schema: Optional[Union[Type[BaseModel], Dict[str, Any]]] = None,
llm_config: Optional[Dict[str, Any]] = None,

Check warning on line 45 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L45

Did you really mean 'llm_config'?
) -> CompletionResponse
```
</Tab>
Expand All @@ -61,7 +61,7 @@
- `hop_depth` (int, optional): Number of relationship hops to traverse in the graph (1-3). Defaults to 1.
- `include_paths` (bool, optional): Whether to include relationship paths in the response. Defaults to False.
- `prompt_overrides` (QueryPromptOverrides | Dict[str, Any], optional): Optional customizations for entity extraction, resolution, and query prompts
- `schema` (Type[BaseModel] | Dict[str, Any], optional): Optional schema for structured output, can be a Pydantic model or a JSON schema dict

Check warning on line 64 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L64

Did you really mean 'Pydantic'?
- `llm_config` (Dict[str, Any], optional): Optional LiteLLM-compatible model configuration (e.g., model name, API key, base URL). Allows overriding the default LLM configuration on a per-query basis. Defaults to None.

## Metadata Filters
Expand All @@ -85,6 +85,23 @@
)
```

You can also filter by folder name and use expressive operators like `$in`, `$regex`, and `$nin`:

```python
# Query across multiple folders
filters = {
"$and": [
{"folder_name": {"$in": ["reports", "invoices"]}},
{"year": 2024},
{"priority": {"$gte": 50}}
]
}

response = db.query("What are the key financial highlights?", filters=filters)
```

For more advanced filtering patterns, see the [Complex Metadata Filtering cookbook](/cookbooks/complex-metadata-filtering).

## Returns

- `CompletionResponse`: Response containing the completion, source information, and potentially structured output.
Expand All @@ -96,7 +113,7 @@
<Tabs>
<Tab title="Sync">
```python
from morphik import Morphik

Check warning on line 116 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L116

Did you really mean 'morphik'?

db = Morphik()

Expand All @@ -115,7 +132,7 @@
</Tab>
<Tab title="Async">
```python
from morphik import AsyncMorphik

Check warning on line 135 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L135

Did you really mean 'morphik'?

async with AsyncMorphik() as db:
response = await db.query(
Expand All @@ -138,7 +155,7 @@
<Tabs>
<Tab title="Sync">
```python
from morphik import Morphik

Check warning on line 158 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L158

Did you really mean 'morphik'?

db = Morphik()

Expand All @@ -160,7 +177,7 @@
</Tab>
<Tab title="Async">
```python
from morphik import AsyncMorphik

Check warning on line 180 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L180

Did you really mean 'morphik'?

async with AsyncMorphik() as db:
# Knowledge graph enhanced query
Expand All @@ -186,7 +203,7 @@
<Tabs>
<Tab title="Sync">
```python
from morphik import Morphik

Check warning on line 206 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L206

Did you really mean 'morphik'?
from morphik.models import QueryPromptOverride, QueryPromptOverrides

db = Morphik()
Expand Down Expand Up @@ -218,7 +235,7 @@
</Tab>
<Tab title="Async">
```python
from morphik import AsyncMorphik

Check warning on line 238 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L238

Did you really mean 'morphik'?
from morphik.models import QueryPromptOverride, EntityExtractionPromptOverride, QueryPromptOverrides

async with AsyncMorphik() as db:
Expand Down Expand Up @@ -275,7 +292,7 @@
<Tabs>
<Tab title="Sync">
```python
from morphik import Morphik

Check warning on line 295 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L295

Did you really mean 'morphik'?

db = Morphik()

Expand Down Expand Up @@ -307,7 +324,7 @@
</Tab>
<Tab title="Async">
```python
from morphik import AsyncMorphik

Check warning on line 327 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L327

Did you really mean 'morphik'?

async with AsyncMorphik() as db:
# Use GPT-4 for a specific query
Expand Down Expand Up @@ -340,13 +357,13 @@

### Using Structured Output

Use the `schema` parameter to get the completion response in a structured format according to a Pydantic model or a JSON schema dictionary.

Check warning on line 360 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L360

Did you really mean 'Pydantic'?

<Tabs>
<Tab title="Sync">
```python
from morphik import Morphik

Check warning on line 365 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L365

Did you really mean 'morphik'?
from pydantic import BaseModel

Check warning on line 366 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L366

Did you really mean 'pydantic'?
from typing import List

# Define the desired output structure
Expand Down Expand Up @@ -386,8 +403,8 @@
</Tab>
<Tab title="Async">
```python
from morphik import AsyncMorphik

Check warning on line 406 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L406

Did you really mean 'morphik'?
from pydantic import BaseModel

Check warning on line 407 in python-sdk/query.mdx

View check run for this annotation

Mintlify / Mintlify Validation (databridge) - vale-spellcheck

python-sdk/query.mdx#L407

Did you really mean 'pydantic'?
from typing import List

# Define the desired output structure
Expand Down