Long-Video Memory
Check the qwen-mm-plugins-video-memory tools in your tool list for full schemas and parameters.
ROUTING RULE — Read This First
When a user asks about a video that is longer than 30 minutes, you MUST use this skill instead of read_video. read_video cannot meaningfully cover a multi-hour video — it samples too few frames once, which is ineffective and always misses important content. You MUST build memory first, then you can fast explore the whole long video with the help of your pre-built memory.
Workflow:
- Check if
<video_path>.memory/ directory exists
- Memory exists → query it using the
qwen-mm-plugins-video-memory tools
- Memory does not exist → build it first (see "Building Graph Memory" section), then query
- After locating a specific segment via memory tools, you MUST use
read_video with a narrow start_time/end_time for frame-level visual inspection, because memory is always coarse and maybe inaccurate.
Hierarchical Graph Memory
The memory is a 4-level tree. You start broad (Root/SuperEvent) and drill down to find specifics:
Root (1 per video)
└─ SuperEvent (10-20 story arcs)
└─ MacroEvent (3-8 per SuperEvent, each ~3-8 min)
└─ Subgraph (entities, events, OCR text, relations)
Level Details
| Level |
Contains |
IDs |
| Root |
Title, description, themes, key entities, emotional tone |
— |
| SuperEvent |
High-level narrative arc, time range, key entities |
super_01, super_02, ... |
| MacroEvent |
Specific event segment with time range, summary, key entities |
macro_0001, macro_0002, ... |
| Subgraph |
Entity nodes (PERSON/OBJECT/LOCATION), Event nodes (timestamped actions), OCR text (on-screen text), and Edges (SEMANTIC/CAUSAL/TEMPORAL/HIERARCHICAL/SPATIAL/IDENTITY relations) |
macro_0001:ent_001, ... |
Building Graph Memory
If graph_memory.json is missing, run the builder below. It installs missing Python dependencies,
including pydantic>=2.11,<3.
When building a new memory, honor an explicitly requested backend. Otherwise:
- Prefer
--retrieval-backend zvec for large or growing memories and multi-video
merges, so the full-text index is persisted rather than rebuilt on load.
- Keep NPZ (the default, or
--retrieval-backend npz) for small, standalone
memories without an expected growth requirement.
# Build memory for a single video (output: <video_path>.memory/)
bash script/build_memory/build_memory.sh /path/to/video.mp4
# Build with custom options
bash script/build_memory/build_memory.sh /path/to/video.mp4 \
--output-dir /path/to/output --model qwen3.7-plus --api-key "$DASHSCOPE_API_KEY"
# Build a persistent zvec vector/scalar/full-text collection
bash script/build_memory/build_memory.sh /path/to/video.mp4 --retrieval-backend zvec
# Merge per-video memories in one directory into one memory and one zvec collection
python script/build_memory/merge_memories.py /path/to/video-dir --retrieval-backend zvec
Retrieval Workflow
Most questions follow a 2-step pattern:
Step 1: Locate (find the right macro_id)
Choose ONE entry point based on the question type:
| Question Type |
Entry Tool |
Example |
| References a specific time |
search_by_time(start_sec, end_sec) |
"What happens at 45:30?" |
| Asks about a person/action/event |
search_nodes(query) |
"What did the chef cook?" |
| Asks about on-screen text/scores |
search_ocr_text(query) |
"What was the final score?" |
| References a known story segment |
get_macro_events(super_id) |
"In the first quarter..." |
| Asks about event causality |
search_nodes(query) → get_subgraph |
"What caused the explosion?" |
Step 2: Drill Down (get full detail)
Call get_subgraph(macro_id) on the 1-2 most relevant macro_ids from Step 1. This returns ALL detail: entities, events, OCR text, and relations. Answer from this data.
Decision Flow
Question arrives
├─ Does the SuperEvent list already narrow it? → get_macro_events(super_id) → get_subgraph
├─ Time reference? → search_by_time → get_subgraph
├─ On-screen text/score? → search_ocr_text → get_subgraph (if needed)
├─ Person/action/event? → search_nodes → get_subgraph
└─ Causal/relational? → search_nodes → get_subgraph (relations are in the subgraph)
Tools Reference
Navigation (hierarchy drill-down)
get_summary — Video-level root summary.
- Params:
video_path (optional)
- Returns: title, description, themes, key entities, emotional tone
- Use when: you need a quick overview before drilling down
get_super_events — List all SuperEvents (high-level narrative arcs).
- Params:
video_path (optional)
- Returns: super_id, label, time_range, key_entities, description, num_macros
- Use when: you need the overall structure or to pick the relevant story arc
get_macro_events — List MacroEvents under a SuperEvent.
- Params:
super_id (optional), macro_ids (optional list)
- Returns: macro_id, time_range, label, key_entity_names, description
- Use when: initial context already narrows the segment
get_subgraph — Full detail for one MacroEvent. Most information-rich tool.
- Params:
macro_id (required)
- Returns: Entities, Events, OCR texts, Relations
- Use when: you have a macro_id and need specifics
Search (direct access)
search_nodes — Semantic search over Entity and Event nodes (excludes OCR).
- Params:
query (required), top_k, node_types (["event"], ["entity"], or both)
- Query guide: write a DESCRIPTIVE STATEMENT, not a question
- Good: "A player scores with an alley-oop dunk"
- Bad: "Which player scored the alley-oop?"
- For multi-choice: extract SHARED info across options, exclude differing details
search_ocr_text — Semantic search over on-screen text only.
- Params:
query (required), top_k
- Use for: scores, stats, jersey numbers, broadcast graphics
- Do NOT use search_nodes for OCR content — they are separate indexes
search_asr_text — Semantic search over ASR transcript text (speech, dialogue, narration).
- Params:
query (required), top_k
- Use for: spoken content, dialogue, narration, or other audio/verbal information
search_by_time — Find MacroEvents by time range.
- Params:
start_sec/end_sec (seconds), or start_time/end_time (HH:MM:SS for ordinary videos;
DAY{N} HH:MM:SS for EgoLife). Valid strings override the corresponding seconds.
- Invalid timestamps and reversed ranges return an error.
- Returns summaries only — follow up with get_subgraph for detail
enumerate_events — Enumerate ALL matching event instances in time order — built for COUNTING / "how many times / list every occurrence" questions.
- Params:
query (required; a descriptive statement of the target event), min_cosine, max_results, node_types (default ["event"]; use ["entity"] for objects/people)
- Unlike search_nodes (top-k best matches), returns every match above a similarity threshold, deduped and sorted by start time
- If undercounting, retry with a lower
min_cosine and alternative phrasings
Video Frame Extraction
read_video — Extract frames from the original video after narrowing the time range via memory tools. video_path is in the initial context.
Anti-Patterns (common mistakes)
- Answering from SuperEvent descriptions — these are summaries. Always get_subgraph for specific details.
- Repeating similar searches — if search_nodes found macro_0022, call get_subgraph(macro_0022) instead of searching with a slightly different query.
- Ignoring tool types — if search_nodes gives poor results, try search_ocr_text or search_by_time. Different indexes cover different content.
- Guessing counts — for "how many" questions, get_subgraph and count from the explicit node list. Never estimate from words like "several" or "multiple".
- Skipping tool calls — never answer without querying the memory graph first, even if the question seems simple.
Storage
Graph memory is stored next to the video, in <video_path>.memory/ (e.g.
/data/clip.mp4 → /data/clip.mp4.memory/). The server auto-loads it from there
when you pass video_path, or set GRAPH_MEMORY_PATH to point at one explicitly.
Contents: graph_memory.json, embeddings.npz or embeddings.zvec/,
01_macros.json, subgraphs/
Efficiency Rules
- Maximum 10 tool call rounds — use them wisely
- Most questions need: 1 search + 1-2 get_subgraph calls
- Always drill down before giving up — the answer is in the subgraph, not the summary
Ver o texto completo da licença (Apache-2.0)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.