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: Memory Timestamps |
| #3 | description: 'Add timestamps to your memories to maintain chronological accuracy and historical context' |
| #4 | --- |
| #5 | |
| #6 | ## Overview |
| #7 | |
| #8 | The Memory Timestamps feature allows you to specify when a memory was created, regardless of when it's actually added to the system. This powerful capability enables you to: |
| #9 | |
| #10 | - Maintain accurate chronological ordering of memories |
| #11 | - Import historical data with proper timestamps |
| #12 | - Create memories that reflect when events actually occurred |
| #13 | - Build timelines with precise temporal information |
| #14 | |
| #15 | By leveraging custom timestamps, you can ensure that your memory system maintains an accurate representation of when information was generated or events occurred. |
| #16 | |
| #17 | ## Benefits of Custom Timestamps |
| #18 | |
| #19 | Custom timestamps offer several important benefits: |
| #20 | |
| #21 | - **Historical Accuracy**: Preserve the exact timing of past events and information. |
| #22 | - **Data Migration**: Seamlessly migrate existing data while maintaining original timestamps. |
| #23 | - **Time-Sensitive Analysis**: Enable time-based analysis and pattern recognition across memories. |
| #24 | - **Consistent Chronology**: Maintain proper ordering of memories for coherent storytelling. |
| #25 | |
| #26 | ## Using Custom Timestamps |
| #27 | |
| #28 | When adding new memories, you can specify a custom timestamp to indicate when the memory was created. This timestamp will be used instead of the current time. |
| #29 | |
| #30 | ### Adding Memories with Custom Timestamps |
| #31 | |
| #32 | <CodeGroup> |
| #33 | |
| #34 | ```python Python |
| #35 | import os |
| #36 | import time |
| #37 | from datetime import datetime, timedelta |
| #38 | |
| #39 | from mem0 import MemoryClient |
| #40 | |
| #41 | os.environ["MEM0_API_KEY"] = "your-api-key" |
| #42 | |
| #43 | client = MemoryClient() |
| #44 | |
| #45 | # Get the current time |
| #46 | current_time = datetime.now() |
| #47 | |
| #48 | # Calculate 5 days ago |
| #49 | five_days_ago = current_time - timedelta(days=5) |
| #50 | |
| #51 | # Convert to Unix timestamp (seconds since epoch) |
| #52 | unix_timestamp = int(five_days_ago.timestamp()) |
| #53 | |
| #54 | # Add memory with custom timestamp |
| #55 | messages = [ |
| #56 | {"role": "user", "content": "I'm travelling to SF"} |
| #57 | ] |
| #58 | client.add(messages, user_id="user1", timestamp=unix_timestamp) |
| #59 | ``` |
| #60 | |
| #61 | ```javascript JavaScript |
| #62 | import MemoryClient from 'mem0ai'; |
| #63 | const client = new MemoryClient({ apiKey: 'your-api-key' }); |
| #64 | |
| #65 | // Get the current time |
| #66 | const currentTime = new Date(); |
| #67 | |
| #68 | // Calculate 5 days ago |
| #69 | const fiveDaysAgo = new Date(); |
| #70 | fiveDaysAgo.setDate(currentTime.getDate() - 5); |
| #71 | |
| #72 | // Convert to Unix timestamp (seconds since epoch) |
| #73 | const unixTimestamp = Math.floor(fiveDaysAgo.getTime() / 1000); |
| #74 | |
| #75 | // Add memory with custom timestamp |
| #76 | const messages = [ |
| #77 | {"role": "user", "content": "I'm travelling to SF"} |
| #78 | ] |
| #79 | client.add(messages, { user_id: "user1", timestamp: unixTimestamp }) |
| #80 | .then(response => console.log(response)) |
| #81 | .catch(error => console.error(error)); |
| #82 | ``` |
| #83 | |
| #84 | ```bash cURL |
| #85 | curl -X POST "https://api.mem0.ai/v1/memories/" \ |
| #86 | -H "Authorization: Token your-api-key" \ |
| #87 | -H "Content-Type: application/json" \ |
| #88 | -d '{ |
| #89 | "messages": [{"role": "user", "content": "I'm travelling to SF"}], |
| #90 | "user_id": "user1", |
| #91 | "timestamp": 1721577600 |
| #92 | }' |
| #93 | ``` |
| #94 | |
| #95 | ```json Output |
| #96 | { |
| #97 | "results": [ |
| #98 | { |
| #99 | "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5", |
| #100 | "data": {"memory": "Travelling to SF"}, |
| #101 | "event": "ADD" |
| #102 | } |
| #103 | ] |
| #104 | } |
| #105 | ``` |
| #106 | |
| #107 | </CodeGroup> |
| #108 | |
| #109 | ### Timestamp Format |
| #110 | |
| #111 | When specifying a custom timestamp, you should provide a Unix timestamp (seconds since epoch). This is an integer representing the number of seconds that have elapsed since January 1, 1970 (UTC). |
| #112 | |
| #113 | For example, to create a memory with a timestamp of January 1, 2023: |
| #114 | |
| #115 | <CodeGroup> |
| #116 | |
| #117 | ```python Python |
| #118 | # January 1, 2023 timestamp |
| #119 | january_2023_timestamp = 1672531200 # Unix timestamp for 2023-01-01 00:00:00 UTC |
| #120 | |
| #121 | messages = [ |
| #122 | {"role": "user", "content": "I'm travelling to SF"} |
| #123 | ] |
| #124 | client.add(messages, user_id="user1", timestamp=january_2023_timestamp) |
| #125 | ``` |
| #126 | |
| #127 | ```javascript JavaScript |
| #128 | // January 1, 2023 timestamp |
| #129 | const january2023Timestamp = 1672531200; // Unix timestamp for 2023-01-01 00:00:00 UTC |
| #130 | |
| #131 | const messages = [ |
| #132 | {"role": "user", "content": "I'm travelling to SF"} |
| #133 | ] |
| #134 | client.add(messages, { user_id: "user1", timestamp: january2023Timestamp }) |
| #135 | .then(response => console.log(response)) |
| #136 | .catch(error => console.error(error)); |
| #137 | ``` |
| #138 | |
| #139 | </CodeGroup> |
| #140 | |
| #141 | If you have any questions, please feel free to reach out to us using one of the following methods: |
| #142 | |
| #143 | <Snippet file="get-help.mdx" /> |
| #144 |