memory-metadata-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemory Metadata Search
Memory元数据搜索
Find notes by their structured frontmatter fields instead of (or in addition to) free-text content. Any custom YAML key in a note's frontmatter beyond the standard set (, , , , ) is automatically indexed as and becomes queryable.
titletypetagspermalinkschemaentity_metadata通过结构化前置元数据字段查找笔记,可替代或结合自由文本内容搜索。笔记前置元数据中,除标准字段(、、、、)外的任何自定义YAML键,都会自动被索引为并支持查询。
titletypetagspermalinkschemaentity_metadataWhen to Use
使用场景
- Filtering by status or priority — find all notes with or
status: draftpriority: high - Querying custom fields — any frontmatter key you invent is searchable
- Range queries — find notes with or
confidence > 0.7score between 0.3 and 0.8 - Combining text + metadata — narrow a text search with structured constraints
- Tag-based filtering — find notes tagged with specific frontmatter tags
- Schema-aware queries — filter by nested schema fields using dot notation
- 按状态或优先级筛选 — 查找所有带有或
status: draft的笔记priority: high - 查询自定义字段 — 你自定义的任何前置元数据键都可搜索
- 范围查询 — 查找或
confidence > 0.7在0.3到0.8之间的笔记score - 文本+元数据组合查询 — 用结构化约束缩小文本搜索范围
- 基于标签的筛选 — 查找带有特定前置元数据标签的笔记
- 感知Schema的查询 — 使用点符号筛选嵌套Schema字段
The Tool
工具说明
All metadata searching uses . Pass filters via , or use the and convenience shortcuts. Omit (or pass ) for filter-only searches.
search_notesmetadata_filterstagsstatusqueryNone所有元数据搜索都使用函数。通过传入筛选器,或使用和快捷方式。省略(或传入)即可仅使用筛选器进行搜索。
search_notesmetadata_filterstagsstatusqueryNoneFilter Syntax
筛选器语法
Filters are a JSON dictionary. Each key targets a frontmatter field; the value specifies the match condition. Multiple keys combine with AND logic.
筛选器是一个JSON字典。每个键对应一个前置元数据字段;值指定匹配条件。多个键之间为AND逻辑关系。
Equality
相等匹配
json
{"status": "active"}json
{"status": "active"}Array Contains (all listed values must be present)
数组包含(需包含所有列出的值)
json
{"tags": ["security", "oauth"]}json
{"tags": ["security", "oauth"]}$in
(match any value in list)
$in$in
(匹配列表中的任意值)
$injson
{"priority": {"$in": ["high", "critical"]}}json
{"priority": {"$in": ["high", "critical"]}}Comparisons ($gt
, $gte
, $lt
, $lte
)
$gt$gte$lt$lte比较运算($gt
, $gte
, $lt
, $lte
)
$gt$gte$lt$ltejson
{"confidence": {"$gt": 0.7}}Numeric values use numeric comparison; strings use lexicographic comparison.
json
{"confidence": {"$gt": 0.7}}数值使用数值比较;字符串使用字典序比较。
$between
(inclusive range)
$between$between
(包含范围)
$betweenjson
{"score": {"$between": [0.3, 0.8]}}json
{"score": {"$between": [0.3, 0.8]}}Nested Access (dot notation)
嵌套访问(点符号)
json
{"schema.version": "2"}json
{"schema.version": "2"}Quick Reference
速查表
| Operator | Syntax | Example |
|---|---|---|
| Equality | | |
| Array contains | | |
| | |
| | |
| | |
| | |
| Nested | | |
Rules:
- Keys must match (dots separate nesting levels)
[A-Za-z0-9_-]+ - Operator dicts must contain exactly one operator
- and array-contains require non-empty lists
$in - requires exactly
$between[min, max]
Warning: Operators MUST include theprefix — write$, not$gte. Without the prefix the filter is treated as an exact-match key and will silently return no results. Correct:gte. Wrong:{"confidence": {"$gte": 0.7}}.{"confidence": {"gte": 0.7}}
| 运算符 | 语法 | 示例 |
|---|---|---|
| 相等匹配 | | |
| 数组包含 | | |
| | |
| | |
| | |
| | |
| 嵌套访问 | | |
规则:
- 键必须匹配(点符号用于分隔嵌套层级)
[A-Za-z0-9_-]+ - 运算符字典必须恰好包含一个运算符
- 和数组包含要求列表非空
$in - 要求恰好为
$between格式[min, max]
注意: 运算符必须包含前缀 — 请写$而非$gte。如果没有前缀,筛选器会被当作精确匹配的键处理,且会静默返回空结果。正确写法:gte。错误写法:{"confidence": {"$gte": 0.7}}。{"confidence": {"gte": 0.7}}
Using search_notes
with Metadata
search_notes结合元数据使用search_notes
search_notesPass , , or to . Omit for filter-only searches, or combine text and filters together.
metadata_filterstagsstatussearch_notesquerypython
undefined向传入、或。省略即可仅使用筛选器搜索,也可将文本搜索与筛选器结合使用。
search_notesmetadata_filterstagsstatusquerypython
undefinedFilter-only — find all notes with a given status
仅筛选 — 查找所有带有指定状态的笔记
search_notes(metadata_filters={"status": "in-progress"})
search_notes(metadata_filters={"status": "in-progress"})
Filter-only — high-priority specs in a specific project
仅筛选 — 特定项目中的高优先级规格文档
search_notes(
metadata_filters={"type": "spec", "priority": {"$in": ["high", "critical"]}},
project="research",
page_size=10,
)
search_notes(
metadata_filters={"type": "spec", "priority": {"$in": ["high", "critical"]}},
project="research",
page_size=10,
)
Filter-only — notes with confidence above a threshold
仅筛选 — 可信度超过阈值的笔记
search_notes(metadata_filters={"confidence": {"$gt": 0.7}})
search_notes(metadata_filters={"confidence": {"$gt": 0.7}})
Convenience shortcuts for tags and status
tags和status的快捷方式
search_notes(status="active")
search_notes(tags=["security", "oauth"])
search_notes(status="active")
search_notes(tags=["security", "oauth"])
Text search narrowed by metadata
结合文本搜索与元数据筛选
search_notes("authentication", metadata_filters={"status": "draft"})
search_notes("authentication", metadata_filters={"status": "draft"})
Mix text, tag shortcut, and advanced filter
混合文本搜索、标签快捷方式和高级筛选器
search_notes(
"oauth flow",
tags=["security"],
metadata_filters={"confidence": {"$gt": 0.7}},
)
**Merging rules:** `tags` and `status` are convenience shortcuts merged into `metadata_filters` via `setdefault`. If the same key exists in `metadata_filters`, the explicit filter wins.search_notes(
"oauth flow",
tags=["security"],
metadata_filters={"confidence": {"$gt": 0.7}},
)
**合并规则:** `tags`和`status`是快捷方式,会通过`setdefault`合并到`metadata_filters`中。如果`metadata_filters`中存在相同的键,则显式指定的筛选器优先级更高。Tag Search Shorthand
标签搜索简写
The prefix in a query converts to a tag filter automatically:
tag:python
undefined查询中的前缀会自动转换为标签筛选器:
tag:python
undefinedThese are equivalent:
以下两种写法等价:
search_notes("tag:tier1")
search_notes("", tags=["tier1"])
search_notes("tag:tier1")
search_notes("", tags=["tier1"])
Multiple tags (comma or space separated) — all must match:
多个标签(逗号或空格分隔)—— 必须同时匹配:
search_notes("tag:tier1,alpha")
undefinedsearch_notes("tag:tier1,alpha")
undefinedExample: Custom Frontmatter in Practice
示例:自定义前置元数据的实际应用
A note with custom fields:
markdown
---
title: Auth Design
type: spec
tags: [security, oauth]
status: in-progress
priority: high
confidence: 0.85
---带有自定义字段的笔记:
markdown
---
title: Auth Design
type: spec
tags: [security, oauth]
status: in-progress
priority: high
confidence: 0.85
---Auth Design
Auth Design
Observations
观察结果
- [decision] Use OAuth 2.1 with PKCE for all client types #security
- [requirement] Token refresh must be transparent to the user
- [决策] 对所有客户端类型使用带有PKCE的OAuth 2.1 #security
- [需求] Token刷新需对用户透明
Relations
关联内容
- implements [[Security Requirements]]
Queries that find it:
```python- 实现 [[Security Requirements]]
可找到该笔记的查询示例:
```pythonBy status and type
按状态和类型筛选
search_notes(metadata_filters={"status": "in-progress", "type": "spec"})
search_notes(metadata_filters={"status": "in-progress", "type": "spec"})
By numeric threshold
按数值阈值筛选
search_notes(metadata_filters={"confidence": {"$gt": 0.7}})
search_notes(metadata_filters={"confidence": {"$gt": 0.7}})
By priority set
按优先级集合筛选
search_notes(metadata_filters={"priority": {"$in": ["high", "critical"]}})
search_notes(metadata_filters={"priority": {"$in": ["high", "critical"]}})
By tag shorthand
通过标签简写搜索
search_notes("tag:security")
search_notes("tag:security")
Combined text + metadata
结合文本搜索与元数据筛选
search_notes("OAuth", metadata_filters={"status": "in-progress"})
undefinedsearch_notes("OAuth", metadata_filters={"status": "in-progress"})
undefinedGuidelines
使用指南
- Use metadata search for structured queries. If you're looking for notes by a known field value (status, priority, type), metadata filters are more precise than text search.
- Use text search for content queries. If you're looking for notes about something, text search is better. Combine both when you need precision.
- Custom fields are free. Any YAML key you put in frontmatter becomes queryable — no schema or configuration required.
- Multiple filters are AND. requires both conditions.
{"status": "active", "priority": "high"} - Omit for filter-only searches.
queryworks without a text query.search_notes(metadata_filters={"status": "active"}) - Dot notation for nesting. Access nested YAML structures with dots: queries the
{"schema.version": "2"}key inside aversionobject.schema - Tags shortcut is convenient but limited. and
tagsare sugar for common fields. For anything else, usestatusdirectly.metadata_filters
- 结构化查询使用元数据搜索。如果你需要通过已知字段值(状态、优先级、类型)查找笔记,元数据筛选器比文本搜索更精准。
- 内容查询使用文本搜索。如果你需要查找与某主题相关的笔记,文本搜索更合适。当需要精准结果时,可结合两者使用。
- 自定义字段不受限制。你添加到前置元数据中的任何YAML键都支持查询 — 无需配置Schema或进行其他设置。
- 多个筛选器为AND关系。要求同时满足两个条件。
{"status": "active", "priority": "high"} - 仅筛选搜索可省略。
query无需文本查询即可生效。search_notes(metadata_filters={"status": "active"}) - 嵌套结构使用点符号。使用点符号访问嵌套YAML结构:用于查询
{"schema.version": "2"}对象中的schema键。version - 标签快捷方式便捷但有局限。和
tags是针对常见字段的语法糖。对于其他字段,请直接使用status。metadata_filters