repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Export Stored Memories |
| #3 | description: "Retrieve, review, and migrate user memories with structured exports." |
| #4 | --- |
| #5 | |
| #6 | |
| #7 | Mem0 is a dynamic memory store that gives you full control over your data. Along with storing memories, it gives you the ability to retrieve, export, and migrate your data whenever you need. |
| #8 | |
| #9 | This cookbook shows you how to retrieve and export your data for inspection, migration, or compliance. |
| #10 | |
| #11 | --- |
| #12 | |
| #13 | ## Setup |
| #14 | |
| #15 | ```python |
| #16 | from mem0 import MemoryClient |
| #17 | |
| #18 | client = MemoryClient(api_key="your-api-key") |
| #19 | |
| #20 | ``` |
| #21 | |
| #22 | <Note> |
| #23 | Your API key needs export permissions to download memory data. Check your project settings on the [dashboard](https://app.mem0.ai) if export operations fail with authentication errors. |
| #24 | </Note> |
| #25 | |
| #26 | Let's add some sample memories to work with: |
| #27 | |
| #28 | ```python |
| #29 | # Dev's work history |
| #30 | client.add( |
| #31 | "Dev works at TechCorp as a senior engineer", |
| #32 | user_id="dev", |
| #33 | metadata={"type": "professional"} |
| #34 | ) |
| #35 | |
| #36 | # Arjun's preferences |
| #37 | client.add( |
| #38 | "Arjun prefers morning meetings and async communication", |
| #39 | user_id="arjun", |
| #40 | metadata={"type": "preference"} |
| #41 | ) |
| #42 | |
| #43 | # Carl's project notes |
| #44 | client.add( |
| #45 | "Carl is leading the API redesign project, targeting Q2 launch", |
| #46 | user_id="carl", |
| #47 | metadata={"type": "project"} |
| #48 | ) |
| #49 | |
| #50 | ``` |
| #51 | |
| #52 | --- |
| #53 | |
| #54 | ## Getting All Memories |
| #55 | |
| #56 | Use `get_all()` with filters to retrieve everything for a specific user: |
| #57 | |
| #58 | ```python |
| #59 | dev_memories = client.get_all( |
| #60 | filters={"user_id": "dev"}, |
| #61 | page_size=50 |
| #62 | ) |
| #63 | |
| #64 | print(f"Total memories: {dev_memories['count']}") |
| #65 | print(f"First memory: {dev_memories['results'][0]['memory']}") |
| #66 | |
| #67 | ``` |
| #68 | |
| #69 | **Output:** |
| #70 | |
| #71 | ``` |
| #72 | Total memories: 1 |
| #73 | First memory: Dev works at TechCorp as a senior engineer |
| #74 | |
| #75 | ``` |
| #76 | |
| #77 | <Info> |
| #78 | **Expected output:** `get_all()` retrieved Dev's complete memory record. This method returns everything matching your filters—no semantic search, no ranking, just raw retrieval. Perfect for exports and audits. |
| #79 | </Info> |
| #80 | |
| #81 | You can filter by metadata to get specific types: |
| #82 | |
| #83 | ```python |
| #84 | carl_projects = client.get_all( |
| #85 | filters={ |
| #86 | "AND": [ |
| #87 | {"user_id": "carl"}, |
| #88 | {"metadata": {"type": "project"}} |
| #89 | ] |
| #90 | } |
| #91 | ) |
| #92 | |
| #93 | for memory in carl_projects['results']: |
| #94 | print(memory['memory']) |
| #95 | |
| #96 | ``` |
| #97 | |
| #98 | **Output:** |
| #99 | |
| #100 | ``` |
| #101 | Carl is leading the API redesign project, targeting Q2 launch |
| #102 | |
| #103 | ``` |
| #104 | |
| #105 | --- |
| #106 | |
| #107 | ## Searching Memories |
| #108 | |
| #109 | When you need semantic search instead of retrieving everything, use `search()`: |
| #110 | |
| #111 | ```python |
| #112 | results = client.search( |
| #113 | query="What does Dev do for work?", |
| #114 | filters={"user_id": "dev"}, |
| #115 | top_k=5 |
| #116 | ) |
| #117 | |
| #118 | for result in results['results']: |
| #119 | print(f"{result['memory']} (score: {result['score']:.2f})") |
| #120 | |
| #121 | ``` |
| #122 | |
| #123 | **Output:** |
| #124 | |
| #125 | ``` |
| #126 | Dev works at TechCorp as a senior engineer (score: 0.89) |
| #127 | |
| #128 | ``` |
| #129 | |
| #130 | Search works across all memory fields and ranks by relevance. Use it when you have a specific question, use `get_all()` when you need everything. |
| #131 | |
| #132 | --- |
| #133 | |
| #134 | ## Exporting to Structured Format |
| #135 | |
| #136 | For migrations or compliance, you can export memories into a structured schema using Pydantic-style JSON schemas. |
| #137 | |
| #138 | ### Step 1: Define the schema |
| #139 | |
| #140 | ```python |
| #141 | professional_profile_schema = { |
| #142 | "properties": { |
| #143 | "full_name": { |
| #144 | "type": "string", |
| #145 | "description": "The person's full name" |
| #146 | }, |
| #147 | "current_role": { |
| #148 | "type": "string", |
| #149 | "description": "Current job title or role" |
| #150 | }, |
| #151 | "company": { |
| #152 | "type": "string", |
| #153 | "description": "Current employer" |
| #154 | } |
| #155 | }, |
| #156 | "title": "ProfessionalProfile", |
| #157 | "type": "object" |
| #158 | } |
| #159 | |
| #160 | ``` |
| #161 | |
| #162 | ### Step 2: Create export job |
| #163 | |
| #164 | ```python |
| #165 | export_job = client.create_memory_export( |
| #166 | schema=professional_profile_schema, |
| #167 | filters={"user_id": "dev"} |
| #168 | ) |
| #169 | |
| #170 | print(f"Export ID: {export_job['id']}") |
| #171 | print(f"Status: {export_job['status']}") |
| #172 | |
| #173 | ``` |
| #174 | |
| #175 | **Output:** |
| #176 | |
| #177 | ``` |
| #178 | Export ID: exp_abc123 |
| #179 | Status: processing |
| #180 | |
| #181 | ``` |
| #182 | |
| #183 | <Info> |
| #184 | **Export initiated:** Status is "processing". Large exports may take a few seconds. Poll with `get_memory_export()` until status changes to "completed" before downloading data. |
| #185 | </Info> |
| #186 | |
| #187 | ### Step 3: Download the export |
| #188 | |
| #189 | ```python |
| #190 | # Get by ID |
| #191 | export_data = client.get_memory_export( |
| #192 | memory_export_id=export_job['id'] |
| #193 | ) |
| #194 | |
| #195 | print(export_data['data']) |
| #196 | |
| #197 | ``` |
| #198 | |
| #199 | **Output:** |
| #200 | |
| #201 | ```json |
| #202 | { |
| #203 | "full_name": "Dev", |
| #204 | "current_role": "senior engineer", |
| #205 | "company": "TechCorp" |
| #206 | } |
| #207 | |
| #208 | ``` |
| #209 | |
| #210 | You can also retrieve exports by filters: |
| #211 | |
| #212 | ```python |
| #213 | # Get latest export matching filters |
| #214 | export_by_filters = client.get_memory_export( |
| #215 | filters={"user_id": "dev"} |
| #216 | ) |
| #217 | |
| #218 | print(export_by_filters['data']) |
| #219 | |
| #220 | ``` |
| #221 | |
| #222 | --- |
| #223 | |
| #224 | ## Adding Export Instructions |
| #225 | |
| #226 | Guide how Mem0 resolves conflicts or formats the export: |
| #227 | |
| #228 | ```python |
| #229 | export_with_instructions = client.create_memory_export( |
| #230 | schema=professional_profile_schema, |
| #231 | filters={"user_id": "arjun"}, |
| #232 | export_instructions=""" |
| #233 | 1. Use the most recent information if there are conflicts |
| #234 | 2. Only include confirmed facts, not speculation |
| #235 | 3. Return null for missing fields rather than guessing |
| #236 | """ |
| #237 | ) |
| #238 | |
| #239 | ``` |
| #240 | |
| #241 | <Tip> |
| #242 | Always check export status before downloading. Call `get_memory_export()` in a loop with a short delay until `status == "completed"`. Attempting to download while still processing returns incomplete data. |
| #243 | </Tip> |
| #244 | |
| #245 | --- |
| #246 | |
| #247 | ## Platform Export |
| #248 | |
| #249 | You can also export memories directly from the Mem0 platform UI: |
| #250 | |
| #251 | 1. Navigate to **Memory Exports** in your project dashboard |
| #252 | 2. Click **Create Export** |
| #253 | 3. Select your filters and schema |
| #254 | 4. Download the completed export as JSON |
| #255 | |
| #256 | This is useful for one-off exports or manual data reviews. |
| #257 | |
| #258 | <Warning> |
| #259 | Exported data expires after 7 days. Download and store exports locally if you need long-term archives. After expiration, you'll need to recreate the export job. |
| #260 | </Warning> |
| #261 | |
| #262 | --- |
| #263 | |
| #264 | ## What You Built |
| #265 | |
| #266 | A complete memory export system with multiple retrieval methods: |
| #267 | |
| #268 | - **Bulk retrieval (get_all)** - Fetch all memories matching filters for comprehensive audits |
| #269 | - **Semantic search** - Query-based lookups with relevance scoring |
| #270 | - **Structured exports** - Pydantic-schema exports for migrations and compliance |
| #271 | - **Export instructions** - Guide conflict resolution and data formatting |
| #272 | - **Platform UI exports** - One-off manual downloads via dashboard |
| #273 | |
| #274 | This covers data portability, GDPR compliance, system migrations, and manual reviews. |
| #275 | |
| #276 | --- |
| #277 | |
| #278 | ## Summary |
| #279 | |
| #280 | Use **`get_all()`** for bulk retrieval, **`search()`** for specific questions, and **`create_memory_export()`** for structured data exports with custom schemas. Remember exports expire after 7 days—download them locally for long-term archives. |
| #281 | |
| #282 | <CardGroup cols={2}> |
| #283 | <Card title="Expire Short-Term Data" icon="timer" href="/cookbooks/essentials/memory-expiration-short-and-long-term"> |
| #284 | Keep exports lean by clearing session context before you archive it. |
| #285 | </Card> |
| #286 | <Card title="Control Memory Ingestion" icon="filter" href="/cookbooks/essentials/controlling-memory-ingestion"> |
| #287 | Ensure only verified insights make it into your export pipeline. |
| #288 | </Card> |
| #289 | </CardGroup> |
| #290 |